Enhancement Suggestion

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Enhancement Suggestion

Post by fmw42 » 2017-05-16T16:10:51-07:00

If this is not a large effort, then perhaps compare might be enhanced to permit other operations within parenthesis processing, such as:

-resize
-rotate
-trim
-crop
-distort SRT
-brightness-contrast
-level
-sigmoidal-contrast

This would allow modification of the reference image in-line (without having to process externally and save to file) the image so that one may be able to loop over compare more efficiently to test different rotations and/or sizes (and possibly adjust the brightness/contrast).



Alternately, perhaps enhance

convert .... -compare -format "%[distortion] info:

to allow subimage-search and to report the coordinates of the best match.

snibgo
Posts: 8659
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Enhancement Suggestion

Post by snibgo » 2017-05-16T16:36:38-07:00

This would be useful. My preference would be to allow "-subimage-search", "‑dissimilarity‑threshold" and "‑similarity‑threshold" within both "convert" and "magick", with reporting of the found coordinates.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-16T16:43:04-07:00

If the developers want to rewrite compare or convert ... -compare, a large degree of speedup can be achieved using summed area tables. See
https://en.wikipedia.org/wiki/Summed_area_table
https://classes.soe.ucsc.edu/cmps160/Fa ... 7-crow.pdf
https://computersciencesource.wordpress ... ral-image/

P.S. Here are fast histograms and median filtering using summed area tables. See
https://nomis80.org/ctmf.pdf
http://www.merl.com/publications/docs/TR2005-057.pdf

User avatar
magick
Site Admin
Posts: 10554
Joined: 2003-05-31T11:32:55-07:00

Re: Enhancement Suggestion

Post by magick » 2017-05-16T17:55:57-07:00

We'll add the operators you suggested to the 'compare' command-line utility in the next point release of ImageMagick.

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-17T11:13:28-07:00

Thanks. Would you add the following also, so that the background can be set during rotation and the texture under transparency can be set to a constant color and a mask extracted from the transparent reference

-background
-virtual-pixel
-alpha (background, extract, off)

User avatar
magick
Site Admin
Posts: 10554
Joined: 2003-05-31T11:32:55-07:00

Re: Enhancement Suggestion

Post by magick » 2017-05-17T12:18:09-07:00

We added support for -background. The other two options are already supported.

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-17T13:11:32-07:00

Thanks

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-18T20:30:23-07:00

I tried this command in the latest beta:

Code: Select all

im6beta compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( 224977object4.png +repage -background black -alpha background -rotate 180 -trim +repage \) \
diff.png
but it errors with regard to +repage. Would you add repage, please.

(Images from viewtopic.php?f=1&t=31928&start=15#p146149)

User avatar
magick
Site Admin
Posts: 10554
Joined: 2003-05-31T11:32:55-07:00

Re: Enhancement Suggestion

Post by magick » 2017-05-19T04:30:56-07:00

Done.

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-19T14:07:34-07:00

Thanks. This command works now in the latest IM 6.9.8.6 beta as of today.

Code: Select all

compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( 224977object4.png +repage -background black -alpha background -rotate 180 -trim +repage \) \
diff.png
4808.31 (0.0733701) @ 269,40

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-19T14:33:46-07:00

Sorry, one more request. Would you add +-write and +-delete so that I can save to mpr: format, such as in the following for IM 7 with masking:

magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( 224977object4.png +repage -background black -alpha background -write mpr:ref +delete \
mpr:ref -alpha extract -write mpr:mask +delete \) \

\( -read-mask mpr:mask mpr:ref \) diff.png

compare: unrecognized option `-write' @ error/compare.c/CompareImagesCommand/1079.



Or if this extra parens to create the mpr: images in the above is not possible, then would you allow parenthesis processing for the mask image and reference image separately, so that I can do

im7beta magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( -read-mask \
\( 224977object4.png +repage -background black -alpha background -alpha extract \) \
\( 224977object4.png +repage -background black -alpha background \) \
\) diff.png

compare: unable to open image '(': No such file or directory @ error/blob.c/OpenBlob/3094.
compare: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509.

User avatar
magick
Site Admin
Posts: 10554
Joined: 2003-05-31T11:32:55-07:00

Re: Enhancement Suggestion

Post by magick » 2017-05-19T17:05:24-07:00

Done.

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-20T17:02:34-07:00

The commands below do not seem to work to rotate the small image 180 deg and compare to the larger image in the latest IM release 7.0.5.7.

Inputs:
Image
Image

This command errors:

Code: Select all

magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( -read-mask \
\( 224977object4.png +repage -background black -alpha background -alpha extract \) \
\( 224977object4.png +repage -background black -alpha background \) \
\) diff7.png
compare: unable to open image '(': No such file or directory @ error/blob.c/OpenBlob/3094.
compare: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509.


This command finishes but is not the proper match:

Code: Select all

magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 370669patch.png +repage -background black -alpha background \) \
\( -read-mask 224977object4.png +repage -background black -alpha background -alpha extract \) \
\( 224977object4.png +repage -background black -alpha background \) diff7.png
Image

It should produce something similar to the IM 6.9.8.6 command that does not use a mask and achieves a perfect match as follows:

Code: Select all

convert \
\( 370669patch.png +repage -background black -alpha background \) \
\( 224977object4.png +repage -background black -alpha background \) miff:- |\
compare -metric rmse -subimage-search -dissimilarity-threshold 1 - diff6.png
0 (0) @ 353,6
Image

Was the last set of changes folded into this release or the upcoming Beta? Or am I not doing something correctly?

User avatar
fmw42
Posts: 20937
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion

Post by fmw42 » 2017-05-20T17:17:44-07:00

Sorry, the following does work properly in IM 7.0.5.7 with the following command approach and shows a perfect match at the proper location

Code: Select all

magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 \
\( 224977object4.png +repage -background black -alpha background -write mpr:ref +delete \
mpr:ref -alpha extract -write mpr:mask +delete \) \
\( 370669patch.png +repage -background black -alpha background \) \
\( -read-mask mpr:mask mpr:ref \) -alpha off diff.png
0 (0) @ 353,6


Thanks. So I can use parenthesis processing with mpr:

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests