Filter löschen
Filter löschen

Can anyone please explain the working of this code ?

2 Ansichten (letzte 30 Tage)
Sarmad Paracha
Sarmad Paracha am 1 Mär. 2019
Kommentiert: Mark Sherstan am 4 Mär. 2019
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

Akzeptierte Antwort

Mark Sherstan
Mark Sherstan am 1 Mär. 2019
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 Kommentare
Mark Sherstan
Mark Sherstan am 4 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by