Convert raw image data to lossless PNG or TIFF?

Hello,

I've got some files dumped from radiographic software and apparently made up of raw data, 2 bytes per pixel.

Since I can't open them in any image editor (I tried GIMP, Photoshop, IrfanView and a few others), I'd like to know how to convert them into a lossless format (preferably but not necessarily limited to C++), like PNG (one specification of it handles 24bit so it'd be fine) or TIFF, which should natively support 16bit pixels.

Here's a sample file, it's just called "data" without any extension, it's just 13 MB: http://s000.tinyupload.com/?file_id=08235066018321542051

In Processing 3.0 I've been suggested the following code, however I don't know where is the image size stored within the file nor why does its image size behave so that it had to be rounded (and I guess also lose/distort, even if just slightly, its native ratio).

What sets this raw data apart from other raw data that should be loaded just fine by image processing software?


Thank you very much

Allison


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
byte[] data;
 
public void settings() {
  size(2336, 2928); // image is 2328 wide but round up to next nearest 32
}
 
public void setup() {
  data = loadBytes("image.raw");
  noSmooth();
  noLoop();
}
 
public void draw() {
  background(0);
  loadPixels();
  int index = 256; // skip metadata
  for (int y = 0 ; y < height ; y++) {
    for (int x = 0 ; x < width ; x++) {
      int c = data[index + 1] & 0xff; // only using msbyte of 16 bit data
      pixels[y * width + x] = (65536 + 256 + 1) * c; // greyscale
      index += 2;  // 16 bit colour = 2 bytes
    }
  }
  updatePixels();
  save("hand.png");
}
I've looked at the file itself. It begins with a 256-byte header containing the following text:
__RowAlignmentBoundary=32;
__BitsStored=16;
__BitsAllocated=16;
__Columns=2328;
__Rows=2928;
__TypeName=Agfa.Healthcare.Medicad.Common.BulkData.DataContainer.DCImage;
__AssemblyName=Medicad.Common.BulkData.DataContainer;
__BulkSize=13679616

(Use any hex editor to examine the file contents).

Based on that information, I was able to open the file in photoshop, after renaming it with the .RAW extension. When prompted in the file open dialogue, I used the following values:
Dimensions
Width 2336 pixels
Height 2928 pixels

Channels
Count 1
16 Bits
IBM PC

Header
Size 256 Bytes


Note, the width figure I used was 2336 rather than 2328, the extra bytes are 'padding' to make it a multiple of 32.


Sorry, I've not looked at your code yet, that's as far as I got.
Last edited on
There was a question,
why does its image size behave so that it had to be rounded (and I guess also lose/distort, even if just slightly, its native ratio).

The extra bytes are added simply because certain computer systems may be able to process the data more efficiently when it is aligned in memory on word boundaries. It doesn't cause any distortion, it simply adds a black border on the edge of the image, this isn't part of the image itself and can be cropped out in an image editor, or better, omitted/skipped over when reading from the file.

I started to write some code to parse the contents of the header, so far my code is both ugly and fragile, so I won't post it here. However, it appears that the first four bytes of the file contain a 32-bit integer with the value 256, which is the offset from the start of the file to the beginning of the image data (effectively the length of the full header). The next four bytes are another 32-bit integer with the value 233 - that is the length of the text stored in the header. The text itself starts at offset 8 from the start of the file.
Topic archived. No new replies allowed.