Hi,
Is it possibe to extract the rotated rectangle from the annotation layer, preferable also with some kind of ID, to link it to the very same feature in the feature table? We would like to calculate distances between feature boundaries very fast and oriented rectangles would be a great help for that as a boundary approximation.
Best regards
Fredrik Olsson
Extract rotated rectangle around feature
Hi,
Well, I do not really manage to extract these rotated rectangle graphics. Here is an example of a code snippet:
image = Zen.Analyzing.Analyze(b,ias)
Zen.Windows.ShowImage2d(image,False) - works excellent with nice rotated rectamgles around features
print image.Graphics.Count - Gives 0
print image.Graphics[0] - Does not work
print image.GraphicLayers.Count - Gives 3
print image.GraphicLayers[0].Count - Gives 0
print image.GraphicLayers[1].Count - Gives 0
print image.GraphicLayers[2].Count - Gives 0
print image.GraphicLayers[0].Name - Gives ""
print image.GraphicLayers[1].Name - Gives Annotation
print image.GraphicLayers[2].Name - Gives ""
So what is the right way to fetch those?
At the moment I use the feature data with the ellipse approximation to create my own rotated rectangles but using the already available rectangles could save some important processing time. We need to calculate on parameters such as contour distances between features and rotated rectangles is an accepted approximation with simpler mathematics compared with ellipses. We can use image processing techniques such as dilation -> thinning -> pruning but it simply adds too much time per image. Its better when we use higher binnings whereas gray8 or gray16 does not affect the timings. We run ~400 images per sample and the image acquiring counts for 1 - 1.2s per image including scanning step. So we try to optimize the processing step as much as possible.
Kind regards
Fredrik Olsson
Well, I do not really manage to extract these rotated rectangle graphics. Here is an example of a code snippet:
image = Zen.Analyzing.Analyze(b,ias)
Zen.Windows.ShowImage2d(image,False) - works excellent with nice rotated rectamgles around features
print image.Graphics.Count - Gives 0
print image.Graphics[0] - Does not work
print image.GraphicLayers.Count - Gives 3
print image.GraphicLayers[0].Count - Gives 0
print image.GraphicLayers[1].Count - Gives 0
print image.GraphicLayers[2].Count - Gives 0
print image.GraphicLayers[0].Name - Gives ""
print image.GraphicLayers[1].Name - Gives Annotation
print image.GraphicLayers[2].Name - Gives ""
So what is the right way to fetch those?
At the moment I use the feature data with the ellipse approximation to create my own rotated rectangles but using the already available rectangles could save some important processing time. We need to calculate on parameters such as contour distances between features and rotated rectangles is an accepted approximation with simpler mathematics compared with ellipses. We can use image processing techniques such as dilation -> thinning -> pruning but it simply adds too much time per image. Its better when we use higher binnings whereas gray8 or gray16 does not affect the timings. We run ~400 images per sample and the image acquiring counts for 1 - 1.2s per image including scanning step. So we try to optimize the processing step as much as possible.
Kind regards
Fredrik Olsson
Hello Fredrik Olsson,
there is an alternative apporach via regions!
I hope this code snippet helps to speed up your processing.
there is an alternative apporach via regions!
Code: Select all
image = Zen.Analyzing.Analyze(b,ias)
# Get regions from Analysis
regs = Zen.Analyzing.GetRegions(image, "Class1")
print("Number of Regions found: " + str(len(regs)))
#initialize Regions counter
r = 0
# initialize Table
table = ZenTable()
# for all regions get the polygon
for reg in regs:
poly = reg.GetPolygon()
i = 0
table.Columns.Add("Polygon_x")
table.Columns.Add("Polygon_y")
# write the coordinates in a table
for point in poly:
table.SetValue(i,0, point.X)
table.SetValue(i,1, point.Y)
i += 1
# save table as csv
filename = OutputFolder + "\\table_polygon_" + str(r) + ".csv"
table.Save(filename)
table.Close()
r += 1
Hi,
I have tried it out and it looks promising and I get the point lists for the polygons. However, I have struggled a bit with trying to add polygon back as a graphic element in order to verify their positions. When setting the shape of a graphical element I only see the setbound method, which seems to be the same for all different graphical elements, thus works good for object whose size can be determined by applying boundary box position and box size. Is there an uncomplicated way to add a pointlist-polygon back as graphical element?
Best regards
Fredrik Olsson
I have tried it out and it looks promising and I get the point lists for the polygons. However, I have struggled a bit with trying to add polygon back as a graphic element in order to verify their positions. When setting the shape of a graphical element I only see the setbound method, which seems to be the same for all different graphical elements, thus works good for object whose size can be determined by applying boundary box position and box size. Is there an uncomplicated way to add a pointlist-polygon back as graphical element?
Best regards
Fredrik Olsson
Hello Fredrik Olsson,
this worked for me:
this worked for me:
Code: Select all
image = Zen.Application.ActiveDocument
polyline = image.Graphics.Add(ZenGraphicCategory.Polyline)
polyline AddPoint(10,20)
polyline AddPoint(20,30)
polyline AddPoint(30,50)
polyline AddPoint(20,60)
polyline AddPoint(10,20)
-
- Posts: 1
- Joined: Thu Aug 17, 2023 5:33 pm
Re: Extract rotated rectangle around feature
Hello Fredrik Olsson,
Thank you for reaching out. Yes, it is indeed possible to extract rotated rectangles from the annotation layer and associate them with unique IDs to link them to corresponding features in the feature table. This approach can significantly aid in rapidly calculating distances between feature boundaries, using oriented rectangles as a boundary approximation.
By extracting these rotated rectangles from the annotation layer and establishing a connection with their respective IDs in the feature table, you can efficiently perform boundary calculations and analyses, enhancing the accuracy and speed of your computations. INTERIOR & EXTERIOR WINDOW CLEANING
If you require any further assistance or have additional questions, please don't hesitate to ask.
Thank you for reaching out. Yes, it is indeed possible to extract rotated rectangles from the annotation layer and associate them with unique IDs to link them to corresponding features in the feature table. This approach can significantly aid in rapidly calculating distances between feature boundaries, using oriented rectangles as a boundary approximation.
By extracting these rotated rectangles from the annotation layer and establishing a connection with their respective IDs in the feature table, you can efficiently perform boundary calculations and analyses, enhancing the accuracy and speed of your computations. INTERIOR & EXTERIOR WINDOW CLEANING
If you require any further assistance or have additional questions, please don't hesitate to ask.
Re:
I think this will be the best and most suitable answer for you.user-6033 wrote: ↑Fri Oct 11, 2019 9:48 am Hi,
Well, I do not really manage to extract these rotated rectangle graphics. Here is an example of a code snippet:
image = Zen.Analyzing.Analyze(b,ias)
Zen.Windows.ShowImage2d(image,False) - works excellent with nice rotated rectamgles around features
print image.Graphics.Count - Gives 0
print image.Graphics[0] - Does not work
print image.GraphicLayers.Count - Gives 3
print image.GraphicLayers[0].Count - Gives 0
print image.GraphicLayers[1].Count - Gives 0
print image.GraphicLayers[2].Count - Gives 0
print image.GraphicLayers[0].Name - Gives ""
print image.GraphicLayers[1].Name - Gives Annotation
print image.GraphicLayers[2].Name - Gives ""
So what is the right way to fetch those?
At the moment I use the feature data with the ellipse approximation to create my own rotated rectangles but using the already available rectangles could save some important processing time. We need to calculate on parameters such as contour distances between features and rotated rectangles is an accepted approximation with simpler mathematics compared with ellipses. We can use image processing techniques such as dilation -> thinning -> nyt wordle -> pruning but it simply adds too much time per image. Its better when we use higher binnings whereas gray8 or gray16 does not affect the timings. We run ~400 images per sample and the image acquiring counts for 1 - 1.2s per image including scanning step. So we try to optimize the processing step as much as possible.
Kind regards
Fredrik Olsson