compose blending different with cropped image, why?

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?".
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

compose blending different with cropped image, why?

Post by fragileandys »

I have an image, and an almost exact copy of the same image that I am compose blending together with ModulusSubtract into one image:

Code: Select all

convert -page 185x230 img.jpg -page +0 copy.png -background none -compose ModulusSubtract -flatten out.png
However if I crop the copy.png image and try the same compose blending applying the offset (after finding it with -subimage-search), the final image doesnt appear to have the same blending applied:

Code: Select all

convert -page 185x230 img.jpg -page +4+5 copyCrop.png -background none -compose ModulusSubtract -flatten out.png
Why would I get different results just because one image is cropped? I am positive my offset of +4+5 is correct, as the images align perfectly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

Try removing the virtual-canvas created with the png image by adding +repage just before the output of your first command.
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

The +repage doesnt seem to have any effect.

Let me specify that the first command is the one that is working how I want it to and would like to replicate with the cropped image, comparing it to the original.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

where did you get the image copyCrop.png, if you used crop on a png, then it will have a virtual canvas. Try removing the virtual canvas with +repage on the cropped image. Or specify how you got copyCrop.png so we can see what is going on.
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

I didn't use IM to crop the image. I am on a mac, I opened the copy.png with the built-in 'preview' application, cropped it and saved it out from there.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

At this point I suggest you post links to your various input and output images, so others can review and test with them.

If you cannot post these images somewhere and link to them, then post the results of

convert copyCrop.png -verbose info:
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

Thanks for all your help fmw42!!

I just cropped the same image using photoshop and saving is as a ping and it worked fine. So 'preview' must do something strange to the image before it saves.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

fragileandys wrote:Thanks for all your help fmw42!!

I just cropped the same image using photoshop and saving is as a ping and it worked fine. So 'preview' must do something strange to the image before it saves.
Probably keeps the virtual-canvas, which can be removed by adding +repage after reading in the cropped image in your command line.
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

haha, thanks man, i'll mess around with that +repage more
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compose blending different with cropped image, why?

Post by anthony »

The +repage should be immediately after the -crop operation
PNG will save 'virtual canvas' information so doin it as two steps will not help.

photoshop and gimp does not preserve this information. IM does because it can be useful in later image processing stages.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

Anthony

So if the image is cropped in an outside program that saves the virtual canvas (the default 'preview' on a Mac), there's nothing I can do about it?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

fragileandys wrote:Anthony

So if the image is cropped in an outside program that saves the virtual canvas (the default 'preview' on a Mac), there's nothing I can do about it?

No, if the virtual-canvas is saved (and I don't know if Preview does that), all you need to do is add +repage after reading in your cropped image.

convert croppedimage.png +repage ....

PNG saves a virtual canvas, jpg does not.

You can check if your image has a virtual-canvas, by looking at the verbose info.

convert image -verbose info:

Look for the line near the bottom that is "page geometry" and see if it is the same size and zero offset as the image. If not, then there is a virtual canvas.

Or from identify

convert logo: -gravity center -crop 50x50%+0+0 logo.png
identify logo.png

logo.png PNG 320x240 640x480+160+120 8-bit PseudoClass 226c 14.5KB 0.000u 0:00.000


The blue is the actual image size. The red is the virtual canvas.


P.S. On my Mac OSX Snow Leopard, I tried to crop an image with Preview. But it does not look like it saves the virtual canvas for me. So I am puzzled why you are having this problem.
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

It doesnt appear that there is a virtual canvas applied to it. The 'Page Geometry' is the same as the 'identify' output.

What I'm doing is tiling a watermark across an image at .5% opacity. Then comparing the original image with the watermarked image to show the watermark.

If I crop the watermarked image with photoshop I am able to use -subimage-search and the output images from that show me the same difference I can see when when comparing the full images (i can see the watermark).

However when I crop using 'preview' then use -subimage-search, the outputted comparison image does not show me the watermark. So preview is doing something differently when cropping than photoshop is doing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose blending different with cropped image, why?

Post by fmw42 »

Is it possible to provide links to your images so that others can test. Also what was your exact command line for the compare in both cases? Note that the resulting x,y coordinates from compare refer to the upper left corner of the subsection (small image) in relation to the upper left corner of the larger image (not the center of the small image). What version of IM are you using?
fragileandys
Posts: 11
Joined: 2012-02-07T10:53:21-07:00
Authentication code: 8675308

Re: compose blending different with cropped image, why?

Post by fragileandys »

First off, this image is not my own. I do not own it and do not claim to have taken the photo.

photobucket album password: imtesting

The original image: http://i28.photobucket.com/albums/c242/ ... /image.jpg

The watermarked image: http://i28.photobucket.com/albums/c242/ ... m/copy.png

make a random crop of the watermarked image with photoshop saved as crop1.png then:

Code: Select all

compare -metric RMSE -subimage-search image.jpg crop1.png out.png
the out-0.png is: http://i28.photobucket.com/albums/c242/ ... /out-0.png


make a random crop of the watermarked image with mac's default 'preview' saved as crop2.png then:

Code: Select all

compare -metric RMSE -subimage-search image.jpg crop2.png out.png
the out-0.png is: http://i28.photobucket.com/albums/c242/ ... ut-0-1.png
Post Reply