HIDIHO!

giving something back to the Flash community

seam carving bis repetita

Tags: , , , , ,

cover
hi, seam carving has been a big trend last year some people have already ported it in various ways. yet I’ve always been fascinated by it for it is definitely fascinating. so I gave it a go.
not much to say, people before me may have done it better.

what is seam carving?
- a kick ass algorithm, already ported a couple of times

knowing for example that Quasimondo and Joa Ebert have given it a thourough try (woodpecker will fortunaletly be be released soon), one might say it was no use.

well I am somehow trying to understand how things work and this one was a tricky one.

The concept is simple, you filter the image using an edge detector, process an energyMap using the greyscale values of the energy map. When resizing, you pick the lowest cost path that crosses the image from one side to the other.

this path is the one that will show the least when removed from the picture. As the energy map is to be processed every time a change is performed on the image, this is rather computer exepensive (if not killing).

first I used a Sobel filter (2kernel) to get the energy variations from one pixel to the other and was storing the color value in the array. Wasn’t working much, so I took the luminance of each pixel instead. it worked a bit better yet the real improvement was to select another filter type. now I am using the Prewitt filter (4kernel) which is definitely more accurate and not that much more computer exepensive.

To make it run fatser I thought about a couple of things:

  • the way I’m collecting the energy map is not exact: theoretically, one should compare a pixel to its 8 neighbouring pixels to deduce a morphological gradient. I am only taking each pixels’ value individually.
  • I process the energy map every # times: indeed when the image contains big, lightly variating areas such as a blue sky, it’s no use recomputing it every frame
  • Then I apply a threshold filter to the energy map. it incitates the seam to choose some pathes rather than others.
  • I have reduced the number of get/setPixel as much as I could: not redrawing the map saves a lot of processing time too. I’m mostly working on 2D arrays

well the best is to check what it does :
filterType = PREWITT;
refreshRate = 10;
threshold = 0xFF666666;



filterType = PREWITT;
refreshRate = 10;
threshold = 0xFF666666;


filterType = PREWITT;
refreshRate = 10;
threshold = -1;


filterType = PREWITT;
refreshRate = 5;
threshold = 0xFF666666;



filterType = SOBEL;
refreshRate = 5;
threshold




classes:

that was it any feedback / comments are welcome :)

Tags: , , , , ,

© 2009 HIDIHO!. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.