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)
Show older comments
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
0 Comments
Answers (1)
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.
2 Comments
Image Analyst
on 13 Mar 2014
Sorry - I forgot to delete them
a=img_in(:,:,1);
b=img_in(:,:,2);
c=img_in(:,:,3);
d=(a+b+c)/3;
img_out = uint8(d);
Use : (meaning "all") instead.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!