MATLAB: How to write this equation in matlab?

digital image processingequationimage mathImage Processing ToolboxMATLABMATLAB and Simulink Student Suite

Hello everyone.In the below equation can anyone suggest me how to write this eqn in matlab..
L_in (x,y)=0.299.I_in^R (x,y)+0.587I_in^G (x,y)+0.114I_in^B (x,y).
where I_in is input image.
Many thanks in advance..

Best Answer

Images are not indexed (x,y), they (like all matrices) are indexed (y, x) which is (row, column).
So, L_in (x,y)=0.299.I_in^R (x,y)+0.587I_in^G (x,y)+0.114I_in^B (x,y) would be
L_in(y, x) = 0.299 * I_in(y, x) ^ R(y, x) + 0.587 * I_in(y, x) ^ G(y, x) + 0.114 * I_in(y, x) ^ B(y, x);
Looks like a very strange equation though. What are R, G, and B and why are you raising the gray level of the image to those powers? And is I_in a gray scale image (which I assumed above), or an RGB image. If it's an RGB image, you might possibly want (the still weird):
L_in(y, x) = 0.299 * I_in(y, x, 1) ^ R(y, x) + 0.587 * I_in(y, x, 2) ^ G(y, x) + 0.114 * I_in(y, x, 3) ^ B(y, x);
or maybe you want (if you're trying to convert an RGB image into a gray scale image one pixel at a time in a loop):
L_in(y, x) = 0.299 * I_in(y, x, 1) + 0.587 * I_in(y, x, 2) + 0.114 * I_in(y, x, 3);
or (NOT in a loop over x and y):
L_in = 0.299 * I_in(:, :, 1) + 0.587 * I_in(:, :, 2) + 0.114 * I_in(:, :, 3);
or even, more simply:
L_in = rgb2gray(I_in);