Page 1 of 1

-draw image unexpected results compared to composite cmd

Posted: 2008-11-01T07:00:15-07:00
by rmagick
An RMagick user reports a difference between compositing using DrawImage and compositing using CompositeImage. I've reproduced it using plain ImageMagick commands. This is 6.4.4 on 64-bit Ubuntu.

Here's the input image: Image
This convert command produces the image shown below. I enlarged it 8x for clarity:

Code: Select all

convert -size 40x40 xc:white -draw "image over 10,10,0,0 priority_07.png" -resize 800% bad-compose.png
Image
This composite command produces the expected results.

Code: Select all

composite priority_07.png -gravity center -size 40x40 xc:white -resize 800% good-compose.png
Image

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T07:32:38-07:00
by magick
The draw command uses DrawAffineImage() rather than CompositeImage(), however, we did find an off-by-one error which is fixed in the ImageMagick Subversion trunk available sometime tomorrow. Thanks.

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T07:53:53-07:00
by rmagick
32 minute turnaround! Not too bad :-) I'll pass this onto the RMagick user. Thanks!

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T08:24:55-07:00
by fmw42
rmagick wrote:An RMagick user reports a difference between compositing using DrawImage and compositing using CompositeImage. I've reproduced it using plain ImageMagick commands. This is 6.4.4 on 64-bit Ubuntu.

Here's the input image: Image
This convert command produces the image shown below. I enlarged it 8x for clarity:

Code: Select all

convert -size 40x40 xc:white -draw "image over 10,10,0,0 priority_07.png" -resize 800% bad-compose.png
Image
This composite command produces the expected results.

Code: Select all

composite priority_07.png -gravity center -size 40x40 xc:white -resize 800% good-compose.png
Image

Strange, but resulting image names seems opposite to me. The draw seems to make a good result and the composite seems to be clipping the edges in some way. Was this a typo or am I missing something?

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T10:34:29-07:00
by rmagick
The names are right. Examine the original image closely and you'll see that the "good" image is a more accurate representation of the original.

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T11:31:58-07:00
by magick
We released ImageMagick 6.4.5-3 with a patch for this problem. Give it and try and let us know if more work is needed.

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T13:49:50-07:00
by rmagick
I installed 6.4.5-3 and gave it a try. Here's the new output from -draw image (DrawAffineImage):
Image
This is much better but it's not my place to say if it's sufficient. I'll let you know if the RMagick user has any questions or comments. (Or he might choose to post here directly.)

I do think that the output from the composite command is superior. For reference, on the left is the original priority_07.png enlarged 800% with GIMP and overlaid onto a white background. On the right is the output from the composite command.
Image Image

Thanks again for the quick turnaround. (It's not quite 7 hours since my original post. Not too shabby!)

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-01T14:04:34-07:00
by magick
We need to use DrawAffineImage() in the -draw option because it supports the -affine option to rotate / shear / translate the image. We would not expect the results to perfectly match that of CompositeImage().

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-04T17:18:27-07:00
by anthony
I think the problem may be the virtual pixel leaking into the draw affine. Try setting -virtual-pixel white and seeing if the result is better.

Remember the default -virtual-pixel setting is 'edge' and that must NOT change as it is vital to the default handling of simple operations such as blur.

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-05T16:16:31-07:00
by rmagick
I'm not seeing any difference, Anthony.

Code: Select all

convert -size 40x40 xc:white -virtual-pixel white -draw "image over 10,10,0,0 priority_07.png" -resize 800% anthony-compose.png
Image

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-05T16:44:58-07:00
by anthony
No the above result looks good. I was thinking of the other previous results, which had what looked like there were extra 'clipped' circles on the very edge.

Re: -draw image unexpected results compared to composite cmd

Posted: 2008-11-05T16:55:49-07:00
by rmagick
I agree, the result looks good. It may be that it's what the user wants. I haven't heard from him since last Friday.