Measuring curve lengths and irregular areas
Posted: 2012-10-31T02:18:44-07:00
I'm not sure if this should go here or in the image processing section, so apologies if I'm in the wrong place.
I was tinkering with some of the tools I am adding to my windows interface for IM. One of these tools lets you lay out a bezier curve or polyline (open or closed) etc. on top of an image, it then produces an MVG string for the shape. Then it hit me if I Draw this shape with a white Stroke and Stroke-Width 1 on a black canvas then I could use Statistics or a Histogram to count the white pixels and get the length of the curve. I could use this method to measure any object in the original image. The same idea would work for areas just draw the curve with a white fill.
But before you get carried away there are potential snags, especially with the curve length mainly to do with antialiasing. If you turn antialiasing off (stroke-antialias 0) you get a chunky curve which is two pixels wide in some places but is pure black and white. On the other hand if you leave antialiasing on you get a smoother looking curve which is no longer black and white but shades of grey as well.
So I have a few questions someone may be able to answer:-
1. Is it better to draw the curve with antialiasing on and use statistics, or off and use histogram to add up/count whiteness?
2. What width should the curve be, would you get a more accurate result with a wider curve and deviding the result by the stroke width?
3. Is there a best shape to draw as a test curve to scale the results with, e.g. I could draw a circle of known circumferance and use the result to correct other curve lengths?
4. How accurate is the greyness of antialias pixels, if a pixel wide curve cuts a canvas pixel in half will the colour be half quantum range?
5. Would any Morphology technique work on a non-antialiased curve to correct for the curve being two pixels wide in places?
Alan Hadley
I was tinkering with some of the tools I am adding to my windows interface for IM. One of these tools lets you lay out a bezier curve or polyline (open or closed) etc. on top of an image, it then produces an MVG string for the shape. Then it hit me if I Draw this shape with a white Stroke and Stroke-Width 1 on a black canvas then I could use Statistics or a Histogram to count the white pixels and get the length of the curve. I could use this method to measure any object in the original image. The same idea would work for areas just draw the curve with a white fill.
But before you get carried away there are potential snags, especially with the curve length mainly to do with antialiasing. If you turn antialiasing off (stroke-antialias 0) you get a chunky curve which is two pixels wide in some places but is pure black and white. On the other hand if you leave antialiasing on you get a smoother looking curve which is no longer black and white but shades of grey as well.
So I have a few questions someone may be able to answer:-
1. Is it better to draw the curve with antialiasing on and use statistics, or off and use histogram to add up/count whiteness?
2. What width should the curve be, would you get a more accurate result with a wider curve and deviding the result by the stroke width?
3. Is there a best shape to draw as a test curve to scale the results with, e.g. I could draw a circle of known circumferance and use the result to correct other curve lengths?
4. How accurate is the greyness of antialias pixels, if a pixel wide curve cuts a canvas pixel in half will the colour be half quantum range?
5. Would any Morphology technique work on a non-antialiased curve to correct for the curve being two pixels wide in places?
Alan Hadley