2. Specify the block size, such as 24*32 (divided into 20*20 blocks);
3. The block immediately takes n pixels, assuming that 20 pixels are taken at first, then the average G value of these 20 pixels is defined as G 1, and the average G value G0 of all pixels in the block is calculated;
4. Find the variance varG between G 1 and G0 and store it in the array for later use;
image = im read(' tupian . jpg ');
g 1 = 0; temp =[];
Because i= 1:24:480
For j= 1:32:640
area=image(i:i+23,j:j+3 1,:); % take out the area
For n= 1:20
x = round(rand()* 24);
y = round(rand()* 32); % and then generate the x and y coordinates of the point to be taken.
And x==0 | y==0
x = round(rand()* 24);
y = round(rand()* 32);
end
g 1 = g 1+double(area(x,y,2)); %G 1 Save the sum of g values of 20 points in this block.
end
g 1 = double(g 1)/20; %G 1 is the average value of g at 20 points.
G0=mean(mean(area(:,:,2)); %G0 saves the average value of the g value of this block.
G=[G 1,G0];
varG = var(G); % variance
temp =[temp; varG];
end
end
The above program can be run.