我正在尝试对图像进行标准化,我应用了公式来执行此操作,但是这样做会遇到一个奇怪的算术运算问题。
这是我的代码:
IM3=imread('mdb022.pgm');
i = IM3(:,:,1);
rtemp = min(i); % find the min. value of pixels in all the columns (row vector)
rmin=min(rtemp) % find the min. value of pixel in the image
rtemp = max(i); % find the max. value of pixels in all the columns (row vector)
rmax=max(rtemp) % find the max. value of pixel in the image
a=255;
b=rmax-rmin
m=a/b % find the slope of line joining point (0,255) to (rmin,rmax)
c = 255 - m*rmax; % find the intercept of the straight line with the axis
i_new = m*i + c; % transform the image according to new slope
在命令窗口中:
>> contrast_stretching_1
rmin =
0
rmax =
221
b =
221
m =
1
对于步骤m = a / b,除法应为255除以221,等于1.1538 ......,但为什么matlab显示1?
有人可以告诉我并帮助我解决这个问题吗?
谢谢!
答案 0 :(得分:0)
将图像更改为双(或单个)
IM3 = imread('mdb022.pgm');
I = double(IM3(:,:,1));
rmin = min(I(:));
rmax = max(I(:));
m = 255.0 ./ (rmax - rmin);
I_new = m.*(I - rmax) + 255.0;
% I_new = uint8(I_new); if you want the image as uint8