silhouette from an image

Started by
12 comments, last by broady 15 years, 8 months ago
Hello guys, i have to solve this problem: given a raster image (without holes) retrieve a collection of vertices approximating the contour of the image. Think about the image in this way: a rectangular box whit a shape in the middle. The pixels wich dont stay inside the shape are trasparent. Pixel data inside the shape have rgb values of course. The goal is to build a "struct" containing the vertices of the shape. Reading here and there i found the marching squares algorithm. Do you think i can code it or should i find some resource? If you think there is a better/simpler algorithm speak please :D Thanks bro
Advertisement
Well if you know that every pixel outside of the shape will be transparent you can do something simple like, if the pixel is not transparent and their is a transparent pixel touching it, then add it to the list of edge pixels.
This night i'lltry to do that.

Thanks mate
It's not a good idea i think. In that way u can't control how many vertices u are going to take. Basically in that way u have a vertex for every pixel of the shape contour.

I'd like to have an implementation where i specify the number of vertex i want and an eventually function returns back vertex data.

Any tip?
You could convert the silluette into a distance map, and then run marching squares over the distance map to generate a polygon mesh from it. This would me nice as you can just change the resolution of your marching squares grid to adjust how many vertices the final poly has and how much you trade off speed for accuracy.
Quote:Original post by OrangyTang
You could convert the silluette into a distance map, and then run marching squares over the distance map to generate a polygon mesh from it. This would me nice as you can just change the resolution of your marching squares grid to adjust how many vertices the final poly has and how much you trade off speed for accuracy.


Thanks for the tip but it's too hard for me. I am at the start.
It's a hard problem. If you're looking for some magic process which doesn't require effort on your part you're out of luck.
You can just use the marching squares if transparency information is available, this will result in a unsorted list of edges.
Then find the edges' neighbours and finally merge edges pointing into the same direction.

You can merge as many edges as you need until you reach your desired vertex count.
http://www.8ung.at/basiror/theironcross.html
Quote:Original post by OrangyTang
It's a hard problem. If you're looking for some magic process which doesn't require effort on your part you're out of luck.


OrangyTang, i am not looking for magic. I am just looking for an other way to accomplish that stuff. I am moving back to the first approach now.

Thanks guys
Bro
Hello guys, i have soptted one of my many problems. I am doing an example to show it.
suppose i have a 256*256 pixel image. In this image, starting at x=y=100px there is a square of some size. As always the image is transparent outside of the square and opaque inside the square. My pixel data is stored in a dinamically allocated GLubyte 1d array of 256*256*4 (4 since it's rgba). Given this array, for the i-th pixel the alpha value is given by this index [i+3+(i*3)]. Once loaded the image, i went to check this alpha values and they are not all 0 or 255.

The transparency is shaded. For example i'd like to have a value of 0 for the (100,99) pixel ans 255 for the (100,100) where the image starts. Instead i have 0 for the (100,97), 255 for the (100,100) and alpha values between 0 and 255 for the the pixel in the middle of em.

Clearly with this kind of image i can't work properly. Is there a way to create a "perfect" image with ps or gimp?

thanks guys
Bro

This topic is closed to new replies.

Advertisement