我在matlab工作,我想对灰度图像和RGB图像应用对比度拉伸, 所以对于灰度我已经尝试了这个并且它有效
clear all;
clc;
itemp = imread('cameraman.tif'); %read the image
i = itemp(:,:,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
m = 255/(rmax - rmin); % 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
figure,imshow(i); % display original image
figure,imshow(i_new); % display transformed image
这适用于灰度图像,
问题是我不知道如何处理RGB图像 任何的想法?怎么实现呢? 谢谢你:))
答案 0 :(得分:0)
如果你写
rmin = min(i(:));
然后计算i
中所有值的最小值。这也适用于RGB图像,它只是3D矩阵,沿第3维有3个值。
其余代码也直接适用于此类图片。