-draw image unexpected results compared to composite cmd

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

-draw image unexpected results compared to composite cmd

Post 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
Last edited by rmagick on 2008-11-01T07:36:05-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -draw image unexpected results compared to composite cmd

Post 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.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: -draw image unexpected results compared to composite cmd

Post by rmagick »

32 minute turnaround! Not too bad :-) I'll pass this onto the RMagick user. Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -draw image unexpected results compared to composite cmd

Post 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?
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: -draw image unexpected results compared to composite cmd

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -draw image unexpected results compared to composite cmd

Post 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.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: -draw image unexpected results compared to composite cmd

Post 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!)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -draw image unexpected results compared to composite cmd

Post 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().
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -draw image unexpected results compared to composite cmd

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: -draw image unexpected results compared to composite cmd

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -draw image unexpected results compared to composite cmd

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: -draw image unexpected results compared to composite cmd

Post 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.
Post Reply