필터 지우기
필터 지우기

Can anyone please explain the working of this code ?

조회 수: 2 (최근 30일)
Sarmad Paracha
Sarmad Paracha 2019년 3월 1일
댓글: Mark Sherstan 2019년 3월 4일
Hello,
In this code a rule is being applied on the image to see if Ydash (luminance of the image) is greater then Cb(chrominance of blue component) but i am unable to understand the working of this code. rchannel, gchannel and bchannel are the R G B components of the image defined erlier in the code(not mentioned here) Can anyone please help me? Thanks
[R1r, R1c] = find(Ydash>Cb);
ruleIpixel=size(R1r);
Ir1= zeros(size(Im1),'uint8');
for i=1:ruleIpixel-1
Ir1(R1r(i),R1c(i),1) =rchannel(R1r(i),R1c(i));
Ir1(R1r(i),R1c(i),2) =gchannel(R1r(i),R1c(i));
Ir1(R1r(i),R1c(i),3) =bchannel(R1r(i),R1c(i));
i=i+1;
end

채택된 답변

Mark Sherstan
Mark Sherstan 2019년 3월 1일
Let us know if you need further clarification at any of the steps.
[R1r, R1c] = find(Ydash>Cb); % Find the indices where Ydash is greater than Cb
ruleIpixel=size(R1r); % Get the number of instances Ydash>Cb
Ir1= zeros(size(Im1),'uint8'); % Create a matrix nxn of type uint8 which is the size of some variable Im1
for i=1:ruleIpixel-1 % Create a loop incrementing by 1 for the number of instances (Ydash>Cb - 1). Note i should be replaced with ii as i is an imaginary number variable in MATLAB.
% In the zero matrix replace the zero with elements from each color channel based on the indices found on line 1 of code.
Ir1(R1r(i),R1c(i),1) =rchannel(R1r(i),R1c(i)); % For the red dimension (1)
Ir1(R1r(i),R1c(i),2) =gchannel(R1r(i),R1c(i)); % For the green dimension (2)
Ir1(R1r(i),R1c(i),3) =bchannel(R1r(i),R1c(i)); % For the blue dimension (3)
i=i+1; % Not required
end
  댓글 수: 3
Mark Sherstan
Mark Sherstan 2019년 3월 4일
Lets say that your [R1r, R1c] values are as such: (1,3) and (2,2) and (3,2) and that your zero matrix is as so:
0 0 0
0 0 0
0 0 0
We know that an RGB image can be simplified into the following:
Capture.PNG
So the loop would give a result as so:
Iteration 1:
0 0 121 0 0 153 0 0 49
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Iteration 2:
0 0 121 0 0 153 0 0 49
0 195 0 0 205 0 0 34 0
0 0 0 0 0 0 0 0 0
Iteration 3: Although there are 3 entries found using find the for statment considers n-1 of them so the last one is not conisdered.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by