% read a color picture showing RGB three channel pictures respectively
% change the mean variance entropy of image by changing color picture to gray image
Im= (Imread (' robot.jpg '));
Figure,imshow (IM);
% STEP1 display RGB three channel pictures respectively
Subplot (2,2, 1), imshow (IM); % Original color image
Subplot (2, 2, 2), Imshow (IM (:,:, 1)); %r Channel IM (:,:, 1) represents a three-dimensional image the first parameter means get all rows
Subplot (2, 2, 3), Imshow (IM (:,:, 2)); %G Channel The second parameter means get all columns
Subplot (2, 2, 4), Imshow (IM (:,:, 3)); %b Channel The second parameter means get the number of pages
% STEP2 convert color images to grayscale images
% STEP3 the mean variance entropy of the image
Im1=rgb2gray (IM);
Figure,imshow (IM1);
[Row,col]=size (IM1); % gets the number of rows and columns
Im1=double (IM1); % must first be converted to double otherwise the accumulation cannot be realized
sum=0; % of all elements of the Matrix and
For I=1:row
For J=1:col
SUM=SUM+IM1 (I,J);
End
End
% mean value
mid=sum/(Row*col);
% to calculate variance
s=0;
For X=1:row
For Y=1:col
s=s+ (im1 (x, y)-M) ^2; the sum of the squares of all pixels and mean values.
End
End
a2=s/(row*col);% Variance
% seeking Information entropy
a=im1;
[M,n]=size (A);
Temp=zeros (1,256);% set blank matrix for recording probabilities
For m=1:m;
For N=1:n;
if A (m,n) ==0;% if the value is 0
i=1;% sequence number is 1
Else
i=a (m,n);% otherwise the original serial number
End
Temp (i) =temp (i) +1;% counts the number of occurrences of each grayscale value
End
End
% seeking Information entropy
temp=temp/(m*n);% all values divided by the number of elements, indicating the probability that P (i) in the formula
result=0;
for I=1:length (temp)% returns the maximum value in the column of temp, which is
if temp (i) ==0;% if the probability is 0 does not accumulate 0 to be processed separately
% Result=result;
Else% otherwise the formula
result=result-temp (i) *log2 (temp (i));
End
End
DAY13 color images show RGB Three channels image mean variance entropy of image