help need in matlab syntax

Thread Starter

embedded29

Joined Apr 8, 2017
72
Hello,
i copy code for RGB image from jpg
i dont not understand this in bold what is the use of this?

a=imread('C:\Users\user\Pictures\rg.jpg');

subplot('2,2,1');
imshow(a);
R=a;
G=a;
B=a;
R( : ,:,2:3)=0;
 

MrChips

Joined Oct 2, 2009
20,862
R, G, and B are simply three matricies that are created and assigned the same values as the matrix a.

Usually, in the context of colour graphics application, the letters R, G, and B would be used to represent the three colours red, green, and blue.

Assuming that each of the variables are 3-dimensional matricies containing the same image using jpg format, the last statement is setting all pixels in the green and blue layers to 0. Hence the R matrix will display the image in red colour only.
 

Thread Starter

embedded29

Joined Apr 8, 2017
72
here is total code...

Code:
a=imread('C:\Users\user\Pictures\rg.jpg');

subplot('2,2,1');
imshow(a);
R=a;
G=a;
B=a;
R(:,:,2:3)=0;
subplot('2,2,2');
imshow(R);
G(:,:,1)=0;
G(:,:,3)=0;
subplot('2,2,3');
imshow(G);
B(:,:,2)=0;
subplot(2,2,4);
imshow(B);
the last statement is setting all pixels in the green and blue layers to 0. Hence the R matrix will display the image in red colour only.
ok, in rgb the 3 matrix are in which sequence first secound third..?
 

bertus

Joined Apr 5, 2008
20,447
Hello,

I do not know matlab, but as I see the code it looks like that it shows 4 images.
1) the complete image
2) the red extracted image
3) the green extracted image
4) the blue extracted image.

Bertus

PS others, please correct me if I am wrong.
 

MrChips

Joined Oct 2, 2009
20,862
here is total code...

Code:
a=imread('C:\Users\user\Pictures\rg.jpg');

subplot('2,2,1');
imshow(a);
R=a;
G=a;
B=a;
R(:,:,2:3)=0;
subplot('2,2,2');
imshow(R);
G(:,:,1)=0;
G(:,:,3)=0;
subplot('2,2,3');
imshow(G);
B(:,:,2)=0;
subplot(2,2,4);
imshow(B);


ok, in rgb the 3 matrix are in which sequence first secound third..?
The original file is an image in jpg format. This is three layers of x,y pixels.
The first layer is red. The second layer is green. The third layer is blue.
The R, G, and B matrices have specific layers reset to zero so that the R matrix is red, G matrix is green, and B matrix is blue.
 

MrChips

Joined Oct 2, 2009
20,862
For gray scale, set the R,G,B layers to the same values.
btw, there is an error in line 15, shown corrected in the code below:
Code:
a=imread('C:\Users\user\Pictures\rg.jpg');

subplot('2,2,1');
imshow(a);
R=a;
G=a;
B=a;
R(:,:,2:3)=0;
subplot('2,2,2');
imshow(R);
G(:,:,1)=0;
G(:,:,3)=0;
subplot('2,2,3');
imshow(G);
B(:,:,1:2)=0;
subplot(2,2,4);
imshow(B);
R(:,:,2)= R(:,:,1);
R(:,:,3)= R(:,:,1);
subplot(2,2,2);
imshow(R);
 

Thread Starter

embedded29

Joined Apr 8, 2017
72
what is wrong in this code?
cant display canny edge detection

Code:
a=imread('C:\Users\user\Pictures\gray.png');
subplot(2,2,1);
imshow(a);
bb=edge(a, 'canny');   % here showing error 
subplot(2,2,2);
imshow(bb);
 

MrChips

Joined Oct 2, 2009
20,862
What is the error?
Did you read the requirements of the edge( ) function?
Convert the a matrix to a 2-dimensional matrix.
 
Top