直方图规定化(匹配)matlab实现(续)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/majinlei121/article/details/46575351

灰度图直方图匹配

%灰度图直方图匹配matlab
clear
I=imread('lena.bmp');%读取图像
Imatch=imread('face.bmp');%读取匹配图像
Jmatch=imhist(Imatch);%获取匹配图像直方图
Iout=histeq(I,Jmatch);%直方图匹配
figure;%显示原图像、匹配图像和匹配后的图像
subplot(1,3,1),imshow(I);title('原图像');
subplot(1,3,2),imshow(Imatch);title('匹配图像');
subplot(1,3,3),imshow(Iout);title('匹配之后图像');
figure;%显示原图像、匹配图像和匹配后图像的直方图
subplot(3,1,1),imhist(I,64);title('原图像直方图');
subplot(3,1,2),imhist(Imatch,64);title('匹配图像图像直方图');
subplot(3,1,3),imhist(Iout,64);title('匹配之后图像直方图');

彩色图像直方图匹配

%彩色图像直方图匹配matlab
clear
I=imread('57.jpeg');%读取图像
Imatch=imread('Model_train.png');%读取匹配图像
R=I(:,:,1);%获取原图像R通道
G=I(:,:,2);%获取原图像G通道
B=I(:,:,3);%获取原图像B通道
Rmatch=Imatch(:,:,1);%获取匹配图像R通道
Gmatch=Imatch(:,:,2);%获取匹配图像G通道
Bmatch=Imatch(:,:,3);%获取匹配图像B通道
Rmatch_hist=imhist(Rmatch);%获取匹配图像R通道直方图
Gmatch_hist=imhist(Gmatch);%获取匹配图像G通道直方图
Bmatch_hist=imhist(Bmatch);%获取匹配图像B通道直方图
Rout=histeq(R,Rmatch_hist);%R通道直方图匹配
Gout=histeq(G,Gmatch_hist);%G通道直方图匹配
Bout=histeq(B,Bmatch_hist);%B通道直方图匹配
J(:,:,1)=Rout;
J(:,:,2)=Gout;
J(:,:,3)=Bout;
figure;%显示原图像、匹配图像和匹配后的图像
subplot(1,3,1),imshow(I);title('原图像');
subplot(1,3,2),imshow(Imatch);title('匹配图像');
subplot(1,3,3),imshow(J);title('匹配之后图像');
figure;%显示原图像、匹配图像和匹配后图像的直方图
subplot(3,3,1),imhist(R,64);ylabel('原图像R通道直方图');
subplot(3,3,2),imhist(G,64);ylabel('原图像G通道直方图');
subplot(3,3,3),imhist(B,64);ylabel('原图像B通道直方图');

subplot(3,3,4),imhist(Rmatch,64);ylabel('匹配图像R通道直方图');
subplot(3,3,5),imhist(Gmatch,64);ylabel('匹配图像G通道直方图');
subplot(3,3,6),imhist(Bmatch,64);ylabel('匹配图像B通道直方图');

subplot(3,3,7),imhist(Rout,64);ylabel('匹配之后图像R通道直方图');
subplot(3,3,8),imhist(Gout,64);ylabel('匹配之后图像G通道直方图');
subplot(3,3,9),imhist(Bout,64);ylabel('匹配之后图像B通道直方图');


灰度图直方图匹配(不使用histeq)

%灰度图直方图匹配matlab(不使用histeq)
clear

im      = imread('lena.bmp');
imRef   = imread('face.bmp');
hist    = imhist(im);                % Compute histograms
histRef = imhist(imRef);
cdf     = cumsum(hist) / numel(im);  % Compute CDFs
cdfRef  = cumsum(histRef) / numel(imRef);
 
% Compute the mapping
M   = zeros(1,256);
for idx = 1 : 256
    [tmp,ind] = min(abs(cdf(idx) - cdfRef));
    M(idx)    = ind-1;
end
 
% Now apply the mapping to get first image to make
% the image look like the distribution of the second image
imMatch = M(double(im)+1);

figure;%显示原图像、匹配图像和匹配后的图像
subplot(1,3,1),imshow(im,[]);title('原图像');
subplot(1,3,2),imshow(imRef,[]);title('匹配图像');
subplot(1,3,3),imshow(imMatch,[]);title('匹配之后图像');
figure;%显示原图像、匹配图像和匹配后图像的直方图
subplot(3,1,1),imhist(im,64);title('原图像直方图');
subplot(3,1,2),imhist(imRef,64);title('匹配图像直方图');
subplot(3,1,3),imhist(uint8(imMatch),64);title('匹配之后图像直方图');

灰度图直方图匹配



扫描二维码关注公众号,回复: 3773732 查看本文章

彩色图像直方图匹配




灰度图直方图匹配(不使用histeq)



参考:http://blog.sina.com.cn/s/blog_65273bfa0102vf1u.html

猜你喜欢

转载自blog.csdn.net/majinlei121/article/details/46575351
今日推荐