RGB to Gray function with Matlab code

1 Ansicht (letzte 30 Tage)
jenny mat
jenny mat am 1 Nov. 2011
hi all , we all know the Matlab belt in rgb2gray ,
i am tring to do it myself ,, here's my function
function out=gray(x)
[p,q,n]=size(x);
%out=uint8(ones(m,n,p));
R=x(:,:,1);
G=x(:,:,2);
B=x(:,:,3);
out=((R+G+B)/3);
and i have this error whn calling gray()
??? Subscript indices must either be real positive integers or logicals.
i don't know what's wrong , if any one know the solution .. Thanx in advance ..

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 1 Nov. 2011
gray() is a MATLAB function too. Do the following to see if there are conflicts.
which gray -all
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 1 Nov. 2011
You mean you change the name of your own gray() function? Why did the error message still say "Error in ==> gray at 6, G=x(:,:,2);"?
jenny mat
jenny mat am 1 Nov. 2011
yes ,, i deleted the old one and it worked very well ..
thanx very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 1 Nov. 2011
Chances are you are trying to call gray() from within a routine in which you have a variable named "gray".

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by