资源简介
提高图像对比度和亮度,改进图像质量,适用于偏暗、低对比度的图像
代码片段和文件信息
%直方图均衡化
clear all
close all
clc
DIR=‘D:\直方图均衡\data\Imgs_MSRA\‘;
str=dirr(DIR);
for k=1:length(str)
close all
I_in = imread(strcat(DIRstr(k).name));
I_in = imresize(I_in[300400]);
%%%%%%%%%%%%%%%%计算标准差%%%%%%%%%%%%%%%%%%%%%%%%%
% std_m=std_function(I_in);
%%%%%%%%%%%%%%%%%%end%%%%%%%%%%%%%%%%%%%%%%%
% if std_m<0.0249
I=rgb2gray(I_in);
I_gray = I;
%for cn=1:size(I_in3)
I_matlab=histeq(I);
I_o=I;
[heightwidth] = size(I);
S_I_gray = 0;
S_I_e = 0;
%进行像素灰度统计;
NumPixel = zeros(1256);%统计各灰度数目,共256个灰度级
for i = 1:height
for j = 1: width
NumPixel(I(ij) + 1) = NumPixel(I(ij) + 1) + 1;%对应灰度值像素点数量增加一
end
end
%计算灰度分布密度
for i = 1:256
ProbPixel(i) = NumPixel(i) / (height * width * 0.8);
end
%计算累计直方图分布
CumuPixel = zeros(1256);
for i = 1:256
if i == 1
CumuPixel(i) = ProbPixel(i);
else
% j=(sum(ProbPixel(1:i)))/(height * width * 1.0-(sum(ProbPixel(1:i))));
j=(sum(ProbPixel(1:i)))/(1+sum(ProbPixel(1:i)));
% j=(sum(ProbPixel(1:i-1)))*(1-ProbPixel(i)+0.5);
CumuPixel(i)=j;
end
end
CumuPixel=CumuPixel/(max(CumuPixel)-min(CumuPixel));
%累计分布取整
CumuPixel = uint8(255 .* CumuPixel + 0.8);
%对灰度值进行映射(均衡化)
I2=im2double(I);
Im=filter2(fspecial(‘average‘5)I)/255;
for i = 1:height
for j = 1: width
if I(ij)==0
I(ij)=1;
end
I_e(ij) = CumuPixel(I(ij))+(I2(ij)-Im(ij))*255;
% I_e(ij) = CumuPixel(I(ij));
%方案一
% if I_e(ij)>=230
%
- 上一篇:均值滤波Matlab程序
- 下一篇:四阶带通巴特沃斯滤波器Multisim设计文件
评论
共有 条评论