close all;
filepath='D:\19_无人机照片\';
file =dir(strcat(filepath,'*.jpg'));
[k ~]=size(file);
for j=1:k
imgname=file(j).name;
RGB1 = imread(strcat(filepath,imgname));
R=RGB1(:,:,1);
G=RGB1(:,:,2);
B=RGB1(:,:,3);
maxR=im2double(max(max(R)));
maxG=im2double(max(max(G)));
maxB=im2double(max(max(B)));
k=(maxR+maxG+maxB)/3;
if k<0.9
RGB2 = imadjust(RGB1,[0 0 0; k k k],[0 0 0;1 1 1],0.7);
else
RGB2=RGB1;
end
% %全屏显示图像
% hfig1 = figure(1);
% hfig2 = figure(2);
% figure(1); imshow(RGB1);title('原图');
% set(hfig1, 'unit', 'normalized', 'position', [0,0,1,1]);
out_path1 = strcat('./result',num2str(0.7),'/');
if ~isdir(out_path1)
mkdir(out_path1);
end
imwrite(RGB2,strcat(out_path1,imgname));
end
beep;
主要涉及到imadjust函数,在此记录(参考博客):一般的语法调用格式为:f1=imadjust(f,[low_in high_in],[low_out high_out],gamma)
该函数的意义如图1所示,把图像f 灰度变换到新图像f1的过程中,f 中灰度值低于low_in的像素点在f1中灰度值被赋值为low_out,同理,f中灰度值高于high_in的像素点变换到f1时其灰度值也被赋值为high_out;而对于参数gamma,当gamma<1时,灰度图像靠近low_in的灰度值较低像素点灰度值变高,其灰度变化范围被拉伸,灰度值靠近high_in的一端灰度变化范围被压缩,图像整体变明亮。如图1(a)所示,同理,当gamma>1时,则灰度图像的靠近low_in的灰度值较低像素点灰度值变低,其灰度变化范围被压缩,灰度值靠近high_in的一端的灰度变化范围被拉伸,如图1(c)所示。
效果如下:分别为原图和效果图