我有一个 12 位 pgm-image,我用 imread 读取它。结果是一个 16 位图像,其值在 0 到 2^16 - 1 的整个范围内。
Matlab 如何进行扩展?将要
X = imread('filename');
X = uint16(double(X)*((2^12-1)/(2^16-1)));
恢复原来的强度?
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.
解决方法就像这样
function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = floor(out_image./16);
return
或者向右执行 4 位移位:
function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = bitshift(out_image,-4);
return
更多信息可以在这里找到:http://www.mathworks.com/matlabcentral/answers/93578-why-are-12-bit-pgm-images-scaled-up-to-16-bit-value-representation-in-image-processing-toolbox- 7-10 http://www.mathworks.com/matlabcentral/answers/93578-why-are-12-bit-pgm-images-scaled-up-to-16-bit-value-representation-in-image-processing-toolbox-7-10
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)