计算直方图算法
histogram.m
function bars=histogram(I)
%用==提取某个灰度的像素
%并用sum计算个数
tic
bars=zeros(1,256);
for value 0:255
bars(value+1)=sum(value==I(:))
end
bars=bars./numel(I)
toc
brightness.m
close all;
clear all;
clc;
I=imread('图片地址');
%I=rgb2gray(I);彩色图片需要转为灰度图片
bars=histogram(I);
set(0,'defaultFigurePosition',[100 100 1000 500]);
set(0,'defaultFigureCOlor',[1 1 1]);
figure;
subplot(121),imshow('I');
subplot(122),bar(0:255,bars);