6.9.3-0 hdri 12bpp jpeg "invalid colormap index"

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mmmaxwwwell
Posts: 2
Joined: 2016-01-20T10:42:50-07:00
Authentication code: 1151

6.9.3-0 hdri 12bpp jpeg "invalid colormap index"

Post by mmmaxwwwell »

I'm attempting to use ImageMagick 6.9.3-1 to convert a medical X-ray format into a more common one, be it a png, bmp or whatever. I have zero documentation on this file format. I have zero access to the software that loads the image. I'm hoping this wonderful community can help me out here.

So far I have determined it is a grey scale jfif with 12 bits per pixel.

I have compiled ImageMagick to enable decompression of 12 bit jfifs, which is where the problem may lie, but more on that later.

ImageMagick identify outputs no errors

Code: Select all

C:\libjpeg\ImageMagick-6.9.3-1\VisualMagick\bin>identify.exe C:\Users\alexander\
Desktop\708_885_5856.xdr
C:\Users\alexander\Desktop\708_885_5856.xdr JPEG 1896x1368 1896x1368+0+0 12-bit
Gray 4096c 659KB 0.000u 0:00.000
However, ImageMagick identify -verbose reports the error "invalid colormap index"

Code: Select all

C:\libjpeg\ImageMagick-6.9.3-1\VisualMagick\bin>identify.exe -verbose C:\Users\a
lexander\Desktop\708_885_5856.xdr
Image: C:\Users\alexander\Desktop\708_885_5856.xdr
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: PseudoClass
  Geometry: 1896x1368+0+0
  Units: Undefined
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 12/16-bit
  Channel depth:
    gray: 16-bit
  Channel statistics:
    Pixels: 2593728
    Gray:
      min: 0 (0)
      max: 319.989 (0.0781415)
      mean: 0.0593298 (1.44883e-05)
      standard deviation: 2.68324 (0.000655247)
      kurtosis: 3867.56
      skewness: 57.5931
      entropy: 0.00257194
  Colormap entries: 4096
  Colormap:
  Rendering intent: Undefined
  Gamma: 0.454545
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1896x1368+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 84
  Orientation: Undefined
  Properties:
    comment: ♦
    date:create: 2016-01-12T12:53:56-05:00
    date:modify: 2016-01-19T16:41:03-05:00
    jpeg:colorspace: 1
    jpeg:sampling-factor: 1x1
    signature: f913f28ee8f54a718a3224d8b097f5cf3086509c6e4229974f4ce8570fd97f6e
  Artifacts:
    filename: C:\Users\alexander\Desktop\708_885_5856.xdr
    verbose: true
  Tainted: False
  Filesize: 659KB
  Number pixels: 2.594M
  Pixels per second: 41.2KB
  User time: 62.672u
  Elapsed time: 1:04.010
  Version: ImageMagick 6.9.3-1 Q16 x64 2016-01-19 http://www.imagemagick.org
identify.exe: Invalid colormap index `C:\Users\alexander\Desktop\708_885_5856.xd
r' @ error/colormap-private.h/ConstrainColormapIndex/34.
This seems strange to me because identify was able to calculate the statistics for the gray channel, and "Colormap entries" registers as 4096.

When I attempt to use ImageMagick to convert one of these images, I end up with a appropriately sized grey scale image that is 99% black pixels, and I get the "invalid colormap index" message. I am aware that the maximum pixel value of 319 is ~7% of the range; I have run the command with -auto-levels and i'm still not seeing any satisfactory results.

Code: Select all

C:\libjpeg\ImageMagick-6.9.3-1\VisualMagick\bin>convert.exe -verbose C:\Users\al
exander\Desktop\708_885_5856.xdr C:\Users\alexander\Desktop\output.png
C:\Users\alexander\Desktop\708_885_5856.xdr JPEG 1896x1368 1896x1368+0+0 12-bit
Gray 4096c 659KB 61.844u 1:02.400
C:\Users\alexander\Desktop\708_885_5856.xdr=>C:\Users\alexander\Desktop\output.p
ng JPEG 1896x1368 1896x1368+0+0 16-bit Gray 22c 9.73KB 0.391u 0:00.187
convert.exe: Invalid colormap index `C:\Users\alexander\Desktop\708_885_5856.xdr
' @ error/colormap-private.h/ConstrainColormapIndex/34.
The block of code referenced in the "invalid colormap index" error is

Code: Select all

static inline IndexPacket ConstrainColormapIndex(Image *image,
  const size_t index)
{
  if ((index < image->colors) && ((ssize_t) index >= 0))
    return((IndexPacket) index);
  (void) ThrowMagickException(&image->exception,GetMagickModule(),
    CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
  return((IndexPacket) 0);
}
Which seems to make sense, index is coming in > 4095 or < 0.

I'm not very familiar with Visual Studio or c++, so please bear with me. When I was setting libjpeg to read 12 bit images, I came across a line of code in jdct.h that caught my attention. The middle word "UINT32" on the middle line was underlined in red.

Code: Select all

typedef INT32 DCTELEM;      /* must have 32 bits */
typedef UINT32 UDCTELEM;
typedef unsigned long long UDCTELEM2;
Visual Studio does not recognize UINT32 as a valid data type, so to compile, I tried defining UDCTELEM as an unsigned long, unsigned short, and an unsigned int, all with the same "invalid colormap index" result. I don't think UDCTELEM's datatype is the issue.

I found a program at http://www.imageconverterplus.com that can read and convert the image. This program confirms that it is indeed a 12bpp(12 bits per sample 1 sample per pixel) jpeg in "Extended sequential" mode, in the grayscale colorspace with DCT & Huffman compression.

Does anyone have any ideas? Please tell me I'm an idiot and all I have to do is add a flag or something!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: 6.9.3-0 hdri 12bpp jpeg "invalid colormap index"

Post by snibgo »

I didn't know that IM could process 12-bit JPEGs. Perhaps it can't, and that's the fundamental problem

A developer would need to comment.
snibgo's IM pages: im.snibgo.com
mmmaxwwwell
Posts: 2
Joined: 2016-01-20T10:42:50-07:00
Authentication code: 1151

Re: 6.9.3-0 hdri 12bpp jpeg "invalid colormap index"

Post by mmmaxwwwell »

Well technically ImageMagick doesn't process the jpegs, a library that it uses does. I also compiled that library for 12 bpp jpegs. If you look in my first post, you'll see that it calculates an average pixel value, among other things.

Code: Select all

Channel statistics:
    Pixels: 2593728
    Gray:
      min: 0 (0)
      max: 319.989 (0.0781415)
      mean: 0.0593298 (1.44883e-05)
      standard deviation: 2.68324 (0.000655247)
      kurtosis: 3867.56
      skewness: 57.5931
      entropy: 0.00257194
How can it come up with any of those values if ImageMagick can't read the data?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: 6.9.3-0 hdri 12bpp jpeg "invalid colormap index"

Post by snibgo »

As you say, it clearly is reading the data. But is it reading the data correctly? I don't know. You say the output is 99% black, which is consistent with the low values reported by "identify". Is this the expected output?

A developer would need to comment.
snibgo's IM pages: im.snibgo.com
Post Reply