histeq():
如果图像的对比度太差,常用的方法就是灰度直方图均衡化。
在matlab中,能达到这个目的的函数就是histeq. ​

imhist():
imhist是MATLAB图像处理模块中的一个函数,用以提取图像中的直方图信息。
图片要求为灰度图或者二值图。imhist这个函数好像只能针对1通道的处理灰度图,如果是彩色图片,可以通过rgb2gray(i)变成1通道的。 ​

最后结果:

1,

MATLAB_no.1:入门作业_histeq():_imhist()_(男孩的三个图,以及文字描述)_直方图

2,

MATLAB_no.1:入门作业_histeq():_imhist()_(男孩的三个图,以及文字描述)_直方图_02

1,

代码:

clear,clc,close all;
f=imread('boy.jpg');
g=rgb2gray(f);
g1=imadjust(g);
g2=histeq(g);
subplot(3,2,1)
imshow(g),title('灰度图');
subplot(3,2,2)
imhist(g),title('灰度图的直方图');
subplot(3,2,3)
imshow(g1),title('对比度默认拉伸图');
subplot(3,2,4)
imhist(g1),title('对比度默认拉伸图的直方图');
subplot(3,2,5)
imshow(g2),title('直方图均衡后图');
subplot(3,2,6)
imhist(g2),title('直方图均衡后图的直方图');

2,

f=imread('boy.png');
g=rgb2gray(f);
b=im2bw(g);
figure;
subplot(131);
imshow(f);
title('RGB图片');
subplot(132);
imshow(g);
title('灰度图');
subplot(133);
imshow(b);
title('二值图')