2016-08-24 105 views

回答

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