Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
669 B
4
Indexable
Never
%read an image in matrix I
I=imread("peppers.png");
%read an image in matrix m,n,c
[m,n,c]=size(I);
%creating zero matrix of size m x n
J=zeros(m , n );
J1=zeros(m , n );

%initalizing the values in the zero matrix J and J1
for i=1:m 
    for j=1:n 
        J(i,j)=(I(i,j,1)+I(i,j,2)+I(i,j,3))/3;
        J1(i,j)=(0.299*I(i,j,1)+0.587*I(i,j,2)+0.114*I(i,j,3))/3;
    end;
end;
K=rgbzgray(I);
%showing the images by using subplot
figure;
subplot(2,2,1);
imshow(I);
title("original");
subplot(2,2,2);
imshow(J,[]);
title("gray scale image using avrage method");
subplot(2,2,3);
imshow(J1,[]);
title("gray scale image using weighted method");

Leave a Comment