图像处理篇-利用matlab绘制灰度直方图

平台:windows7

软件:matlab 2014b

利用matlab绘制灰度直方图

figure;
I=imread('G:\matlab\img\1.jpg');
subplot(1,2,1);imshow(I);
title('原始图像');

imwrite(I,'test.png');

subplot(1,2,2);
imhist(y);
title('灰度图像直方图');

在利用imhist绘制直方图的时候,报错,如图

灰度直方图的绘制需要imhist函数,若直接imhist,由于图像是RGB格式,是3维的,是不能绘制的.

使用rgb2gray将图像转化为灰度图

figure;
I=imread('G:\matlab\img\1.jpg');
subplot(1,3,1);imshow(I);
title('原始图像');

imwrite(I,'test.png');

subplot(1,3,2);
y=rgb2gray(I);
imshow(y);
title('灰度图');

subplot(1,3,3);
imhist(y);
title('灰度图像直方图');

猜你喜欢

转载自blog.csdn.net/rong11417/article/details/89434378