fast identify for actual bit depth

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

fast identify for actual bit depth

Post by fmw42 »

The string formats "%z" and "%[depth]" only show 8 vs 16, etc (depending upon quantumrange). If one has a binary image the depth in the verbose info shows 8/1-bit.

It would be nice to get the actual bit-depth of 1 in this case.

Right now I can do it by extracting that from the IM verbose information.

# create depth 1 image

convert rose: -threshold 50% rose_t50.png
identify -verbose rose_t50.png
...
Depth: 8/1-bit

In unix, this could get extracted by

depth=`convert rose_t50.png -verbose info: | sed -n 's/^ Depth:[^0-9]*\(.*\)-bit$/\1/p' | tr "/" " " | cut -d\ -f2`
echo "$depth"
1

depth=`convert rose: -verbose info: | sed -n 's/^ Depth:[^0-9]*\(.*\)-bit$/\1/p' | tr "/" " " | cut -d\ -f2`
echo "$depth"
8


It might be nice to have a new string format

convert image -format "%[bit-depth] info:

or if one prefers

convert image -format "%[bitdepth] info:

That gets the actual bit depth such a 1
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: fast identify for actual bit depth

Post by dlemstra »

I prefer bit-depth, it will be available in the next release of ImageMagick.

Code: Select all

C:\Test>identify -format "%[bit-depth]" rose:
8
C:\Test>identify -format "%[bit-depth]" rose_t50.png
1
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: fast identify for actual bit depth

Post by fmw42 »

Thanks.

Fred
Post Reply