Page 1 of 2

Depth (not quantum depth) of image using identify

Posted: 2009-06-10T22:45:36-07:00
by Pravin
Hi,

I want to get depth (not quantum depth) of image using identify.

Is there any way to do so?

Thanks.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-06-11T07:53:53-07:00
by fmw42
see %z image depth from string formats at http://www.imagemagick.org/script/escape.php

identify -format "%z" yourimage

Re: Depth (not quantum depth) of image using identify

Posted: 2009-07-06T06:51:11-07:00
by Pravin
Thanks. Its working.
But it gives me result which are different from file summary (right click on image - properties - summary).
I am using Windows XP machine.
e.g.

for image1 if IM returns depth as 8, in file summary it shows 24
for image2 if IM returns depth as 16, in file summary it shows 48.

that mean on Windows it shows depth as a multiple of 3 of depth returned by IM.
Is there any such kind of relation exists for windows?

Re: Depth (not quantum depth) of image using identify

Posted: 2009-07-06T08:54:41-07:00
by fmw42
IM reports the depth per channel. Your windows is probably reporting the depth per image (all channels added together).

Re: Depth (not quantum depth) of image using identify

Posted: 2009-07-06T21:38:40-07:00
by anthony
See the note on Depth in IM Examples, Basics
HTTP://www.imagemagick.org/Usage/basics/#depth

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-26T08:06:19-07:00
by Pravin
Hi,

As I stated earlier, I am using ImageMagick on windows.
on Windows it shows depth as a multiple of 3 of depth returned by IM.

Is there any way so that, I can get depth per image (all channels added together) using identify.exe.
as
depth shown on windows = depth returned by IM x 3.

This formula does not work for all file formats (e.g. .gif)

Please help.

Thanks.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-26T09:39:22-07:00
by fmw42
sounds like a Windows issue. but please post a couple of links to one image that works and one that does not and show your identify and your Windows information. IM shows information in a consistent way as far as I know. So I would expect it is Windows that is not consistent. But a special -fx calculation and report may be workable for you in IM if you know which image types show correctly and which do not.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-27T03:23:48-07:00
by Pravin
Hi,

I think there is some information missing in my post.

When I say On Windows i.e. from file summary (right click on image - properties - summary) it shows different value.
which is - depth per image (all channels added together)

Is there any way to get depth per image (all channels added together).

Please help.
Thanks.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-27T08:29:51-07:00
by fmw42
If windows does not report this consistently (you said it did not for gif), then it is a Windows issue.

However, if you want IM to give you the depth per channel * 3, then you can use

img="rose:"
depth=`convert $img -format "%z" info:`
colorspace=`convert $img -format "%[colorspace]" info:`
[ "$colorspace" = "RGB" ] && depth=`convert xc: -format "%[fx:3*$depth]" info:`
echo "$img depth = $depth"
rose: depth = 24

If the image is grayscale, then you will just get 8

Note, however, if you are on Q16 IM, then you could get a depth per channel of 16 and thus 16*3=48 for a result

If you always want the 8-bit equivalent even on Q16, then

img="rose:"
depth=`convert $img -depth 8 -format "%z" info:`
colorspace=`convert $img -format "%[colorspace]" info:`
[ "$colorspace" = "RGB" ] && depth=`convert xc: -format "%[fx:3*$depth]" info:`
echo "$img depth = $depth"
rose: depth = 24

Other than this, there is no way that I know to get IM to report the total depth of the image. You have to compute it from the number of channels and the depth per channel

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-28T00:25:58-07:00
by Pravin
Hi,

Thanks a lot for your help.

I have another question, How to get number of channels and the depth per channel for image using identify.exe.
Basically I want to show depth per image (all channels added together).

Please Help.
Thanks.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-08-28T09:10:39-07:00
by fmw42
It is the same with identify as with convert except you don't need the "info:"

identify -format "%z" rose:
8
identify -format "%[colorspace]" rose:
RGB

Re: Depth (not quantum depth) of image using identify

Posted: 2009-10-05T02:52:00-07:00
by Pravin
Hi,

My issue is still not solved.
Please help me.

I have read the articles from following link.
HTTP://www.imagemagick.org/Usage/basics/#depth

Here is the content from that site related to image depth.
---------------------------------------------------------------------------------------------------
Depth - file format bit depth
Now most image formats are of depth 8. That is they use 8 bits (or a value from 0 to 28-1) to hold each color value used in the image. That is a value of 0 to 255 for red, 0 to 255 for green, and 0 to 255 for the blue channel. More usually this type of image is referred to as 24 bit images (total bits, NOT the channel bit depth), and includes such formats as such as JPEG), or 32 bit images if you also have an alpha channel, such as a typical PNG images).

What a lot of people refer to as 8 bit images, are really a image with an 8 bit palette or color map (giving a 256 color limit over the whole image). While such images are also a 8 bit depth, that is not what is being referred to. GIF images are a good example of this.

Transparency in such images are usually handled either by specifying a specific color as representing transparency (set using the "-transparent-color" meta-data setting) as in GIF format, or using a special profile for a specific number of colors in the color table in a PNG8 image. However only a single color transparency is implemented in IM bit image formats at this time.

In general...

24 bit images are : 3 x 8 bit depth values 3 color channels only
32 bit images are : 4 x 8 bit depth values 3 colors + Alpha channel
8 bit images are : 8 bit color mapped image, with 256 color limit

Because most image formats only save color values at an 8 bit depth, a lot of people install IM using a 'Q' or Quality level of depth 8, which requires far less memory and processes images faster than a more normal Q16 version of IM. Often 3 or more times faster. These Q8 versions work well for general image processing and converting, and can be used for generating simple images, annotating, or overlaying images.
------------------------------------------------------------------------
In this article, author explains the depth of jpeg, png and gif image types. Depth changes as the per the channel used
in this image formats.
Now my questions are...
1. How we can consider all these aspects and calculate the total image depth using identify.exe. My system expects the total image depth.

As per the suggested by "fmw42", I have tried to get no of channels of .gif type.
It shows me "RGB". But when I view the properties (On Windows Xp - right click on Images + Summary tab), it shows depth as 8. I am not getting this.

Please help me.

Thanks a lot.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-10-05T16:19:56-07:00
by anthony
GIF is limited to 256 colors. The colors are stored in a table (colormap or color table), that is at most 256 long. The color in that table is 3 x 8 bit channel RGB colors.

The actual pixel data however is a 8 bit value (0-255) that is an index into that color table. That is the 'raster' or 'array' of pixels is not 3 x 8 bit colors, like it is in PNG and JPEG, but a index that can be used to lookup the actual color from the color table.

Because the actual pixel data is only a 8bit lookup index, it is classed as a 8 bit image, even though the actual colors are still 3 x 8 bit channels.

What you need to look for is RGB and a colormap also known PseudoClass, ro PattetteMatte...

Code: Select all

identify -verbose http://www.imagemagick.org/Usage/images/scroll.gif |\
     head -20
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 177x131+0+0
Resolution: 72x72
Print size: 2.45833x1.81944
Units: Undefined
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
Channel statistics:
red:
min: 0 (0)
max: 200 (0.784314)
This image is RGB in that it has 3 channels (GIF always has three channels, just as most images do) But the image is also of type "PaletteMatte" meaning it has a colortable of some length, and could have transparency.

The channel depths has a 1-bit alpha so it is boolean tansparency (just on/off no semi-transparency). In colormaps that means ONE color index (the transparency index) is designated as being transparent.

Further down the verbose identification you will see
Colormap: 256
which means the image has only a 256 colors in its color table, which as it is less than (or equal to) 256 means it is a 8-bit colormaped RGB image.



PNG can use store colors either in a colortable OR directly in the 'raster' (more typical). However its colortable can be larger than 256. Typically however it also limits colortables to 256, as a way to make the image file smaller. Using more than 256 colors will go to the rare 16 bit image form, than that does not have a good file size saving, to make it worth the effort.


I have tried to make this clearer in IM Examples.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-10-06T23:19:34-07:00
by Pravin
Hi,

Thanks a lot for your help.

One question:
Is that means, "GIF" file types are always of 8-bit depth?
and other formats depth(jpeg, png ...etc) can be calculated by depth returned by identify command multiple by 3.

Thanks.

Re: Depth (not quantum depth) of image using identify

Posted: 2009-10-06T23:30:47-07:00
by anthony
Yes GIF is always 8-bit depth.

Other formats like PNG, and I believe TIFF too, can also have color tables too.

PNG8: file format is what IM calls a PNG with a color table (GIF like with boolean transparency).


Image file depth is basically the number of bits used per pixel in the raster array it stores. TIFF can also have a 1 bit depth (bitmap image).