Jump to content
  • Advertisement
Sign in to follow this  
broady

silhouette from an image

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!