clear;
clc;
rgb =imread('girl.jpg');
gray =rgb2gray(rgb);
new_gray = gray;figure(1);subplot(1,2,1);imshow(gray);title('原图');% 划分4*4的网格,分别计算cdf
[m, n]=size(gray);
cdf =zeros(16,256);for i=1:4for j=1:4cdf((i -1)*4+ j,:)=compute_cdf(gray((i -1)* m /4+1: i * m /4,(j -1)* n /4+1: j * n /4));
end
end
% 逐个像素点进行转换
for i=1:m
for j=1:n
% 处理四个角落
if((i <= m /8|| i >= m - m /8)&&(j <= n /8|| j >= n - n /8))
gray_scale_value =gray(i, j)+1;
which_block =(ceil(i / m