Page 1 of 1

Affine matte stack

Posted: 2007-01-01T22:40:12-07:00
by rmabry
I don't know if this is a bug, an undesirable effect or an expected result. But I was surprised to find that under some conditions (which I have not pinned down), stacked (appended) images behave differently depending on the order of the images, even when of the same size, perhaps with some dependence on which has a matte channel. The following perl script illustrates it, the results being at the link below.

http://sun.cs.lsus.edu/~rmabry/magick/m ... ndtest.plx

Code: Select all

#!/usr/bin/perl -- 

use Image::Magick;

$image1 = new Image::Magick;
$image1->Read("logo:");
$image1->Resize('50%');  #needn't be so big for this demo
$image1->Border(width=>4, height=>4, color=>'blue'); #shows up better

($w,$h) = $image1->Get('width', 'height');
$image2 = $image1->Clone();  # two identical images


$image1->AffineTransform(affine=>[1,1,-1,1,0,0]); # any affine matrix can be used here
$image1->Resize("$w x $h!"); # make both images the same size 

#uncomment either of the two following and rerun for comparison
# $image2->Draw(primitive=>'line', stroke=>'black', points=>sprintf("0,0 %d,%d", $w-1,$h-1));
# $image2->Set(matte=>'true');

# Now make two stacked images, each stack having the two images in different orders
$image12 = $image1->Clone();
$image21 = $image2->Clone();

$image12->[1] = $image2;
$image21->[1] = $image1;

$image12 = $image12->Append(stack=>'false');
$image21 = $image21->Append(stack=>'false');

# the two images differ, but not in the way I'd have expected

$image12->Border(width=>4, height=>4, color=>'#eeccee'); #shows up better
$image21->Border(width=>4, height=>4, color=>'#eeccee'); #shows up better

$image12->Write("image12.png");
$image21->Write("image21.png");

Bug or feature? And bug or feature of what? (AffineTransform? Append?) And what happens when either of the two commented-out commands is included? What then makes it come out "right"?

While I'm at it, I am surprised at the way Border works on the stacked images, too.

This is 6.3.1-4 12/24/06 Q16

I hope everyone stayed home last night and got 'pixellated'.

Rick

Posted: 2007-01-02T08:39:58-07:00
by magick
ImageMagick algorithms works in either of RGB, RGBA, CMYK, or CMYKA colorspaces. If your image is RGB it does not copy the matte channel when updating pixels. That accounts for the different behavior for Append(). By default you are working in RGB. When call Draw() or Set() you are promoting the image to RGBA which tells the append algorithm to copy the opacity channel along with the red, green, and blue channels.

Posted: 2007-01-02T10:11:41-07:00
by rmabry
magick wrote: If your image is RGB it does not copy the matte channel when updating pixels. That accounts for the different behavior for Append().


But this seems the opposite -- the entire RGB image is "promoted" to RGBA with a completely transparent matte, evidently obtained from the border or background, even though that is not true of the RGBA image (which is not entirely transparent). The RGB image turns into a big blank. That doesn't seem friendly.

And what about the result of the final border command? These do not have the "borders" I'd expect or want as a result of the final commands in the script above:

http://sun.cs.lsus.edu/~rmabry/magick/matte-append/

Posted: 2007-01-02T10:32:34-07:00
by magick
We will have a patch for this problem and the append problem by tommorrow. Thanks for the problem report.