How to write this equation in matlab??

조회 수: 15 (최근 30일)
Rocky
Rocky 2020년 4월 12일
댓글: Rocky 2020년 4월 12일
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..

채택된 답변

Image Analyst
Image Analyst 2020년 4월 12일
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
Image Analyst
Image Analyst 2020년 4월 12일
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.
Rocky
Rocky 2020년 4월 12일
Thank you for your guidance..I will go through the link..

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Hill
David Hill 2020년 4월 12일
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
Rocky
Rocky 2020년 4월 12일
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by