Info

This question is closed. Reopen it to edit or answer.

I'm trying to transform a colored imaged to gray scale without using the function rgb2gray?

3 views (last 30 days)
I am having difficulties with N and M because when it runs through the loop, it cannot read since the index is out of bounds. What does N and M represent instead? Thanks in advance!
function [img_out] = myGreyScale(img_in)
img=double(imread(img_in))/255;
N= 1:255;
M=1:255;
for i = 1:N
for j= 1:M
a=img_in(i,j,1);
b=img_in(i,j,2);
c=img_in(i,j,3);
d=(a+b+c)/3;
img_out(i,j,1)=d;
img_out(i,j,2)=d;
img_out(i,j,3)=d;
end
end
end

Answers (1)

Image Analyst
Image Analyst on 13 Mar 2014
Change the lines to
a=img_in(i,j,1);
b=img_in(i,j,2);
c=img_in(i,j,3);
d=(a+b+c)/3;
img_out = uint8(d);
No loops needed.

This question is closed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!