Click here to Skip to main content
13,511,801 members
Rate this:
Please Sign up or sign in to vote.
See more: , +

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.
Posted 3-Aug-11 7:43am
Updated 3-Aug-11 8:32am
SAKryukov 3-Aug-11 14:06pm
What "image processing". Add a proper tag: WPF, Forms, ASP.NET, what?
Member 8133819 3-Aug-11 14:33pm

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.


1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180417.1 | Last Updated 3 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100