Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would need to allow a user to draw a closed shape using polylines and then loop through all the pixels "inside" this closed shape. Is there an easy way to find out which pixels are an element of the shape? (I would need the index (x,y)).

I guess this is somewhat similar to a "fill method" like in paint?
I have a prototype working with rectangles (which is easy), but I have no clue on how to start with the polyline method.

Any tips are more than welcome.

thanks.

[EDIT]
The image is a drawing of sunspots. The user can (today) draw a rectangle around a sunspot group and the application will detect the "dirty" pixels (that make out the sunspots) and do some calculations on it. There are, however, unwanted features on these drawings (written text eg) which we could take out if we were using a polyline shape instead of a rectangle.
[/EDIT]
Posted
Updated 26-Aug-14 21:43pm
v2
Comments
Richard MacCutchan 27-Aug-14 3:36am    
Instead of using x,y co-ordinates to identify the edge of the shape, you would need to use some specific colour or property of the pixel to identify it. You could also narrow down the search area by drawing a virtual rectangle around the polygon.
V. 27-Aug-14 3:43am    
mmm, I'm not following where you want to go with this. The image is a drawing of sunspots. The user can (today) draw a rectangle around a sunspot group and the application will detect the "dirty" pixels (that make out the sunspots) and do some calculations on it. There are, however, unwanted features on these drawings (written text eg) which we could take out if we were using a polyline shape instead of a rectangle.
I'm not sure how your solution will solve this. (it could be I don't understand ;-))
Richard MacCutchan 27-Aug-14 3:48am    
That's because you did not explain what the issue was. You said that you wanted to allow a user to draw an irregular shape and then loop through all the pixels. Now you are talking about pictures of sunspots, and an application that detects a certain class of pixel. That's a totally different issue.
V. 27-Aug-14 3:54am    
true, but I did state I wanted the pixels -inside- the shape, not the shape itself... I updated the question to be more clear.
Richard MacCutchan 27-Aug-14 4:01am    
Yes, and that is what I responded to, but your suplementary information presents a totally different question.

1 solution

The following page provides a basic technique for detecting if a pixel is inside an irregular polygon:

Pixel Test[^].

A similar principle can be applied. Given the set of points making your polygon, find the min/max along the x/y coordinates. Then, for each scan line, track when you are inside or outside the polygon as you go.

You can then apply your sunspot detection algorithm only to those points that enumerate within the polygon.
 
Share this answer
 
Comments
V. 27-Aug-14 6:11am    
thanks, I'll look into it!
V. 27-Aug-14 8:51am    
Looks like this is working. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900