ImageMagick compare executable: unrecognized option `-metric' # error/convert.c/ConvertImageCommand/2060 - imagemagick

I tried to use apt-get install imagemagick command to install ImageMagick on my Debian Wheezy. But when I try to diff images, I get following error:
root#work:/home/tests/YAML_SHOTS/en-us# convert 1.png 2.png -metric RMSE -compare 3.png
convert.im6: unrecognized option `-metric' # error/convert.c/ConvertImageCommand/2060.
Secondly, I tried to install ImageMagick from binary source (described here: http://www.imagemagick.org/script/install-source.php#unix). But it does not install the convert executable command.
How can I fix that?
P.S. If I remove -metric option, I get one more error:
convert.im6: unrecognized option `-compare' # error/convert.c/ConvertImageCommand/1107.

Use the compare utility directly.
compare 1.png 2.png -metric RMSE 3.png
But if you want to generate a image diff without sending the metrics to STDERR, define the -metric and -compare before the image stack.
convert -metric RMSE -compare 1.png 2.png 3.png

Assuming your ImageMagick version is a fairly recent one, try this command:
compare -metric phash 1.png 2.png delta.png
7.61662
The returned pHash value of 7.61662 indicates, that there was indeed some difference in the compared image, and that the delta.png will show some red highlighted pixels.
The red pixels indicate there is a difference in the color values of the respective pixels in the two compared images. White pixels indicate identical color values. The grayed-out, light color background of the delta.png is derived from the first image, in order to help identify better the differences in more complex images. If you do not want the background, run this modified command:
compare -metric phash 1.png 2.png -compose src delta.png
Above illustration depicts 1.png (left), 2.png (center) and delta.png (right).
Compare this to
compare -metric phash 1.png 1.png delta2.png
0
Here there is no difference, the pHash value is 0, and the delta2.png doesn't show any red pixels:
Above illustration depicts 1.png (left), 1.png (center) and delta2.png (right).
By default, the compare command will run with 72 PPI. If you need a higher resolution (for example, when comparing PDF pages), add -density 300 as the first parameter to get 300 PPI.

Related

how to search an image for subimages on linux

i've seen the answer of Mark Setchell (https://stackoverflow.com/users/2836621/mark-setchell), which seems to be outdated and not working anymore. How to search an image for subimages using linux console?
https://stackoverflow.com/a/31874879/17686212
How to search an image for subimages using linux console?
downloading the needle and creating the haystack image and "hiding" the needles within it works fine.
Needle Image
convert -size 256x256 gradient:lime-blue haystack.png
convert haystack.png needle.png -geometry +30+5 -composite haystack.png
convert haystack.png needle.png -geometry +100+150 -composite haystack.png
Running the specified compare Images command causes an error:
compare -metric RMSE -subimage-search haystack.png needle.png locations.png
compare: images too dissimilar `haystack.png' # error/compare.c/CompareImagesCommand/1166.
i've tried to apply -similarity-threshold and -dissimilarity-threshold and changed/lowered the convert location threshold but had no success aka bad results like this:
compare -similarity-threshold 0 -dissimilarity-threshold 1 -metric RMSE -subimage-search haystack.png needle.png locations.png
convert locations-1.png -threshold 95% txt: | grep white
locations-0.png
locations-1.png
I've used imagemagick version 7.1.0.14 on gentoo and 6.9.11.60+dfsg-1.3 on kali Linux
Hopefully you can help me to resolve this issue.
Here is how to do masked composite in ImageMagick 7.
Template:
Image:
Create Mask:
magick needle.png -transparent white -alpha extract mask.png
magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 haystack.png \( -read-mask mask.png needle.png \) compare.png
9031.97 (0.137819) # 100,150
Compare-0 (differences):
Compare-1 (match scores):
If you want to find the best matches, you would need to use my script, maxima
maxima -t 80 -n 10 compare-1.png
max=1 100,150 gray=56540,220,86.2745%
max=2 30,5 gray=54484,212,83.137%
You will not get a good result from ImageMagick 6 with
compare -metric rmse -subimage-search -dissimilarity-threshold 1 haystack.png needle.png compare.png
26789 (0.408773) # 96,114
because there is too much white in your needle image and it will mismatch with the green and blue in the haystack image. Unfortunately, you cannot do masked compare in ImageMagick 6.

What is distortion of a channel in an image?

I am relatively new to image processing, and I have a basic question: what is a distortion of red/green/blue channel, and the distortion of the entire image ?
taken from the imagemagick home site, in the compare command section:
In addition to the visual interpretation of the difference in an image and its reconstruction, we report a mathematical measure of the difference:
magick compare -verbose -metric mae rose.jpg reconstruct.jpg
difference.png Image: rose.jpg Channel distortion: MAE red: 2282.91
(0.034835) green: 1853.99 (0.0282901) blue: 2008.67 (0.0306503)
all: 1536.39 (0.0234439)
I dont understand the concept, can someone explain it to me ?
It's nothing to do with shape transformation or -distort if that is what is confusing you. All that "distortion" means, in this context, is "the specific error metric you requested". When comparing images there are various "metrics" you can select to measure:
AE
MAE
DSSIM
RMSE
etc.
and so on. The "distortion" is just a generic term meaning "whichever one of those you selected".
Here is a little example, a 100x10 red rectangle on a large black background.
convert -size 100x10 xc:red -bordercolor black -border 100 a.png
Now roll that 1-pixel to the right and re-save as b.png:
convert a.png -roll +1+0 b.png
Now compare absolute error:
compare -metric ae [ab].png null:
20
and you can see that the 10 pixels on the left and 10 pixels on the right of the red bar are "distorted".
Now roll down one pixel instead of across and compare again:
convert a.png -roll +0+1 b.png
compare -metric ae [ab].png null:
200
and the "distortion" is 100 pixels along the top pf the red bar that have become black and 100 pixels below the bottom of the red bar that have become red.
It may make more sense if you use the convert based method of comparing rather than the compare method. Here, you use the more common convert command with 2 images and then use -compare as the operator but you now will see the variable called distortion being used and that it just refers to whatever -metric you selected:
convert a.png b.png -metric AE -compare -format "%[distortion]" info:
200

Compare pixels moved but similar images using ImageMagick

When comparing two images, both of the images are the same, except that in one of the images the text is moved by a couple of pixels. Please take a look at the below URL. It is a GIF that shows the difference of both the similar images.
https://giphy.com/gifs/9x50JjoLSPZ7lKRebk
My team initially used compare command which doesn't address this issue. Need suggestions please?
You can remove all the text in Imagemagick and just compare the bars by thresholding the Saturation/Chroma channel and then doing the compare. The text is gray, so it has little if any saturation. The bars are cyan, so they are colored and have a medium to high saturation.
convert giphy.gif -colorspace HCL -channel g -separate +channel -threshold 5% +write tmp.gif miff:- | compare -metric rmse - null:
3164.96 (0.0482942)
So this is 4.8% different.
I save tmp.gif, which you do not need, only to show the result of the processing before the compare.
If your version of Imagemagick is too old and you do not have -colorspace HCL, then try HSL or HSB. C and S are similar and measure saturation/chroma.

imagemagick mean image sequence and ignore alpha channel

I want to get the mean of a sequence of images by using Imagemagick. Therefore I use the following command:
convert *.png -evaluate-sequence mean MEAN.png
Each of my images does contain an alpha channel. What I want is: Combine all the images by ignoring the alpha channel.
When I combine the images, the alpha channel is considered in the "mean" method and my final image has transparency. That isn't what I want.
Result:
I tried to add the parameter -alpha off, but then Imagemagick converts the alpha channel to black.
convert *.png -alpha off -evaluate-sequence mean MEAN.png
Result:
Photoshop does it right. I load all images in a stack and create a smart object. When I use the "mean" method in Photoshop, the alpha channel is not considdered in the final result.
Result that I want with Imagemagick:
Does someone have an idea how to do that with Imagemagick?
What you need to do is to use the alpha channels as weighting images for each image. The total fraction of white values at each pixel from all the alpha channels would be the weight to use for the average. So something like this should do what you want or at least be close.
First, cd to your directory of images. Then run the following.
convert *.png -evaluate-sequence mean \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
-delete 0 +swap -compose divide -composite result.png
This will work if there is some image texture at each pixel coming from al least one image. That is at a given pixel all images are not totally black (transparent).
compare -metric rmse result.png mean_photoshop.png null:
125.167 (0.00190993)
So this shows that there is about 0.2% difference between my result and what you got from photoshop
Maybe this way of working will help you get there - or at least explain the problem:
convert xc:"rgba(255,0,0,1)" xc:"rgba(0,0,0,1)" xc:"rgba(0,0,0,0)" -depth 8 -evaluate-sequence mean txt:
Output
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (21845,0,0,43690) #550000AA srgba(85,0,0,0.666667)
Using IM 6.8.9.4 Q16 or IM 7.0.5.5 Q16 Mac OSX Sierra, this seems to work fine for me:
Make transparent image
convert logo: -transparent white logot.png
Get mean
convert logot.png logot.png logot.png -alpha off -evaluate-sequence mean result.png
magick logot.png logot.png logot.png -alpha off -evaluate-sequence mean result.png
This also seems to work:
convert logot.png logot.png logot.png -channel rgb -evaluate-sequence mean -alpha off result.png
So perhaps you need to upgrade your ImageMagick (and/or libpng?)
Can you post a zip file of some of your input images, so we can test with your images?
One problem that I see is that the PNG images that you provided have black under the transparent areas and not image texture. So when you disable alpha as in my commands above, you see black and the black gets averaged into the final result. Did you use these same PNG images in Photoshop or did you have Photoshop PSD images or some other images that you used and then exported to PNG, which may have put black under the transparent areas. Have you tried using the same PNG images in Photoshop to do the average?
In fact, you have 8-bit color (palette) images, which have one color (black) assigned to be the transparent color.

How do I convert EXR to PNG and adjust brightness at the same time

I was able to convert my EXR image to a PNG using the techniques outlined in Image conversion from IFF and EXR formats to JPEG format .
convert 0007.exr /tmp/0007.png
Unfortunately the PNG looks quite dim.
What should I add to the imagemagick convert command line to increase the brightness?
Starting with this:
You could try -auto-gamma:
convert start.jpg -auto-gamma result.jpg
If the -auto-gamma overcooks the image for your liking, you could apply a percentage of it. So, here I clone the original image and apply auto-gamma to the clone but then only blend 80% back into the original because I feel auto-gamma overdoes it:
convert start.jpg \( +clone -auto-gamma \) \
-define compose:args=80 -compose blend -composite result.jpg
Or, another option, you could experiment with your particular images and maybe try using -modulate for the brightness, where 100% means "do nothing", so numbers over 100 increase the brightness:
convert start.jpg -define modulate:colorspace=LCHuv -modulate 160 result.jpg
You can try -auto-level, which will take the minimal value and the maximal value of your picture and then stretches the values to the full range of values:
convert input.exr -auto-level output.jpg
Note that if you picture was too bright and this does not help, then it might be that your image is stored with 32 Bit, while ImageMagick is working with 16 Bit and no HDRI support. 32 Bit input is supported if convert --version
either show Q32 as part of the version string or lists HDRI under features.
Depending on your operating system you might be able to install another variant of ImageMagick. For example, for Debian Buster we can use sudo apt list imagemagick* to see that the package imagemagick-6.q16hdri is available. Installing this package provides convert-im6.q16hdri, which allows reading 32 Bit EXR images.
EXR is in linear RGB colorspace. You want to convert it to non-linear sRGB colorspace in Imagemagick as:
Input:
convert image.exr -set colorspace RGB -colorspace sRGB output.png

Resources