0
我有一個像[0.1,... 0.7..0.3](100 +元素包含最大值和最小值)的矩陣 如何將其轉換爲灰度圖像,使得0.1 (分鐘元件)具有亮強度(255)和最大元件具有0(在這種情況下0.7)使用逆映射顯示GreyScale圖像
我有一個像[0.1,... 0.7..0.3](100 +元素包含最大值和最小值)的矩陣 如何將其轉換爲灰度圖像,使得0.1 (分鐘元件)具有亮強度(255)和最大元件具有0(在這種情況下0.7)使用逆映射顯示GreyScale圖像
檢查下面的代碼示例:
%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));