Ordinary histograms count the number of grayscale occurrences of pixels in an image.
One of the dimensions of the two-dimensional histogram is an ordinary histogram, which counts the number of grayscale occurrences of pixels in the image.
Two-dimensional histogram, 1-dimensional is an ordinary histogram, 2-dimensional is a neighborhood mean histogram with a radius of 1:
clear all;
close all;
clc;
img=imread('lena.jpg');
[m n]=size(img);
r=1; %邻域半径
imgn=zeros(m+2*r+1,n+2*r+1);
imgn(r+1:m+r,r+1:n+r)=img;
imgn(1:r,r+1:n+r)=img(1:r,1:n); %扩展上边界
imgn(1:m+r,n+r+1:n+2*r+1)=imgn(1:m+r,n:n+r); %扩展右边界
imgn(m+r+1:m+2*r+1,r+1:n+2*r+1)=imgn(m:m+r,r+1:n+2*r+1); %扩展下边界
imgn(1:m+2*r+1,1:r)=imgn(1:m+2*r+1,r+1:2*r); %扩展左边界
Hist=zeros(256,256);
for i=1+r:r+m
for j=1+r:r+n
pix1=uint8(imgn(i,j));
pix2=uint8(mean2(imgn(i-r:i+r,j-r:j+r)));
Hist(pix1+1,pix2+1)=Hist(pix1+1,pix2+1)+1;
end
end
mesh(double(Hist))
operation result