|
Dude... this is awsome!!
I loved it!
I need to extend this to add certain simbols to the image as annotations... lets say "a point", "a little spiral" (as an icon)... what do I need to extend in order to accomplish this?
I'm quite good at GDI+ so I need to know where to hook.
Thanks in advance!
|
|
|
|
|
Hi there,
what I have done in more recent versions of this library (which cannot be distributed easily because of certain dependencies), is create a class 'Geometry2D' which works on List(of PointF) which are inside the annotations. Besides classic 'point on line, point inside polygon, ...' methods I also have some shape creation routines:
''' Object shapes.
Public Enum Shape
Ellipse
Circle
Rectangle
Diamond
End Enum
''' Create the points for a shape with the given parameters.
''' Parameters are:
''' Circle: center X, center Y, radius
''' Ellipse: center X, center Y, semi major axis, semi minor axis, angle
''' Rectangle: center X, center Y, width, height, angle
''' Diamond: center X, center Y, width, height, angle
Public Shared Function CreatePolygonShape(ByVal shape As Shape, ByVal par As Double())
Return CreatePolygonShape(shape, par, 16)
End Function
''' Get the points for a shape with the given parameters.
''' Parameters are:
''' Circle: center X, center Y, radius
''' Ellipse: center X, center Y, semi major axis, semi minor axis, angle
''' Rectangle: center X, center Y, width, height, angle
Public Shared Function CreatePolygonShape(ByVal shape As Shape, ByVal par As Double(), ByVal nrPts As Integer) As IList(Of PointF)
Select Case shape
Case shape.Circle
Return CreatePolygonEllipse(New PointF(par(0), par(1)), par(2), par(2), 0, nrPts)
Case shape.Ellipse
Return CreatePolygonEllipse(New PointF(par(0), par(1)), par(2), par(3), par(4), nrPts)
Case Geometry2D.Shape.Rectangle
Return CreatePolygonRectangle(New PointF(par(0), par(1)), par(2), par(3), par(4), True)
Case Geometry2D.Shape.Diamond
Return CreatePolygonDiamond(New PointF(par(0), par(1)), par(2), par(3), par(4))
End Select
Return Nothing
End Function
''' Create a polygonal ellipse shape
Public Shared Function CreatePolygonEllipse(ByVal center As PointF, ByVal semiMajorAxis As Double, ByVal semiMinorAxis As Double, _
ByVal angle As Double, ByVal nrPts As Integer) As PointF()
Dim angleStep As Double = Math.PI * 2 / nrPts, i As Integer
Dim pts(nrPts - 1) As PointF
Dim cosAngle, sinAngle As Double
'angle = angle / 180 * Math.PI NOW in radians!!!!
cosAngle = Math.Cos(angle)
sinAngle = Math.Sin(angle)
For i = 0 To nrPts - 1
Dim cosT, sinT As Double
cosT = Math.Cos(angleStep * i)
sinT = Math.Sin(angleStep * i)
pts(i).X = CSng(center.X + semiMajorAxis * cosT * cosAngle - semiMinorAxis * sinT * sinAngle)
pts(i).Y = CSng(center.Y + semiMajorAxis * cosT * sinAngle + semiMinorAxis * sinT * cosAngle)
Next
Return pts
End Function
''' Create a rectangle, possibly angled, from center or corner point.
Public Shared Function CreatePolygonRectangle(ByVal rectPt As PointF, ByVal width As Double, ByVal height As Double, _
Optional ByVal angle As Double = 0, Optional ByVal center As Boolean = False) As PointF()
Dim sin As Double = Math.Sin(angle), cos As Double = Math.Cos(angle)
Dim pts(3) As PointF
Dim w As New PointF(cos * width, sin * width)
Dim h As New PointF(-sin * height, cos * height)
If center Then
pts(0).X = CSng(rectPt.X - 0.5 * (w.X + h.X))
pts(0).Y = CSng(rectPt.Y - 0.5 * (w.Y + h.Y))
Else
pts(0).X = CSng(rectPt.X)
pts(0).Y = CSng(rectPt.Y)
End If
pts(1).X = CSng(pts(0).X + w.X)
pts(1).Y = CSng(pts(0).Y + w.Y)
pts(2).X = CSng(pts(1).X + h.X)
pts(2).Y = CSng(pts(1).Y + h.Y)
pts(3).X = CSng(pts(2).X - w.X)
pts(3).Y = CSng(pts(2).Y - w.Y)
Return pts
End Function
''' Create a rectangle polygon from a rectangle structure.
Public Shared Function CreatePolygonRectangle(ByVal rect As RectangleF) As PointF()
Dim pt(3) As PointF
pt(0).X = rect.X
pt(0).Y = rect.Y
pt(1).X = pt(0).X + rect.Width
pt(1).Y = pt(0).Y
pt(2).X = pt(1).X
pt(2).Y = pt(1).Y + rect.Height
pt(3).X = pt(2).X - rect.Width
pt(3).Y = pt(2).Y
Return pt
End Function
''' Create a rectangle polygon using the top left and bottom right points
Public Shared Function CreatePolygonRectangle(ByVal pt1 As PointF, ByVal pt2 As PointF) As PointF()
Return CreatePolygonRectangle(New RectangleF(pt1, New SizeF(pt2.X - pt1.X, pt2.Y - pt1.Y)))
End Function
''' Create a diamond, possibly angled!
Public Shared Function CreatePolygonDiamond(ByVal center As PointF, ByVal width As Double, ByVal height As Double, _
ByVal angle As Double) As PointF()
Dim sin As Double = Math.Sin(angle), cos As Double = Math.Cos(angle)
Dim pts(3) As PointF
Dim w As New PointF(0.5 * cos * width, 0.5 * sin * width)
Dim h As New PointF(-0.5 * sin * height, 0.5 * cos * height)
pts(0).X = CSng(center.X - h.X)
pts(0).Y = CSng(center.Y - h.Y)
pts(1).X = CSng(center.X + w.X)
pts(1).Y = CSng(center.Y + w.Y)
pts(2).X = CSng(center.X + h.X)
pts(2).Y = CSng(center.Y + h.Y)
pts(3).X = CSng(center.X - w.X)
pts(3).Y = CSng(center.Y - w.Y)
Return pts
End Function
I suggest you extend these with your requirements ...
Good luck
|
|
|
|
|
Thanks dude!
I'm using the code from this article... where there are some DLL with no code and the test app.
Can you send me or upload the code for this assemblies?
And where should I add this class you provide: Polygon or AnnotatedImage assembly?
It would be nice to include same Delegates to be able to hook and extend the type of shapes so you don't need to think of all the types of shapes... leaving the responsability to the user of your assembly.
Thanks Yves!
modified on Thursday, October 28, 2010 11:45 AM
|
|
|
|
|
I currently cannot help you with the source code of dll's provided without source code, sorry (legal stuff).
Regarding the location of the class, do what best suits you it does not matter much. You currently cannot add it to the polygon class, but you could provide extra constructors in the annotation class. It's not the cleanest design, but it will work ...
Regarding the delegates, you are right! For me though the emphasis is not on shapes, but rather on boundaries which are the result of image processing or user interaction (as in freehand drawing to delineate an object), so this is not as complete as one would like for some other applications where shapes are important like GIS, flowcharts, ....
I have though about releasing a newer version of my code (the CodePlex system did not work at all for me), I will post this here if I do.
Yves
|
|
|
|
|
Hi Yvdh, Thanks, Have you got a link to the new download please, I have had look an can only see your previous posts. Pete
****
Hi there,
I have sent a newer version of my 2006 article on the same subject to the CodeProject. It contains the latest version of the image control. It also contains an image processing library which is used to perform some manipulations of the image. Post any new questions on the 2006 article.
Cheers
Yves
****
|
|
|
|
|
|
I will update the codeplex site with recent source code and release version.
modified on Thursday, April 23, 2009 8:31 AM
|
|
|
|
|
Dear Fiends,
How I can download it as a complete set?
Thanks
|
|
|
|
|
Great job with this control! (though if you could link to this article from the old one, that might be good -- I spent quite some time modifying that one to work in VS2005, then realized you had a new version, heh)
I have a couple questions -- one, how can I get information about the selected area, such as the horizontal width at various points?
Also, is there some way I could make a selection based on (color) edge detection?
Here's a little idea of what I'm trying to do:
http://www.techautos.com/downloads/DetectionDiag.jpg[^]
Thanks
|
|
|
|
|
Hi there,
both your questions can be solved readily!
In order to get the horizontal profile you could compute the centroid, and then run through the points and take the absolute value of the difference in x coordinates. You may need to resample the contour to a fine detail before doing so.
The edge detection problem can range from very simple to really, really hard, depending on the input images. Yours look like luggage X-ray images, and there are many ways to detect edges in grayscale images: using convolution (gradient, Laplacian zero-crossings, ...), region growing (interactive), watershed transform, ... I maybe able to help if i know more about what you want: automatic,interactive, type of images, what the objects are you are looking for, etc. ...
I will do better and modify the annotated image control articles to point to my website with the lates version of the control in the future. Problem is this control needs another of my libraries which is not free to distribute. Soon as I work this stuff out I'll update them.
|
|
|
|
|
Ok, so from what I can tell, I could use the points to get the centroid and then get distances to outer points. How can I access the points in a selection, and add new points to them? (and I could resample by simply finding midpoints and adding those, right?).
I've been working a bit with my images and found a different method that gives much higher contrast (basically black and white) images (if you're curious, these are simulated anti- brain tumor drug infusions). So here's an example of an image: http://www.techautos.com/downloads/DetectionPlateRdProf.jpg[^]. I'd basically want to get the outline of the white blob as my selection, let the user correct the selection (add/subtract), and then process the selection to get the horizontal distances, etc.
As you can see in that image, there's also a fainter (gray) trace around the blob, from the dish, slide, etc., so I guess the way to get around that would be to only select the strongest white color (which would get the blob but not other stuff), or let the user select a box around the blob to process.
I also have a more detailed image process that I'd like to process through this, which outputs images like: http://www.techautos.com/downloads/DetectionScopeProf.jpg[^], with the goal being the same - select the white mass seen (though here it's a bit less defined, as the edges are a bit gray, etc.).
|
|
|
|
|
My comments pertain to the latest version on Codeplex.
The annotated Image control has a SelectedItem property which can be an Annotation, an AnnotationContainer or a Mask. Each Annotation is basically a strongly typed collection of PointF structures with extra properties so you can easily iterate through all the points using for each loops.
Regarding your image processing problems, they are quite simple and can be solved by several methods, e.g. thresholding or seeded region growing to name but 2 simple ones. User interaction could be to select the starting seeds. I have done this, and with a few mouse click the area was segmented, see http://uzdermis.ugent.be/portals/3/temp/detectionscopeprofsegmented.jpg[^].
Check out the web for seeded image growing, I cannot give you the image processing code for the moment, it is not solely mine to give. I will keep you posted if this software is available.
Yves
|
|
|
|
|
Your software would have been a great piece of code...
But it's NOT COMPLETE.
In facts, you ddin't provide us the source code for the used libraries:
Polygon.dll
Common.dll
ImageProcessing.dll
Therefore, I consider this code UNUSABLE
(I should be able to modify ANY aspect of the code I write. If NOT, I don't write it!!)
It's a pity, because it would have meaningfully helped the developing of my new toy: an Image Map software.
OK, I'll find some other solution...
Fortunately, I don't have to do that for Work, or I'd be ruined.
Cheers,
Klaus
|
|
|
|
|
You maybe right about not providing all the source code, and you are entitled to your opinion about this making the code unusable, but there is no point in being rude about it!
FYI I am thinking about posting this code on something like CodePlex or sourceforge, but this will require putting all of my framework there due to interdependencies. This is a problem for the moment as there are some pieces of code that are co-owned by the university and a company. Once I sort that out I will let people know ...
Don't they say in German: Immer mit Ruhe?
Yves
|
|
|
|
|
Dear Yves,
I'm sorry, if I sounded rude. I just mean to express my disappoint when I was so close to the
solution of my issues... and then "I missed the grasp and have fallen into the emptyness under me".
It's horribly frustrating.
It feels like I have to reinvent the wheel, when someone more clever than me had already done it
before...
For what concerns the copyright issues,
* Can't you just cut out the unused parts away?
Maybe, not the whole framework is needed and a diet could be useful.
Personally, I try to have less unused things as possible, in my code.
* The co-owned code can become YOURS, if you modify it enough to say:
"It's something different. It does the same thing, but differently - mine is better optimized"
That's my 2 cents of Euro thought
Will you keep me informed, when you'll put yor complete sources and where?
Thank you very much in advance
Klaus
"Always with rests", right
|
|
|
|
|
I have copied the DLL's to my project folder, added them to the foms and are attempting to use in a C# project.
But to no avail -I must be missing something.
Does anyone have any source code for how this is implemented in C# (I am trying to build a "multiple Images Annotated to Database application".)
There are no error messages but trying code like
______________________________________________________________________________
private void menuItem2_Click(object sender, System.EventArgs e)
{ if (annotatedsRGBImage1.dlgOpenFile.ShowDialog()==DialogResult.OK)
{
System.Drawing.Image myimage = System.Drawing.Image.FromFile(annotatedsRGBImage1.dlgOpenFile.FileName);
annotatedsRGBImage1.BackgroundImage=myimage;
}
}
____________________________________________________________________________
leaves annotatedsRGBImage1 blank (no image)
The control is being accessed or the dlgOpenFile would not work
Thanks for your help
|
|
|
|
|
There should be no problem using the control in C# (indeed, some parts are even in C# as I wrote some image processing routines that use pointers). The code you present cannot work, as the AnnotatedImage control has its own Bitmap property which you need to set, and which will display the image and its overlaying annotations. Check out the sRGBViewer application for an example.
Good luck
|
|
|
|
|
YOU, ARE THE MAN!
|
|
|
|
|
I have been waiting for this
Something to digest for the weekend.
Marc
|
|
|
|
|