DrawImage changes to higher BitDepth

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
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

DrawImage changes to higher BitDepth

Post by cuongvn08 » 2017-01-10T00:01:36-07:00

My ImageMagick version in Linux is 6.7.7-10
I used the function drawImage() to add some circles into the 8-bit bmp.
However, the problem is after adding some circles, bitdepth of image became 24-bit.
Hopefully, I would like to keep the same bitdepth as the original image.

Is this a bug of ImageMagick or its real design?
Is there any suggestion to keep the same bitdepth?

Thanks so much!

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo » 2017-01-10T00:35:48-07:00

Your drawing may be aliased, in which case the boundary of areas and lines "merge" with the background, creating many new colours. You can prevent this with anti-aliasing.

You can also reduce your image to 255 colours.
snibgo's IM pages: im.snibgo.com

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

Re: DrawImage changes to higher BitDepth

Post by fmw42 » 2017-01-10T00:46:13-07:00

What format was the output? If PNG, then you can do PNG8:output.png to keep 8-bit color per image. With other formats add -type palette before the output. If snibgo is correct, you can add +antialising to keep from introducing new colors. Or use -type palette before saving to force it to 8-bit per image.

IM 6.7.7.10, is very old (about 200 version old) and was during a time when IM colorspace was changing. You might consider upgrading, if you can depending upon your OS.

cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post by cuongvn08 » 2017-01-10T00:53:23-07:00

@fmw42, my output image is still bmp.
My application was written in php.
Code is simply like belows:

$img = new Imagick($image_input_8bit_bmp)

$draw = new ImagickDraw();
$draw->setStrokeOpacity(1);

$img->drawImage(draw);
$img->writeImage(image_output);


Finally, image_output is 24-bit bmp.
Is there any suggestion here to keep original bitdepth? Thanks.

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo » 2017-01-10T01:03:02-07:00

What are you drawing?
snibgo's IM pages: im.snibgo.com

cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post by cuongvn08 » 2017-01-10T01:15:23-07:00

@snibgo
I am going to add some circles but I disabled all these codes. Because I want to see the effect of ImagickDraw.
Even I just created an object of ImagickDraw and did not add anything, bitdepth of image_output was changed to 24.
My full code here:

$img = new Imagick($image_input_8bit_bmp)

$draw = new ImagickDraw();
$draw->setStrokeOpacity(1);

/*
for ($i=0; $i < count($array); $i++)
{
$draw->circle($array[$i][0], $array[$i][1], $array[$i][2]);
}
*/

$img->drawImage(draw);
$img->writeImage(image_output);

Of course, if I disable $img->drawImage(draw), bitdepth of image_output is still 8-bit.
That's why I confused the problem may be drawImage() and ImagickDraw. And this is a bug of ImageMagick.

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo » 2017-01-10T01:25:05-07:00

So, is your input image paletted? If so, have you tried SetImageStorageClass() before writing?
snibgo's IM pages: im.snibgo.com

cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post by cuongvn08 » 2017-01-10T01:32:28-07:00

@snibgo,
my input image is just grey-scale image.
I have not tried SetImageStorageClass() before writing.

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: DrawImage changes to higher BitDepth

Post by glennrp » 2017-01-10T11:55:59-07:00

As others said, you need to turn off antialiasing.

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

Re: DrawImage changes to higher BitDepth

Post by fmw42 » 2017-01-10T12:08:04-07:00

If you add color to a grayscale image, it will automatically increase the bit depth from 8-bits per image to 24-bits color per image (3 channels of 8-bits), unless you force the result to -type palette (8-bits color per image).

cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post by cuongvn08 » 2017-01-10T16:55:58-07:00

glennrp wrote:
2017-01-10T11:55:59-07:00
As others said, you need to turn off antialiasing.
Could you please show me how can I turn off anti-aliasing?
And what is the effect of anti-aliasing here?
Thank you.

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo » 2017-01-10T18:55:28-07:00

snibgo's IM pages: im.snibgo.com

Post Reply