imread如何扩展12bit图像?

jol*_*olo 3 matlab imread

我有一个12位的pgm图像,我用imread读取.结果是16位图像具有在0到2 ^ 16-1的整个范围内的值.

Matlab如何扩展?将

 X = imread('filename');
 X = uint16(double(X)*((2^12-1)/(2^16-1)));
Run Code Online (Sandbox Code Playgroud)

恢复原来的强度?

drs*_*lks 5

MATLAB可以正确加载PGM 12位图像.但是,在MATLAB加载图像后,图像值将从12位重新调整为16位.

MATLAB使用以下算法将值从12位缩放到16位:

% W contains the the 12-bit data loaded from file. Data is stored in 16-bit unsigned integer
% First 4 bits are 0. Consider 12-bit pixel color value of ABC
% Then W = 0ABC
X = bitshift(W,4); % X = ABC0
Y = bitshift(W,-8); %Y = 000A
Z = bitor(X,Y); %Z = ABCA 
% Z is the variable that is returned by IMREAD.
Run Code Online (Sandbox Code Playgroud)

对此的解决方法就是这样

function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = floor(out_image./16);
return
Run Code Online (Sandbox Code Playgroud)

或者,向右执行4位移位:

function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = bitshift(out_image,-4);
return
Run Code Online (Sandbox Code Playgroud)

更多信息可以在这里找到:http: //www.mathworks.com/matlabcentral/answers/93578-why-are-12-bit-pgm-images-scaled-up-to-16-bit-value-representation-in -图像-处理-工具箱-7-10