Page 1 of 1
Special image comparison
Posted: 2015-10-11T07:17:02-07:00
by lansmnet
Hi all,
I would like to compare and find differences (expect white color) of 2 images by sectors, by 5 degrees for example, and if it possible than change white color to red of the secton with marginal differencdes. Currently I'am experimenting with IM in windows CMD. I know this is pretty complicated and difficult algoritm but any ideas are welcome.
Sample image:
Image to compare with sample and find anomalies:
Testing method:
Thank you forward for your help.
Re: Special image comparison
Posted: 2015-10-11T07:57:32-07:00
by snibgo
For graphics images, don't use JPEG unless someone is holding a gun to your head.
"-compose Difference -composite" gives 7 small white blobs on a black background. "-morphology erode" can reduce each to a single white pixel. Many techniques can find the coordinates of those white pixels, eg make black transparent and output to "sparse-color:".
I don't understand what you want then. Perhaps the "+" represents a known coordinate, and you want the distance and angle from that coordinate to each of the white pixels. Simple trigonometry will calculate that.
Re: Special image comparison
Posted: 2015-10-11T08:09:31-07:00
by lansmnet
Hi snibgo,
the "+" represents the origo point. This is not on the image originally. From that point I want to compare sectors. Is there any function in IM for comparing just a specified areas of two same size images?
Re: Special image comparison
Posted: 2015-10-11T08:27:05-07:00
by snibgo
"-distort depolar" will convert the image to a polar representation, where the x-axis is the angle from north, and the y-axis is the distance from the centre. I've named your samples as blob1.jpg and blob2.jpg:
Code: Select all
convert blob1.jpg -distort depolar -1 d1.png
convert blob2.jpg -distort depolar -1 d2.png
With appropriate resizing, each column would represent 5 degrees. Then:
Code: Select all
convert d1.png d2.png -compose Difference -composite c.png
... gives the locations.
Re: Special image comparison
Posted: 2015-10-11T12:09:03-07:00
by lansmnet
Hi snibgo, thanks for your kind support.
It's working but extreamly slowly. I am comparing images by 10pixel width columns. Should I use different image format instead of png?
Here is my .bat file:
@echo off
setlocal enableextensions enabledelayedexpansion
set /a "x = 0"
set /a "error = 0"
:while1
if %x% leq 100 (
set /a "x = x + 10"
convert sample/sample.png -crop 10x1200+%x%+0 sample/cropped_sample.png
convert totest/totest.png -crop 10x1200+%x%+0 totest/crops/cropped%x%.png
compare -metric AE sample/cropped_sample.png totest/crops/cropped%x%.png null:
goto :while1
)
endlocal
Also I dont know how to return and save to error variable the compare functions value.
Re: Special image comparison
Posted: 2015-10-11T13:17:29-07:00
by snibgo
For speed, don't use png for temporary results. Use miff instead.
Better yet, don't save temporary results. Combine the two converts and compare into a single convert.
Even with that, you would still read both inputs multiple times. Converting both to miff and re-reading that would be quicker. Better, just create one large convert command that reads both inputs, and creates many pairs of crops, each with a "-compare".
"compare" writes the text output to stderr.
You might get some tips from "whatRot.bat" on my "What rotation?" page.
Re: Special image comparison
Posted: 2015-10-11T14:25:32-07:00
by fmw42
If you are creating files once and reading them multiple times, then MPC format should be faster. See
http://www.imagemagick.org/Usage/files/#mpc