How to write this equation in matlab??

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..

 Accepted 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);

3 Comments

In the above equation,I'm separating only luminance part from rgb.I'm not using (rgb2gray)..instead ycbcr is used.
rgb2gray() gets the luminance part of a color image. It's basically the same as if
  1. you used rgb2hsv() and took the V component, or
  2. rgb2ycbcr() and took the Y component, or
  3. rgb2lab() and took the L component.
They're all basically the monochrome brightness or intensity of the image.
Actually they're not, UNLESS you do a color calibration, which most people (NOT including me) do. But that's a whole other story. Just be aware that if you look at any of those components with a genuine spectrophotometer (the gold standard instrument for measuring color), your digital values will not match the actual real-world colors measured with that instrument. It's a complicated topic and may not be needed for some situations. See attached tutorial.
Whoever did that crazy equation you had in your original post didn't know what they were doing.
Thank you for your guidance..I will go through the link..

Sign in to comment.

More Answers (1)

If I is X-Y-3 matrix, then:
L=0.299*I(:,:,1)+0.587*I(:,:,2)+0.114*I(:,:,3);
You should look at:
L = rgb2gray(I);%converts with built in matlab function

1 Comment

Thank you for your response..but I need to use ycbcr instead of gray..I need to know how to use x,y part(L_in(x,y))

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Asked:

on 12 Apr 2020

Commented:

on 12 Apr 2020

Community Treasure Hunt

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

Start Hunting!