Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Getting the actual bit depth of an image

Even if an image is saved as a 16bit file, it often originates from a camera that produced only 10 or 12 bits. I would like to be able to check if some - and which - bits of an image file are always zero.

I.e. the camera produces XXXXXXXXXXXX, it gets written as XXXXXXXXXXXX0000 or as 0000XXXXXXXXXXXX

Edit: Here are 4 files as an example, 8bit, 10bit, 12bit and 16bit: https://filesender.uninett.no/?s=download&token=6a6f7f90-708d-4636-ba71-949acaaaded3

question from:https://stackoverflow.com/questions/66062566/getting-the-actual-bit-depth-of-an-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get the bit-depth with ImageMagick in the shell with:

magick identify -format "%[bit-depth]"  12-bit_000000.dpx 
12

Or, to get them all in one go, prefixing with filenames:

magick identify -format "%f: %[bit-depth]
"  *.dpx 
10-bit_000000.dpx: 10
12-bit_000000.dpx: 12
16-bit_000000.dpx: 16
8-bit_000000.dpx: 8

You can see all other details like this:

magick identify -verbose 12-bit_000000.dpx

Sample Output

Image:
  Filename: 12-bit_000000.dpx
  Format: DPX (SMPTE 268M-2003 (DPX 2.0))
  Class: DirectClass
  Geometry: 2048x1536+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: TrueColor
  Endianness: LSB
  Depth: 12-bit
  Channel depth:
    Red: 12-bit
    Green: 12-bit
    Blue: 12-bit
  Channel statistics:
    Pixels: 3145728
    Red:
      min: 0  (0)
      max: 2373 (0.579487)
      mean: 502.223 (0.122643)
      ...
      ...

You can get a copious dump of the pixels in hex like this:

magick 12-bit_000000.dpx txt: 

Sample Output

...
...
118,2: (6897.58,6977.6,8017.83)  #1AF21B421F52  srgb(10.525%,10.6471%,12.2344%)
119,2: (6945.59,7121.63,8033.84)  #1B221BD21F62  srgb(10.5983%,10.8669%,12.2589%)
120,2: (6769.55,7329.68,7921.81)  #1A721CA21EF2  srgb(10.3297%,11.1844%,12.0879%)
121,2: (6465.48,7441.7,7825.79)  #19411D121E92  srgb(9.86569%,11.3553%,11.9414%)
...
...

You can find the brightest pixel like this:

identify -define identify:locate=maximum 12-bit_000000.dpx 

Channel maximum locations:
   Red: 37976.7 (0.579487) 1144,1311
   Green: 36376.3 (0.555067) 1146,1311
   Blue: 34808 (0.531136) 1146,1314

That tells you the brightest area is near (1144,1311), so we can crop out that 4x4 area and dump it in hex:

magick 12-bit_000000.dpx -crop 4x4+1144+1311 txt:

# ImageMagick pixel enumeration: 4,4,65535,srgb
0,0: (37976.7,36040.2,34407.9)  #94598CC88668  srgb(57.9487%,54.9939%,52.5031%)
1,0: (37672.6,36248.3,34455.9)  #93298D988698  srgb(57.4847%,55.3114%,52.5763%)
2,0: (37208.5,36376.3,34407.9)  #91598E188668  srgb(56.7766%,55.5067%,52.5031%)
3,0: (36808.4,36088.3,34055.8)  #8FC88CF88508  srgb(56.1661%,55.0672%,51.9658%)
0,1: (37880.7,35704.2,34055.8)  #93F98B788508  srgb(57.8022%,54.4811%,51.9658%)
1,1: (37544.6,36040.2,34151.8)  #92A98CC88568  srgb(57.2894%,54.9939%,52.1123%)
2,1: (37416.6,36360.3,34407.9)  #92298E088668  srgb(57.094%,55.4823%,52.5031%)
3,1: (37096.5,35992.2,34055.8)  #90E88C988508  srgb(56.6056%,54.9206%,51.9658%)
0,2: (37768.6,35592.1,33991.8)  #93898B0884C8  srgb(57.6313%,54.3101%,51.8681%)
1,2: (37544.6,35960.2,34183.8)  #92A98C788588  srgb(57.2894%,54.8718%,52.1612%)
2,2: (37528.6,35992.2,34487.9)  #92998C9886B8  srgb(57.265%,54.9206%,52.6252%)
3,2: (37464.6,35560.1,34279.8)  #92598AE885E8  srgb(57.1673%,54.2613%,52.3077%)
0,3: (37560.6,35624.2,34263.8)  #92B98B2885D8  srgb(57.3138%,54.359%,52.2833%)
1,3: (37336.5,35816.2,34519.9)  #91D98BE886D8  srgb(56.9719%,54.652%,52.674%)
2,3: (37544.6,35640.2,34808)  #92A98B3887F8  srgb(57.2894%,54.3834%,53.1136%)
3,3: (37688.6,34968,34439.9)  #933988988688  srgb(57.5092%,53.3578%,52.5519%)

Hopefully you can see that the hex of each sample ends in 8 implying the bottom 3 bits are clear.


There are Python bindings to ImageMagick called wand.


Another option altogether is exiftool:

exiftool 10-bit_000000.dpx 

Sample Output

ExifTool Version Number         : 12.00
File Name                       : 10-bit_000000.dpx
Directory                       : .
File Size                       : 12 MB
File Modification Date/Time     : 2021:02:08 09:50:32+00:00
File Access Date/Time           : 2021:02:08 09:59:45+00:00
File Inode Change Date/Time     : 2021:02:08 09:50:32+00:00
File Permissions                : rw-r--r--
File Type                       : DPX
File Type Extension             : dpx
MIME Type                       : image/x-dpx
Byte Order                      : Little-endian
Header Version                  : V2.0
DPX File Size                   : 12584960
Ditto Key                       : New
Image File Name                 : 10-bit_000000.dpx
Create Date                     : 2021:02:01 10:45:32
Creator                         : flashSuite 2 3.4.5
Project                         : Colour test
Copyright                       : 2021
Encryption Key                  : ffffffff
Orientation                     : Horizontal (normal)
Image Elements                  : 1
Image Width                     : 2048
Image Height                    : 1536
Data Sign                       : Unsigned
Components Configuration        : R, G, B
Bit Depth                       : 10              <--- HERE IT IS
Image Description               : 
Source File Name                : 
Source Create Date              : 
Input Device Name               : SpinnerS
Input Device Serial Number      : 5CFC3FE89CDB
Frame Rate                      : 16
Frame ID                        : 
Slate Information               : 
User ID                         : 
Image Size                      : 2048x1536
Megapixels                      : 3.1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...