Special image comparison

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
lansmnet
Posts: 4
Joined: 2015-10-11T06:25:11-07:00
Authentication code: 1151

Special image comparison

Post 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

Image to compare with sample and find anomalies:
Image

Testing method:
Image

Thank you forward for your help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Special image comparison

Post 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.
snibgo's IM pages: im.snibgo.com
lansmnet
Posts: 4
Joined: 2015-10-11T06:25:11-07:00
Authentication code: 1151

Re: Special image comparison

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Special image comparison

Post 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.
snibgo's IM pages: im.snibgo.com
lansmnet
Posts: 4
Joined: 2015-10-11T06:25:11-07:00
Authentication code: 1151

Re: Special image comparison

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Special image comparison

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Special image comparison

Post 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
Post Reply