Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello,

I am writing a simple image processing program. I select a region in an grey scale image and produce a histogram of pixel values. One of the requirements is that the user should be able to select polygon regions of interest in the image. That is, the user clicks multiple times on the image, and each time, an anchor appears on the image that connects with a line to the previous anchor. The user can click multiple times until he draws any arbitrary shape and closes the polygon.

After creating the polygon, the user should be able to modify each anchor. This would be similar to a the poly-line tools in MS Power Point, for example.

When the user is done, I have code to analyze and report on just the pixels inside the polygon region.

This is a standard Windows Application.

I have an idea about how to create such a thing from scratch. But I was wondering if anyone knew of a solution that already exists. Can't seem to find anything on google, etc.

Thank you in advance for your support.
Dmitry
Posted
Updated 3-Aug-11 8:32am
v3
Comments
Sergey Alexandrovich Kryukov 3-Aug-11 14:06pm    
What "image processing". Add a proper tag: WPF, Forms, ASP.NET, what?
--SA
Member 8133819 3-Aug-11 14:33pm    
SAKryukov,

Thank you for your comment. I clarified my original post above. I am writing a windows application in VB.NET. The purpose of it is to select poly-line regions of an grey-scale image and produce a histogram of the pixels. However, the selection should be editable after the fact.

Thanks,
Dmitry

1 solution

In the old days there existed a "scribble" sample program to show you how to handle drawing with mouse interaction under MFC. It is still around, but you should focus on the principles of graphical interaction and not on extra technicalities.

Anyway, what you need to do is:
- design the scenario that allows the user to define and drag the polygon with the mouse (sequence of clicks and mouse movements);
- implement the drawing of the (partial) polygon and anchors; this is done in the Paint event handler, by means of the drawing functions (such as Graphics.DrawLine);
- use the MouseMove, MouseDown... event handlers to monitor the cursor positions as well as mouse button state; to "select" a vertex, you will need to compute the shortest distance between the cursor and all vertices.

That is essentially all you need. The Form Designer will help you create the required event handlers.

You can also get some inspiration here: http://www.vb-helper.com/howto_net_polygon_grab_handles.html[^]
 
Share this answer
 
v3

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