Using MATLAB, Extracting individual Red, Blue & Green (RGB) planes, From a RGB Image, With Code

Extraction of individual Red, Green & Blue from a RGB image is a simple task, just follow these steps if you are new to this process:

1. Suppose we are having an image known as 'xyz.jpg', which is a RGB image.

Now we are going to read that image in MATLAB, by using the command (if the image is in current working directory), imread('xyz.jpg'); or if the image is stored in other folder simply we have to provide the path of that image including the image.

Suppose the path of the image is 'E:\bunty\xyz.jpg' so we have to write like this imread('E:\bunty\xyz.jpg');.

Always prefer to create an exclusive variable for an image, for example here it will be x, x=imread('xyz.jpg');  The creation of a dedicated variable makes it easy to operate anything.
NOTE: Use ';' (Semicolon) to supress the output other wise you will see a large matrix of integers in front of you in the command window!
2. Now use the command imshow(x), in order to view the image just loaded as variable x.

3. Extraction of red (R) plane: We will be storing the red plane of the RGB image in the variable 'xR'. Therefore the command will be xR=x(:,:,1);, now you can use imshow(xR) in order to see the red plane of the RGB image.

4.  Extraction of green (G) plane: We will be storing the green plane of the RGB image in the variable 'xG'. Therefore the command will be xG=x(:,:,2);, now you can use imshow(xG) in order to see the green plane of the RGB image.

5.  Extraction of blue (B) plane: We will be storing the blue plane of the RGB image in the variable 'xB'. Therefore the command will be xB=x(:,:,3);, now you can use imshow(xB) in order to see the blue plane of the RGB image.

So the complete code will be like:
clc;
clear all;
close all;
x=imread('xyz.jpg');
figure, imshow(x);
title('Original RGB Image');
xR=x(:,:,1);
figure, imshow(xR);
title('Red Plane of RGB image');
xG=x(:,:,2);
figure, imshow(xG)
title('Green Plane of RGB image');
xB=x(:,:,3);
figure, imshow(xB)
title('Blue Plane of RGB image');



Snapshots:
Original RGB Image (Using MATLAB, Extracting individual Red, Blue & Green (RGB) planes, From a RGB Image)
Original RGB Image
Blue Plane OF RGB Image(Using MATLAB, Extracting individual Red, Blue & Green (RGB) planes, From a RGB Image)
Blue Plane OF RGB Image

Green Plane OF RGB Image(Using MATLAB, Extracting individual Red, Blue & Green (RGB) planes, From a RGB Image)
Green Plane OF RGB Image

Red Plane OF RGB Image(Using MATLAB, Extracting individual Red, Blue & Green (RGB) planes, From a RGB Image)
Red Plane OF RGB Image

3 comments:

  1. sir .I am final year engineering student working on academic project titled "automatic object sorting based on color by using image processing". I want matlab code for sorting , plz help me. you can contact me on 9923929653 and mailid: [email protected]

    ReplyDelete
    Replies
    1. So what is the sorting technique you wanted to apply? The title of your project covers vast varieties of techniques. Please be specific.
      Giving contact number & email id for talk initiation is absurd.

      Delete
  2. Hello sir, i am doing a project on matlab called "intelligent parking system" in which i have processed the image and getting the coordinates of the free parking slots as the output, so how can i use these coordinates to graphically guide the users about which parking slot is free.

    ReplyDelete