Page 1 of 1

Adjusting images automatically

Posted: 2011-06-21T09:24:49-07:00
by typos
Hello,

in a workflow I get pictures from a webcam that should be compared to some reference images. As the webcam angle might change due to "physical interference" (a.k.a. people bumping into the construction) I would like to adjust the image automatically before comparing it to others.

Two ways I thought about:
1) There is a yellow cross or something similar in the image. If there is a way I can get the coordinates of the edges of the cross, I could use the IM distort function for the right adjustments. But how do I get these coordinates? Histogram voodoo? (I'm using Ruby and RMagick at the moment, but this shouldn't be a limitation.)

2) I read about software for panorama stitching which works similarly. Maybe there is some command line tool that works for my use case? (The Photoshop function Auto-Align layers seems perfect but it can't be used in a command line tool or with two different images.)

Thanks in advance for any suggestion! (Maybe someone has a completely different idea?)

Re: Adjusting images automatically

Posted: 2011-06-21T10:14:25-07:00
by fmw42
typos wrote: 1) There is a yellow cross or something similar in the image. If there is a way I can get the coordinates of the edges of the cross, I could use the IM distort function for the right adjustments. But how do I get these coordinates? Histogram voodoo? (I'm using Ruby and RMagick at the moment, but this shouldn't be a limitation.)
You will have to do something like segmentation of some form (or possibly thresholding, etc) to isolate the cross (perhaps by color). Then edge extract that and convert the result to txt: format and filter so that you only return the edge pixels and not the background, which will give you the coordinates of the edges. Without seeing the image, it is hard to say whether IM can do the "segmentation" as it does not have much in that area other than thresholding and color changing, etc.

Another way, might be to make a reference image that is the cross. Then use the compare function to located the coordinates of the best match of the reference image to the other images. This will then give you the offsets of the two images. Unfortunately, it won't help with rotation. See IM function compare with two different size images. An example is at viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076, but in newer version of IM you need to add -subimage-search

compare -metric rmse -subimage-search largeimage smallimage resultimages

where resultimages is one filename, but will produce either two images -0, -1 or two frames depending upon the image format

Re: Adjusting images automatically

Posted: 2011-06-21T17:41:44-07:00
by anthony
Locating objects in images is difficult. It is even harder when you don't have a reference image to work with.

A yellow cross however should not be too difficult. I woudl start as Fred Weinhaus (previous response) suggested, and extract a mask of 'yellow' or near yellow colors. See...
Replacing Colors in images
http://www.imagemagick.org/Usage/color_basics/#replace
especially see (getting 'near blue colors' example)...
http://www.imagemagick.org/Usage/color_ ... z_distance

HINT.. first map any pixels that are not the right color to say black, then map anything not black to white.

The next step is to clean up any noise or other interference in locatoing those crosses. This is what Morphology is typically used for. Later it is also used to find specific shapes, such as a cross, (rotations can be tricky).

At the end you should end up with the pixel locations of the center of the cross. Though you may like to consider other techniques for finding a more exact sub-pixel location. however if you have multiple crosses, picking which cross is which can still be a problem. One solution is to get distance and angle measurements between these locations so as to determine their relation to each other.

These coordinates can then be feed to distortions to distort one image into another, or to a standard reference image for comparison.

If you like to continue discussion these techniques, respond with a example image and results of various operations.
Others can then try other technqiues and perhaps we can work out a general processing method.

Re: Adjusting images automatically

Posted: 2011-06-27T13:21:39-07:00
by typos
Image
Here's the situation. Actually this is made to find out the status on the display.
The way you both suggest seems okay to me, do I have to worry about the performance? This is the problem with subimage search as it takes ages to process.

Re: Adjusting images automatically

Posted: 2011-06-27T14:26:49-07:00
by fmw42
subimage search from compare can be made faster by using FFT processing via my normcrosscorr, script.

see my unix bash scripts below and also http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr

but you need to be in Q16 HDRI mode for IM compilation to use it.

Re: Adjusting images automatically

Posted: 2011-06-27T20:16:57-07:00
by anthony
However masking the colors, and using morphology to find the center of those crosses may work better.