如何在 MATLAB 中读取 RAW RGB 图像?

How do I read a RAW RGB image in MATLAB?

我正在尝试正确转换 RAW 图像,以便我可以在 MATLAB 中查看它。图片可以下载here. I am using the version of the code provided in How can I read in a RAW image in MATLAB? 但是,它对我来说不能正常工作。下面是我稍作修改的版本:

clear;
row=966;  col=1296;
fin=fopen('C:\Users\user\Desktop\test2.raw','r');
I=fread(fin, col*row*3,'uint8=>uint8'); %// Read in as a single byte stream
I = reshape(I, [col row 3]); %// Reshape so that it's a 3D matrix - Note that this is column major
Ifinal = flipdim(imrotate(I, -90),2); % // The clever transpose
imshow(Ifinal);
fclose(fin); %// Close the file

我得到的:

我应该得到什么:

我不确定为什么它对我不起作用但是如果我使用成像程序 (ImageJ) 如果我 select 图像类型为 '24- 我可以正确转换 RAW 文件位 BGR'。图片的像素格式为8 Bit BAYRG。

好了:

function q43127920
row=966; col=1296;
fin=fopen('test.raw','r');
I = fread(fin, col*row*3,'ubit24=>uint32');
I = reshape(I, col, row, []); 
B = uint8(bitand(bitshift(I,-00),uint32(255)));
G = uint8(bitand(bitshift(I,-08),uint32(255)));
R = uint8(bitand(bitshift(I,-16),uint32(255)));
I = cat(3,R,G,B);
Ifinal = flip(imrotate(I, -90),2);
imagesc(Ifinal);
fclose(fin);

结果: