why image's depth changed?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
cndep
Posts: 3
Joined: 2011-03-06T06:20:13-07:00
Authentication code: 8675308

why image's depth changed?

Post by cndep »

I use this version:ImageMagick-6.6.0


convert -resize 50% bild.bmp test.bmp

the depth of the origin image is 4 bits,after convert the resulting image's depth is changed to 24,why?

I tried this:

convert -resize 50% -depth 4 bild.bmp test.bmp

but it does'nt work.

And I did some code:

while (MagickNextImage(magick_wand) != MagickFalse)
{
MagickScaleImage(magick_wand, iWidth, iHeight);
//after this the depth of the origin image is changed from 4 to 24 bits
}

I tried MagickSetImageDepth(magick_wand,4),but it does'nt work,why?

Code: Select all

while (MagickNextImage(magick_wand) != MagickFalse)
{
	MagickScaleImage(magick_wand, iWidth, iHeight);
	MagickSetImageDepth(magick_wand,4);
	blob = MagickGetImageBlob(magick_wand, &length);
	............
}

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

Re: why image's depth changed?

Post by fmw42 »

try putting the input image first and use BMP3: format

convert bild.bmp -resize 50% -depth 4 BMP3:test.bmp

see http://www.imagemagick.org/Usage/formats/#bmp for depth restrictions
cndep
Posts: 3
Joined: 2011-03-06T06:20:13-07:00
Authentication code: 8675308

Re: why image's depth changed?

Post by cndep »

fmw42 wrote:try putting the input image first and use BMP3: format

convert bild.bmp -resize 50% -depth 4 BMP3:test.bmp

see http://www.imagemagick.org/Usage/formats/#bmp for depth restrictions

Thanks,I tried,but it does'nt work.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: why image's depth changed?

Post by fmw42 »

Post a link to your image so others can test. You might try upgrading your IM to the latest version.

Also try

convert bild.bmp -resize 50% +dither -colors 16 -depth 4 BMP3:test.bmp

Note resize will interpolate colors to more than you started. So you need to force it back to 16 colors and depth 4.

You could try

convert bild.bmp -sample 50% BMP3:test.bmp

-sample will not interpolate colors, but will choose the closest color.



But this works for me on IM 6.6.8.1 Q16 Mac OSX Tiger

# create 4-bit png
convert rose: -colors 16 +dither -depth 4 rose.png
identify -verbose rose.png
Image: rose.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 70x46+0+0
Resolution: 72x72
Print size: 0.972222x0.638889
Units: Undefined
Type: Palette
Endianess: Undefined
Colorspace: RGB
Depth: 8/4-bit
Channel depth:
red: 4-bit
green: 4-bit
blue: 4-bit

Channel statistics:
Red:
min: 51 (0.2)
max: 238 (0.933333)
mean: 143.83 (0.564037)
standard deviation: 68.6489 (0.269211)
kurtosis: -1.41232
skewness: 0.0822659
Green:
min: 51 (0.2)
max: 238 (0.933333)
mean: 88.4739 (0.346957)
standard deviation: 52.5254 (0.205982)
kurtosis: 1.59146
skewness: 1.55269
Blue:
min: 34 (0.133333)
max: 238 (0.933333)
mean: 80.7658 (0.316729)
standard deviation: 52.2382 (0.204856)
kurtosis: 2.95706
skewness: 2.00768
Image statistics:
Overall:
min: 34 (0.133333)
max: 238 (0.933333)
mean: 104.356 (0.409241)
standard deviation: 58.3107 (0.22867)
kurtosis: 0.967865
skewness: 1.37136
Histogram:
54: ( 51, 51, 34) #333322 rgb(51,51,34)
363: ( 51, 51, 51) #333333 grey20
235: ( 51, 68, 51) #334433 rgb(51,68,51)
98: ( 85, 68, 51) #554433 rgb(85,68,51)
84: ( 85,136, 68) #558844 rgb(85,136,68)
241: (102, 51, 51) #663333 rgb(102,51,51)
270: (102,102, 85) #666655 rgb(102,102,85)
184: (119,153, 85) #779955 rgb(119,153,85)
153: (136,136,153) #888899 rgb(136,136,153)
247: (153, 51, 51) #993333 rgb(153,51,51)
116: (170,170,187) #AAAABB rgb(170,170,187)
118: (187, 68, 68) #BB4444 rgb(187,68,68)
340: (204, 51, 51) #CC3333 rgb(204,51,51)
249: (238, 51, 51) #EE3333 rgb(238,51,51)
268: (238, 85, 85) #EE5555 rgb(238,85,85)
200: (238,238,238) #EEEEEE rgb(238,238,238)
Colormap: 16
...



#convert 4-bit png to 4-bit bmp
convert rose.png +dither -colors 16 -depth 4 BMP3:rose.bmp
identify -verbose rose.bmp
Image: rose.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: PseudoClass
Geometry: 70x46+0+0
Resolution: 28.34x28.34
Print size: 2.47001x1.62315
Units: PixelsPerCentimeter
Type: Palette
Endianess: Undefined
Colorspace: RGB
Depth: 4-bit
Channel depth:
red: 4-bit
green: 4-bit
blue: 4-bit

Channel statistics:
Red:
min: 3 (0.2)
max: 14 (0.933333)
mean: 8.46056 (0.564037)
standard deviation: 4.03817 (0.269211)
kurtosis: -1.41232
skewness: 0.0822659
Green:
min: 3 (0.2)
max: 14 (0.933333)
mean: 5.20435 (0.346957)
standard deviation: 3.08973 (0.205982)
kurtosis: 1.59146
skewness: 1.55269
Blue:
min: 2 (0.133333)
max: 14 (0.933333)
mean: 4.75093 (0.316729)
standard deviation: 3.07283 (0.204856)
kurtosis: 2.95706
skewness: 2.00768
Image statistics:
Overall:
min: 2 (0.133333)
max: 14 (0.933333)
mean: 6.13861 (0.409241)
standard deviation: 3.43004 (0.22867)
kurtosis: 0.967865
skewness: 1.37136
Histogram:
54: ( 51, 51, 34) #333322 rgb(51,51,34)
363: ( 51, 51, 51) #333333 grey20
235: ( 51, 68, 51) #334433 rgb(51,68,51)
98: ( 85, 68, 51) #554433 rgb(85,68,51)
84: ( 85,136, 68) #558844 rgb(85,136,68)
241: (102, 51, 51) #663333 rgb(102,51,51)
270: (102,102, 85) #666655 rgb(102,102,85)
184: (119,153, 85) #779955 rgb(119,153,85)
153: (136,136,153) #888899 rgb(136,136,153)
247: (153, 51, 51) #993333 rgb(153,51,51)
116: (170,170,187) #AAAABB rgb(170,170,187)
118: (187, 68, 68) #BB4444 rgb(187,68,68)
340: (204, 51, 51) #CC3333 rgb(204,51,51)
249: (238, 51, 51) #EE3333 rgb(238,51,51)
268: (238, 85, 85) #EE5555 rgb(238,85,85)
200: (238,238,238) #EEEEEE rgb(238,238,238)
Colormap: 16
...

This also works:


convert logo: -resize 50% +dither -colors 16 -depth 4 BMP3:logo.bmp
identify -verbose logo.bmp

Image: logo.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: PseudoClass
Geometry: 320x240+0+0
Resolution: 28.34x28.34
Print size: 11.2915x8.4686
Units: PixelsPerCentimeter
Type: Palette
Endianess: Undefined
Colorspace: RGB
Depth: 4-bit
Channel depth:
red: 4-bit
green: 4-bit
blue: 4-bit

Channel statistics:
Red:
min: 1 (0.0666667)
max: 15 (1)
mean: 13.4754 (0.898359)
standard deviation: 3.94559 (0.26304)
kurtosis: 4.20909
skewness: -2.43552
Green:
min: 1 (0.0666667)
max: 15 (1)
mean: 13.3053 (0.887021)
standard deviation: 4.00473 (0.266982)
kurtosis: 3.06801
skewness: -2.16451
Blue:
min: 1 (0.0666667)
max: 15 (1)
mean: 13.5012 (0.900082)
standard deviation: 3.60552 (0.240368)
kurtosis: 4.3518
skewness: -2.35881
Image statistics:
Overall:
min: 1 (0.0666667)
max: 15 (1)
mean: 13.4273 (0.895154)
standard deviation: 3.85596 (0.257064)
kurtosis: 3.8738
skewness: -2.32518
Histogram:
1762: ( 17, 17, 17) #111111 rgb(17,17,17)
1585: ( 34, 34,102) #222266 rgb(34,34,102)
325: ( 34, 51,136) #223388 rgb(34,51,136)
2735: ( 34, 68,153) #224499 rgb(34,68,153)
143: ( 51, 85,136) #335588 rgb(51,85,136)
749: ( 85, 68, 34) #554422 rgb(85,68,34)
804: ( 85,102,102) #556666 rgb(85,102,102)
252: (119,136,119) #778877 rgb(119,136,119)
1064: (153,153,170) #9999AA rgb(153,153,170)
568: (204,102, 68) #CC6644 rgb(204,102,68)
1040: (221,170, 85) #DDAA55 rgb(221,170,85)
779: (221,204,204) #DDCCCC rgb(221,204,204)
295: (238,170,170) #EEAAAA rgb(238,170,170)
755: (238,238,238) #EEEEEE rgb(238,238,238)
783: (255, 17, 17) #FF1111 rgb(255,17,17)
63161: (255,255,255) #FFFFFF white
Colormap: 16
...
cndep
Posts: 3
Joined: 2011-03-06T06:20:13-07:00
Authentication code: 8675308

Re: why image's depth changed?

Post by cndep »

Thanks very much,the two methods both works.
Post Reply