does image size affects the imagemagick compare?

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
lizac
Posts: 15
Joined: 2011-03-25T19:39:37-07:00
Authentication code: 6789
Location: Philippines

does image size affects the imagemagick compare?

Post by lizac » 2011-06-10T18:15:33-07:00

hi! I have a program that runs daily. This program
1. takes screenshots using iMacros tool "SAVEAS" function.
2. the screenshots are compared from yesterday and today using iMageMagick.
3. since the screenshots have dynamic areas, I used the composite -gravity and composite -geometry to cover those dynamic areas before comparing them.
4. using the "compare -metric AE", yesterday and today's screenshots are compared. As soon as ImageMagick detected a change, it will send an email to me with the difference file attached.
5. Today's screenshot will be renamed to "yesterday.png" for the next day comparison so recent screenshots are only saved.

for sometime, I'm getting email with attached file that has no visible difference. Usually, difference areas has red colors. So I did some testing on taking screenshots before it is being processed by ImageMagick. With 3 days screenshot, I noticed that one of the screenshots has a different size. My questions are:

1. does the image size affect the compare function of ImageMagick? If yes, what metric should I use?
2. As I understand it, "compare" function works on images with the same dimension only. So this answers #1 question as well.
3. Why do I receive difference file with no visible difference (red colors)?
4. I would like to create logs for this program. As of now, I only have the iMacros process logged but not ImageMagick. Any ideas?

I hope you could find time to answer my inquiries. This is very important to me.

Thanks again!

User avatar
fmw42
Posts: 25112
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: does image size affects the imagemagick compare?

Post by fmw42 » 2011-06-10T19:42:31-07:00

1. does the image size affect the compare function of ImageMagick? If yes, what metric should I use?
2. As I understand it, "compare" function works on images with the same dimension only. So this answers #1 question as well.
3. Why do I receive difference file with no visible difference (red colors)?
4. I would like to create logs for this program. As of now, I only have the iMacros process logged but not ImageMagick. Any ideas?
First, this topic should probably be moved by one of the Forum managers to the User's forum. This forum, I believe, is for obscure image processing concepts that do not really pertain to how IM functions today. See viewtopic.php?f=22&t=18778 (Though no real issue about this, so don't worry about it)

Second, I am not sure what your exact command line is. You should post a link to example images as well and identify what version of IM and platform you are using.

Nevertheless, if I understand your comments, the images you are comparing are actually the same size (widthxheight), but you have masked out or cropped out the important areas so that the images are the same widthxheight. Assuming you have masked them, then you have different image content due to different amounts of masked area. Assuming you have cropped the images to be the same size, then their is either some offset or rotation or just lighting changes that make them different. Compare will make any difference show as red in the resulting image, if I understand it correctly. However, if you include a fuzz factor, the score will remain the same, but the difference image seems to ignore close matches.

For example:

Image

Now lets make it grayscale and force the near white to pure white:
convert cyclops.png -colorspace gray -white-threshold 97% cyclops_gt97.png
Image

Now lets change a 5x5 area so that it is one 8-bit graylevel different from white:
convert cyclops_gt97.png -size 5x5 xc:"gray(254)" -geometry +10+10 -compose over -composite cyclops_gt97_tmp1.png
Image

Now lets do a compare:
compare -metric rmse cyclops_gt97.png cyclops_gt97_tmp1.png cyclops_diff1.png
12.85 (0.000196078)
Image

Now lets do a compare including a fuzz factor:
compare -metric rmse -fuzz 10% cyclops_gt97.png cyclops_gt97_tmp1.png cyclops_diff2.png
12.85 (0.000196078)
Image





If your images are not the same size, then compare should likely give you an error message if you are using the most current version unless you use -subimage-search. On older version of IM this was not needed and would do a subimage search on the two different images if the large image was first and the small image was second. Two output images or a two-frame image would then be produced. The first would be similar to the same size difference image you got before. The second would be the match score image.

Until I can see an example of your two images that you think should match perfectly and your command line, it is really hard to second guess your problem.

I am not sure about this, but if -metric fuzz is used you may be able to do compare if the masked areas are transparent having it ignore the transparent pixels. But Anthony knows this metric best. If not, then perhaps some new metric might be needed to do this kind of thing. But then that would have to be requested on the Developers forum.

See http://www.imagemagick.org/Usage/compare/

Perhaps Anthony can say more on this whole issue.
Last edited by fmw42 on 2011-06-11T09:40:39-07:00, edited 1 time in total.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: does image size affects the imagemagick compare?

Post by anthony » 2011-06-11T06:01:38-07:00

Topic moved to "Users", a shadow topic (link) left in old form.

If the two images being compared are different sizes, "compare" should complain!

It is not designed to handle images of different sizes, though you can pre-process images to a similar size and use a fuzz factor to discount small changes.

Their was however a period (quite a long period) where this did not happen as two images of a different size meant compare did a sub-image search (very different technique). The current IM will complain, as a sub-image search will only be done is a specific option is given. That was added specifically to avoid this type of problem.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

lizac
Posts: 15
Joined: 2011-03-25T19:39:37-07:00
Authentication code: 6789
Location: Philippines

Re: does image size affects the imagemagick compare?

Post by lizac » 2011-06-13T07:12:55-07:00

Hi! anthony and fmw42. Thank you both for your responses. Below is the piece of the code I'm using:

ImageMagick 6.6.8-6 Q16, Windows 7 professional


1. " C:\path\to\iMacros.exe" -macro "screenshot_img.iim" -var_filename today_img
2. pushd C:\path\to\ImageMagick
3. composite -gravity south footer.png today_img.png today_img.png
4. composite -geometry 253x216+0+280 side.png today_img.png today_img.png
5. composite -gravity south footer.png today_%%G.png today_%%G.png
6. for /F %%A in ('compare -metric AE today_img.png previous_img.png diff_img.png 2^>^&1') do set Diff=%%A
7. if not "!Diff!"=="0" call :SendEmail
8. move today_img.png previous_img.png

just a few explanation:
1. is the code that calls the Imacros and take screenshot
2-6. Imagemagick code
7. just calling a program that sends email

I just can't simply post here the image for confidential reasons. I hope you understand. Anyways, here's the info of the image info:
http://min.us/mbfjEHpdu3RpsX

I'm still trying to understand what you posted above. I just felt that giving you this info will shed more light to my issues. Thanks a lot!

User avatar
fmw42
Posts: 25112
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: does image size affects the imagemagick compare?

Post by fmw42 » 2011-06-13T09:49:00-07:00

without some example it is really hard to know what might be happening nor exactly what you are doing.

what is the footer image. if it is a date and that date is changing between the two days and it shows in your image for comparison, then compare will detect that difference.

can you clarify further or provide a drawing of what you are doing to prepare the two day's images?

is it possible the camera moves sometimes a little due to wind or other factors, such as vibrations, etc?

lizac
Posts: 15
Joined: 2011-03-25T19:39:37-07:00
Authentication code: 6789
Location: Philippines

Re: does image size affects the imagemagick compare?

Post by lizac » 2011-09-19T09:06:15-07:00

Hi! Sorry for not getting back on this issue sooner.

Anyways, I just realized that composite -geometry is actually resizing the original image I have. Is there any command that I could use to overlay two solid-colored image (about 300x300 size) on the upper left and south respectively of 1078x1052 image without affecting the size of entire image (1078x1052). So this means that after overlaying, the image size should still be 1078x1052.

Or can I just overlay that part of the image with a solid color? Can you provide a sample command line?

Thanks so much again!

User avatar
fmw42
Posts: 25112
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: does image size affects the imagemagick compare?

Post by fmw42 » 2011-09-19T10:31:22-07:00

Try this


convert -size 1078x1052 xc:black \
-size 300x300 xc:red -gravity northwest -compose over -composite \
-size 300x300 xc:blue -gravity south -compose over -composite \
tmp.png

see
http://www.imagemagick.org/Usage/layers/
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/script/comma ... hp#gravity

Post Reply