help need in matlab syntax

Discussion in 'Programmer's Corner' started by embedded29, May 9, 2017.

  1. embedded29

    Thread Starter Member

    Apr 8, 2017
    72
    0
    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;
     
  2. bertus

    Administrator

    Apr 5, 2008
    19,698
    4,060
    embedded29 likes this.
  3. MrChips

    Moderator

    Oct 2, 2009
    18,895
    6,052
    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.
     
    embedded29 likes this.
  4. bertus

    Administrator

    Apr 5, 2008
    19,698
    4,060
    JohnInTX and embedded29 like this.
  5. embedded29

    Thread Starter Member

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

    Code (Text):
    1. a=imread('C:\Users\user\Pictures\rg.jpg');
    2.  
    3. subplot('2,2,1');
    4. imshow(a);
    5. R=a;
    6. G=a;
    7. B=a;
    8. R(:,:,2:3)=0;
    9. subplot('2,2,2');
    10. imshow(R);
    11. G(:,:,1)=0;
    12. G(:,:,3)=0;
    13. subplot('2,2,3');
    14. imshow(G);
    15. B(:,:,2)=0;
    16. subplot(2,2,4);
    17. imshow(B);
    18.  
    ok, in rgb the 3 matrix are in which sequence first secound third..?
     
  6. bertus

    Administrator

    Apr 5, 2008
    19,698
    4,060
    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.
     
  7. embedded29

    Thread Starter Member

    Apr 8, 2017
    72
    0
    yes, sir i have run in Matlab interesting software....
     
  8. MrChips

    Moderator

    Oct 2, 2009
    18,895
    6,052
    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.
     
  9. embedded29

    Thread Starter Member

    Apr 8, 2017
    72
    0
    hello,
    this code make matrix color how to get black and white color display in first matrix?
     
  10. MrChips

    Moderator

    Oct 2, 2009
    18,895
    6,052
    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 (Text):
    1. a=imread('C:\Users\user\Pictures\rg.jpg');
    2.  
    3. subplot('2,2,1');
    4. imshow(a);
    5. R=a;
    6. G=a;
    7. B=a;
    8. R(:,:,2:3)=0;
    9. subplot('2,2,2');
    10. imshow(R);
    11. G(:,:,1)=0;
    12. G(:,:,3)=0;
    13. subplot('2,2,3');
    14. imshow(G);
    15. B(:,:,1:2)=0;
    16. subplot(2,2,4);
    17. imshow(B);
    18. R(:,:,2)= R(:,:,1);
    19. R(:,:,3)= R(:,:,1);
    20. subplot(2,2,2);
    21. imshow(R);
     
  11. embedded29

    Thread Starter Member

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

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

    Moderator

    Oct 2, 2009
    18,895
    6,052
    What is the error?
    Did you read the requirements of the edge( ) function?
    Convert the a matrix to a 2-dimensional matrix.
     
  13. embedded29

    Thread Starter Member

    Apr 8, 2017
    72
    0
    ok
     
Loading...