Page 1 of 1

object offset

Posted: 2012-05-25T13:31:59-07:00
by Tony
I am trying to determine the x,y coordinates for a simple image (circle) on a solid background. I am doing measurements of the object and need to determine the number of pixels in the diameter of the circle. The edges are faily sharp but the circle is not a solid color, it has small areas with some color deviations.
I tried a fx: expression to test for a non-background color and return the coordinates in a variable but I am sure there is an easier way.

This is a current release of IM in the windows environment.


Any suggestions would be appreciated.

Re: object offset

Posted: 2012-05-25T14:21:49-07:00
by fmw42
It would be nice to see your image. But without it, try making it binary and then get the mean of the image and multiply by the width and height. That will tell you the number of pixels that are white.

convert image -threshold XX% -format "%[fx:mean*w*h]" info:

note that [fx:mean] is in the range 0 to 1 so it acts as a fraction of the total pixels (w*h).

Alternately, binarize the image and look at its histogram which is located in the verbose information or can be generate separately. The count of the white pixels and black pixels will be there.

convert image -threshold XX% -verbose info:

or

convert image -threshold XX% -format "%c" histogram:info:

Re: object offset

Posted: 2012-05-25T20:45:59-07:00
by Tony
I should have mentioned that I did some testing with the convert function with numerous fuzz factors specifying the parameters you mentioned... (from a batch file)

convert %%a -threshold 30%% -format %%c histogram:info:

This seemed to be a promising approach as it would basically 'score' all the white area and provide a numerical representation of the area within the circle. This number would basically allow me to 'measure' the circle by the magnitude of the score. Unfortunately the accuracy was not as required. I need to be able to tell the difference between two circles with a difference of .050" with consistency. I suspect some small light areas within the certain circles were contributing to the error but I am not sure this is the best approach for this application.
I had the same issue when I tried to use the -metric option with various flags.

I was toying with the idea of sampling the color in progression via an -fx expression to scan the image for the edges (left/right or top/bottom) and doing simple math to determine the diameter. I was unable to get the fx expression to return a value that I could use. I am new to IM although I have done many programming projects and I am experienced with procedural and object programming. I just don't know enough about the IM capabilities and methods to solve this.

I do appreciate your response and I open to ideas. Perhaps I am approaching the problem from the wrong angle.
Here are some images that I am working with…

Image
and
Image

These are simple images but I need to be able to distinguish differences down to .050"

Thanks for your input.

Tony.

Re: object offset

Posted: 2012-05-25T21:12:18-07:00
by fmw42
Do you need to get the diameter of the inner white circle or the outer circle inside the dark circle? Either way, due to the texture of the outer area, the shadows and glare on the rings, I am not sure that is possible. The only other thing I could think of would be if you knew the exact center of the circles, then you could do a cartesian to polar transformation using -distort depolar. Then you could average all the columns down to one to get the average radius.

You could also draw circles and try to fit the circle to match. But that would be trial and error and would be best on some interactive system that would allow you to expand and contract easily along with drag to move the center around. Take a look at ImageJ. It allows you to draw a circle interactively, then get measurements that include area, perimeter, major and minor distances (of ellipse which in this case is circle), etc.

You could also look at OpenCV. I think it has circular Hough transforms. Look up Circular Hough transforms on Google. Unfortunately, IM does not have such tools at this time.

http://opencv.itseez.com/doc/tutorials/ ... ircle.html

Re: object offset

Posted: 2012-05-27T00:18:25-07:00
by anthony
If you can get a 'mask' of the circle. A simple diameter can be gotten just by 'trimming' the mask, and looking at the resulting image dimentions. That will get you X and Y diameters.

The key is determining what you want. A average of ALL the diameters or just any diameter?

Using the 'depolar' method. Don't bother finding the center. Just depolar. As long as the center of the image is somewhere in the circle the resulting image will have a epicycle function that can be calculated. Or look for the lowest and highest points (1/2 the image X wise from each other. Add those and you have the diameter, as well as a way of finding the 'center' of the object.

Fred did something similar recentally but with straight edges (of a square) instead of a circle.

Re: object offset

Posted: 2012-06-04T12:56:42-07:00
by VanGog
Hey, if you can get the mean, you can calculate surface of the circle. You must know size of the pixel. I am not mathematician but S = (r*r) * pi ... change this to get r and you have size of the cycle.

To get position you can search for first white pixel - which is the edge. So you have distance from edge of the image to edge of the object.

If you calculated radius r .. convert it to pixels and you have the line where the middle of the cycle is. Yet you would need to get y position. Ok. Then rotate the image on 90° and do the same as before to get position of white pixel.

So you know x,y and can do any detections later.

Edit: Maybe simplier would be to light up the object so that the light would go from both sides, not touching surface of the background, to create very dark background (almost black). This should give you better rounded shape with good contrast difference between background and the ring. Then just trim as anthony said.