使用逆映射显示GreyScale图像

时间:2016-08-24 16:34:56

标签: matlab mapping grayscale

我有一个像[0.1,...... 0.7..0.3]这样的矩阵(包含最大值和最小值的100多个元素) 我如何将其转换为灰度图像,使得0.1(最小元素)具有最亮的强度(255)并且最大元素具有0(在这种情况下为0.7)

1 个答案:

答案 0 :(得分:0)

检查以下代码示例:

%Prepare input for demostration:
I = imread('cameraman.tif'); %Load sample image.
I = double(I)/255; %Convert to double format in range [0, 1].
I = (I*(0.7-0.1)) + 0.1;    %Modify the range of I to [0.1, 0.7] (linear transformation).
%%%%%%%%%%%%%

%Now I is: "A matrix like [0.1, ....0.7..0.3] (100+ elements containing a max and min value)"

%Convert I from range [0.1, 0.7] to [0, 255], and save result to J:
%Use linear transformation: subtract minimum, and divide by range.
%Multiply by 255 for converting range to [0, 255].
J = ((I-0.1)/(0.7-0.1))*255;

%Reverse the brighness: 0.1(min elements) has brightest intensity (255) and the max element has 0 (0.7 in this case)
J = 255 - J;

%Round the result, and limit to range [0, 255].
J = max(min(round(J), 255), 0);

%Display result image.
imshow(uint8(J));

结果:
enter image description here