6.9.3-0 hdri 12bpp jpeg "invalid colormap index"
Posted: 2016-01-20T12:02:03-07:00
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
However, ImageMagick identify -verbose reports the error "invalid colormap index"
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.
The block of code referenced in the "invalid colormap index" error is
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.
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!
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
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.
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.
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);
}
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;
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!