Can anyone please explain the working of this code ?

2 次查看(过去 30 天)
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