注:FEIP即Feature Extraction and Image Processing,特征提取与图像处理
最近发现基础很不扎实,每次学习的东西马上就忘了,要用的时候细节死活想不起来。决定以后多做笔记,发到博客里。以前觉得很简单的东西没必要发到这里,但其实往往就是这些简单的东西影响了自己的进展,所以以后要多写一些,权当记录在这里。
直方图是用来描述图像的亮度变化,即灰度值变化,表示每个亮度级在图像中的占有率,而图像的对比度就是通过亮度级范围度量(不是很懂)。
自己写的脚本
% plot gray histogram
I=imread('eye_orig.jpg');
[row, col]=size(I);
H = zeros(256, 1);
for x=1:col
for y=1:row
level = I(y, x); %column first, row second
H(level) = H(level)+1;
end
end
% plot
ymax=max(H);
plot(H);
axis([0,255,0,ymax]);
效果
书中作者的代码
function hist = histogram(image)
%Form an image histogram
%
% Usage: [new histogram] = histogram(image)
%
% Parameters: image - array of integers
%
% Author: Mark S. Nixon
%get dimensions
[rows,cols]=size(image);
%initialise histogram
for i = 1:256
hist(i)=0;
end
for x = 1:cols %address all columns
for y = 1:rows %address all rows
level=image(y,x);
hist(level+1)=hist(level+1)+1;
end
end