clc;
clear all;
img=im2double(imread('D:\Gray Files\3-27.tif'));
BlockSize=3;
%求原始图像的均值和标准差
img_mean=mean2(img);
img_std=std2(img);
g=img;
%扩展区域的行列数
len=floor(BlockSize/2);
%对原始图像进行扩展,此处采用了镜像扩展,目的是解决边缘计算的问题
img_pad=padarray(img,[len,len],'symmetric');
[m,n]=size(img_pad);
%k_0是一个小于1.0正常数,k_1<k_2
k_0=0;
k_1=0.4;
k_2=0;
k_3=0.3;
E=4.0;
for i=1+len:m-2*len
for j=1+len:n-2*len
%从扩展图像中,取出局部图像
Block=img_pad(i-len:i+len,j-len:j+len);
%计算局部图像的均值和标准差
Block_mean=mean2(Block);
Block_std=std2(Block);
%测试局部图像的均值和标准差是否满足要求
if Block_mean<=k_1*img_mean && Block_mean>=k_0*img_mean
if Block_std>=k_2*img_std && Block_std<=k_3*img_std
g(i,j)=E*img(i,j);
end
end
end
end
imshow(g);
title('直方图统计增强');