09-11-2008 07:02 PM
I have defined a couple of regions on an image and I want to mask a region for analysis
The " vision.RegionsToMask(mask, viewer.Regions, false, 255); " function second argument only accept regions. Right now my solution is to add one region at a time mask it and analyse the mask... I basically have a loop that cycles 72 times just to analyse certain regions on the image. I was wondering if you guys have a better solution for this.
Is there a RegionToMask function? I cant seem to find it in cwimaq help file
Thanks,
Riscoh
09-12-2008 11:43 AM
Any suggestions on this guys...
Thanks for your time.
09-14-2008 09:16 PM
09-14-2008 09:51 PM
Adam,
I basically have defined 72 regions on an image (see attachment) and want to mask each region for analysis. From what Ive understand... the RegionsToMask method will store masked image to a CWIMAQImage object...but if I have defined many regions it will store everything into one image.... correct me if Im wrong... so what I did was remove all the regions first by calling Regions.RemoveAll() function, add a new region, mask the region and do analysis and loop this process a couple of times... see the code below...
viewer.Regions.RemoveAll();
viewer.Regions.AddRotatedRectangle(rectangle);
vision.RegionsToMask(mask, viewer.Regions, false, 255);
viewer.Regions.Item(1).Visible = false;
vision.Histogram2(viewer.Image, report, options, mask);
I dont mine looping through it, I just want to find a way to avoid calling the Regions.RemoveAll() and AddRotatedRectangle() functions
Ive re-read the help file again and it says that .... This method operates on all region objects whose Active property is True.
Do you think if I just set the viewer.Regions.Item(1).Active = true to the region I currently want to analyse.....
I could finally get rid of the functions I didnt want to use so the code would look like below
//Set all regions to false first............ and enable as needed
for(int i = 0; i<topCoverRegions.Count; i++)
{
viewer.Regions.Item(i).Active = true;
vision.RegionsToMask(mask, viewer.Regions, false, 255);
// Do histogram analysis on the mask...
}
Thanks for your time
Riscoh
09-15-2008 07:52 AM
09-15-2008 05:28 PM
Hi riscoh,
Thanks for the explanation. I would suggest just trying the idea you have. It does not seem like it will take much time to implement. Other than this, I cannot think of a way to make things work faster on my end. When you said refactoring my code aloud you cod run fast are you saying that you have already tried this?
09-15-2008 05:43 PM
Adam,
Yes I've tried it and the program ran faster...
Thanks
Riscoh
09-16-2008 10:51 AM
Hi riscoh,
Just out of curiosity what exactly did you change to make it run that much faster? It would be useful to know for future reference for both myself and other people on the forums.
09-16-2008 01:10 PM
Adam,
I basically got rid of these...
labelRectangle = new CWIMAQRotatedRectangle();
..................
..................
viewer.Regions.RemoveAll();
viewer.Regions.AddRotatedRectangle(labelRectangle );
The previous code I had keeps on creating CWIMAQRotatedRectangle object and add them to the viewer's region collection and this is where it consumes a lot of time.
And I have to call Regions.RemoveAll() coz there is no RegionToMask() function...
Instead of removing and adding 72 regions I just made all 72 regions inactive and set a region active when I need to do analysis....
Heres what the program does
- Check fiducial using pattern matching
- Reposition 72 regions based on the fiducial pattern match report.. I use Region.Item(1).Move(x,y) method to reposition all 72 regions... I didnt like using TransformRegions method its confusing me, just want to make it simple and offset the center position from the fiducial matchReport
- Mask regions one at a time and call Histogram2 method
- show results
heres how i initialize the my label tools
while (++count < points)
{
thetaX = Math.Cos(Math.PI * angle / 180);
thetaY = Math.Sin(Math.PI * angle / 180);
labelRectangle = new CWIMAQRotatedRectangle();
x = thetaX * labelTool.getRadius() + labelTool.getCenterX();
y = thetaY * labelTool.getRadius() + labelTool.getCenterY();
labelRectangle.Initialize((float)x, (float)y, labelTool.getWidth(), labelTool.getHeight(), (float)(360 - angle));
form.getViewer().Regions.AddRotatedRectangle(labelRectangle);
form.getViewer().Regions.Item(form.getViewer().Regions.Count).Active = false;
form.getViewer().Regions.Item(form.getViewer().Regions.Count).Visible = false;
form.getViewer().Regions.Item(form.getViewer().Regions.Count).PenColor = (uint)ColorTranslator.ToOle(Color.Magenta);
angle += angleIncrement;
}
And to inspect a region....
viewer.Regions.Item(regionIndex).Active = true;
vision.RegionsToMask(mask, viewer.Regions, false, 255);
vision.Histogram2(viewer.Image, report, options, mask);
viewer.Regions.Item(regionIndex).Active = true;
Hope this helps........
Thanks
Cliff
09-17-2008 10:03 AM
Hi riscoh,
Thanks for the info. I am sure it will benefit others in the future.