There are three ways to convert an image from a color graph to a grayscale map The weighted method of mean value method is the maximum value method, respectively!
The weighted method is Gray==0.3*r+0.59*g+0.11*b
The mean method is gray== (R+G+B)/3
Max value is max (R,G,B)
A=imread (' D:\lena. BMP '); R=double (A (:,:, 1)); G=double (A (:,:, 2)); B=double (A (:,:, 3)); [M,n]=size (R); Bw=zeros (M,n); Bw=0.3.*r+0.59.*g+0.11.*b; Subplot (2,2,1) Imshow (Mat2gray (BW)); Title (' Weighted method, in fact our rgb2gray is the default weighting method ') Bw1=zeros (M,n); Bw1= (R+G+B)./3; Subplot (2,2,2) Imshow (Mat2gray (BW1)); Title (' mean Value method ') Bw2=zeros (M,n); For i=1:m For J=1:n BW2 (i,j) =max (Max (R (I,j), G (I,j)), B (i,j)); End End Subplot (2,2,3) Imshow (Mat2gray (BW2)); Title (' Maximum Value method ') |
Converting color graphs into grayscale images