Read img medical image without header in matlab
Asked Answered
G

2

1

I have a radiograph .img file without the header file. However, the researchers who have published the file have given this information about it

High resolution (2048 x 2048 matrix size, 0.175mm pixel size)
Wide density range (12bit, 4096 gray scale)
Universal image format (no header, big-endian raw data)

Using this information, I tried fread command in Matlab to read the image into Matlab.

fid = fopen('image.img','r','B');
oneSlice = fread(fid, [2048 2048], '*uint8','B');
imshow(oneSlice)

However the resulting image is coming up as incorrect. Is there something that I am doing wrong ? Could someone suggest any different method to read this image file ?

Geraldina answered 17/4, 2014 at 18:54 Comment(1)
You need to read it as 16bit, not 8bit, as it contains 12bit data. Try '*uint16' instead. Also I'm not sure if 'B' is accepted, as the documentation says to use 'b'.Superpose
F
2

The lung x-rays of the JSRT database (www.jsrt.or.jp/jsrt-db/eng.php), have that format. I tested this code with them and it works:

fid = fopen('image.img','r','b');
oneSlice = fread(fid, [2048 2048], '*uint16','b');
img = mat2gray(oneSlice, [0,4096]);
fclose(fid);
Foreyard answered 19/5, 2014 at 1:17 Comment(0)
W
0
%%% Read image
    fid = fopen('image.img','r','b');
    oneSlice = fread(fid, [2048 2048], '*uint16','b');
    img = mat2gray(oneSlice, [0,4096]);
    fclose(fid);

%%%rotate image

    imgR = imrotate(img,270);

%%%horizontal flip image

    imgRF = flipdim(TestImgR ,2);  
Works answered 22/12, 2014 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.