使用imhist函数(要先用rgb2gray转化为灰度图像)
利用matlab计算图像直方图函数为imhist()
具体用法:
imhist( i );直接显示图像i的灰度直方图;
imhist(i,n)n为指定灰度级显示直方图;
[count, x] = imhist( i ) 获取直方图信息,count为每一级灰度像素个数,x为灰度级,x也可以在imhist(i,x)中指定,可以通过stem(x,count)画相应直方图;
imhist2.m文件:
I = imread('E:workKodakgirl.jpg'); I = rgb2gray(I); % imshow(i); % figure; imhist(I); % figure; % imhist(i,32); figure; [count,x] = imhist(I,150); stem(x,count);
imhist3.m文件:适当将其灰度增强,0.8亮,0.3暗
I = imread('E:workKodakgirl.jpg'); % imshow(I); % figure; [d1,d2,d3] = size(I); if(d3 > 1) I = rgb2gray(I);%如果是灰度图d3=1,就不用变换 end % [d1,d2,d3] = size(I); I = double(I) / 255; I1 = uint8(255 * I * 0.8 + 0.5); %0.8可变,uint8意思是转换成8bit无符号整型 imshow(I1);imwrite(I,'test.jpg')