Thursday, September 20, 2007

Experiments on Seam Carving

OK, I admit. I was really curious about the technique named seam carving, which I've blogged before, and which has received a fair amount of attention on the net recently. I then decided to explore it a bit more using the gimp plug-in (BTW, kudos to Carlo Baldassi for this plug-in, I'll write more about it later). So, I've chosen a few representative images and ran the implementation on them in order to evaluate in what conditions the algorithm performed ok and when it failed. The rest of this blog details these experiments.

A Reference Image

Before checking the algorithm on real pictures, I've decided to test it on the following somewhat artificial image to better check for its effects on image features:
Gradient picture
A Reference Picture With a 1024 Pixels Width

As can be seen, the image, which has a width of 1024 pixels, consists of two subjects, an apple and grapes, with a gradient background behind them. Why the gradient background? Well, since for this image the seam carving algorithm is going to be applied on its width, and hence it will run roughly over the vertical columns of pixels, we should get approximately the same results as for a plain background. On the other hand, any distortion caused by the carving will be readily apparent, due to distortion on the gradient itself.

Just for the sake of comparison, I've scaled the width down to 640 pixels, which gives a little less than 40% reduction, and the result is shown below. As can be seen, distortion is evident throughout the scaled-down image.

Gradient scaled down
Scaled Down Version of Reference Picture

Applying the seam carving algorithm on the reference image to reduce it to a 640-pixel width gives the result below. Comparing it with the previous scaled-down image, we can immediately see the gains the algorithm gives. Although distortion is visible in the gradient background, the apple and the grapes keep their original shapes.

Gradient picture with seam carving at 640 pixels
Reducing Reference Picture to 640 pixel-width With Seam Carving

We also reduced the image further to a 480 pixel width (a reduction of more than 50%), as shown below. In this case, the fruits start to present some distortion, but this is unavoidable seeing that they are already packed against each other.

Gradient picture with seam carving at 480 pixels
Reducing Reference Picture to 480 pixel-width With Seam Carving

From these pictures we see that the algorithm performs reasonably well when applied to an image with an homogeneous background. Let's check now for more interesting images.

Selected Images

For real-world images, five images were chosen (two landscapes, two with people and one geometric) having features that are representative of most pictures, like human and animal figures, geometric shapes and loosely-constrained shapes (like trees, mountains, grass fields and clouds, whose shapes can vary significantly and still look ok). The images were reduced to 75% and 50% of their original size using seam carving in both width and height (separately).

The first landscape image is a picture of a small village in a valley.

First Landscape Picture - A Valley
Here we see that the image contains a detailed bottom half and a more homogeneous upper half. Besides, none of the elements in the picture are too constrained on their shapes. We then applied the algorithm on this image, getting the results below. As I said in my previous post, the processing time for 1024x800 pixels images are in the order of 15 - 20 seconds. This one, being a little smaller (680x500), took less than 10 seconds.
Applying Seam Carving at 75% on Width
Applying Seam Carving at 75% on Height
Applying Seam Carving at 50% on Width
Applying Seam Carving at 50% on Height

From the above images we see that the algorithm performs reasonably well at both reduction rates and in both directions (width and height). So far, so good.

The next image is a landscape picture with a horse in the middleground.

Horse at a Grass Field
Applying Seam Carving at 75% on Width
Applying Seam Carving at 75% on Height
Applying Seam Carving at 50% on Width
Applying Seam Carving at 50% on Height

The situation here is a little different. The algorithm has problems even at the lower scaling rate, since the horse is significantly distorted in all cases, even though the rest of the picture looks ok. That may be partly due to the patterns for the grass and the clouds having more details than for the horse, but it is also because any change in the shape of the horse is much more noticeable than for the other elements in the picture. This effect can be seen not only here but in the next pictures, too.

Another problematic picture is the one below with a man silhouette in the center of the image.

Silhoueted Man

This is a rather interesting picture because of its lack of details, both in the man as in the other parts of the picture. Running the algorithm on it gives the following images:

Applying Seam Carving at 75% on Width
Applying Seam Carving at 75% on Height
Applying Seam Carving at 50% on Width
Applying Seam Carving at 50% on Height

We can see that only the least reduced-height picture is really acceptable, since it is the only one where the man is not significantly distorted. Again, it may partly due to the lack of details in the man texture, but also is due to more stringent criteria for the human shape.

The fourth picture also has human figures in it, in this case, two children.

Children at the Beach

It's worth noticing that the children are well-lit and have good details, unlike the silhoutted man in the previous image. Applying the algorithm gives the images below.

Applying Seam Carving at 75% on Width
Applying Seam Carving at 75% on Height
Applying Seam Carving at 50% on Width
Applying Seam Carving at 50% on Height

We can see that, even though the algorithm performs a little better, the higher-compressed images are still problematic.

The last image is a picture of a part of the Golden Gate, in San Francisco, and as such is strongly geometric.

Golden Gate

Although the picture doesn't have a lot of detailed patterns, it has lots of straight lines. Applying then the algorithm gives the following results:

Applying Seam Carving at 75% on Height
Applying Seam Carving at 50% on Width
Applying Seam Carving at 50% on Height

We can see that in none of the cases the algorithm performs satisfactorily. Hector Yee in his blog reported finding problems with geometric shapes, too. Interestingly, he tried a modified algorithm which chooses the seam to be removed in a more stochastically way found that it apparently gave better results. Since I didn't have access to the modified algorithm, I couldn't test with the above image, but in some way it makes sense, since removing seams more or less randomly may give straighter lines.

The Gimp Plug-in

The gimp plug-in has a feature where one can define a region of the image to be (mostly) preserved from the operations of the algorithm. We used this feature to re-run the algorithm for the second and third pictures, preserving the areas around the horse and the man, respcectively. The results for the 50% reduction cases are shown below.

Applying Seam Carving at 50% on Width Preserving Horse Shape
Applying Seam Carving at 50% on Width Preserving Human Shape
It can be readily seen that the results have improved very significantly, with both the man and the horse shapes preserved (as they should), while the rest of the picture with the same good results as before. We can conclude that seam carving, as implemented by the gimp plug-in, does a good job in scaling down images with "generic" shapes, like trees and mountains, which are present in most landscape pictures. It has, however, problems with pictures with more constrained shapes, like human and animal shapes. These problems can be, though, substantially improved by protecting the sensitive parts manually before applying the algorithm. On the other hand, images with strong geometric shapes are not suitable in general for the seam carving algoritm.

Conclusions

I'd be most interested in hearing comments on the finding of other implementations.

Labels: ,

6 Comments:

Anonymous Anonymous said...

Hello,

I keep coming to this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Plenty of useful information on orion67.blogspot.com. I am sure due to busy scedules we really do not get time to care about our health. Are you really serious about your weight?. Research presents that closely 60% of all United States adults are either chubby or overweight[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these citizens, you're not alone. Infact many among us need to lose 10 to 20 lbs once in a while to get sexy and perfect six pack abs. Now the question is how you are planning to have quick weight loss? Quick weight loss can be achived with little effort. Some improvement in of daily activity can help us in losing weight quickly.

About me: I am blogger of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also mentor who can help you lose weight quickly. If you do not want to go under difficult training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for fast weight loss.

March 20, 2010 at 4:02 PM  
Anonymous Anonymous said...

i surely adore all your posting style, very attractive,
don't quit and keep creating in all honesty , because it just simply very well worth to read it,
impatient to browse through a lot more of your articles, kind regards :)

March 20, 2010 at 5:34 PM  
Anonymous free adult xxx letters stories said...

Shed been a good deal more dumpy when shedreported for training on her homeworld a half dozen GSCs ago. There had to be another way.
sexy tummy stories
femdom male casteration stories
interracial cuckold wives stories
stories about animal sex with men
bdsm horse device stories
Shed been a good deal more dumpy when shedreported for training on her homeworld a half dozen GSCs ago. There had to be another way.

December 4, 2010 at 5:58 AM  
Anonymous Anonymous said...

Wait around! Or even certainly not! I merely authored to Keith’s e-mail address from a
several spot which occasion I didn't experience an mistake meaning. Therefore he almost certainly got the details your dog wished coming from me personally (checking account number, for example) and after this hindered the e-mail correct having an mistake sales message which usually suggests “Eric’s e-mail address isn't valid anymore”,
although it’s possibly ready to go again. Proof is I personally
delivered some text to his or her tackle at a unique spot
(amongst this different e-mail deals with) we did not get an mistake message… darn…tghthgthgg Jim please help my family stick to the resume with your corporation.
I've already directed my application for your firm contact, make sure you I need the important reaction.
Here is my web-site - http://www.treatmentforgenitalwarts.info/

January 22, 2013 at 6:20 AM  
Anonymous Anonymous said...

I'm going to you truly, I do believe! Would probably this kind of grow to be likely to provide you with your web site interpreted straight to French? Uk is definitely my own minute language.
My site - www.ikarma.com

January 22, 2013 at 9:56 PM  
Anonymous Anonymous said...

I don’t be aware of earn money ended up listed here, however
consider this post is unexpected. I don’t understand your identiity on the other hand unquestionably you are going to often be a well-known blog writer,
if you're not by now.
Feel free to surf my site - Criminal background

February 11, 2013 at 8:47 PM  

Post a Comment

<< Home

eXTReMe Tracker