Color to Grayscale Conversion: MATLAB Image Processing Tutorial

Hi friends, this is my first tutorial on Matlab image processing.The purpose of this tutorial is to gain familiarity with MATLAB’s Image Processing Toolbox. Let us start the basic of the image processing with a very simple example i.e. converting a color image of any format (ex. jpeg, jpg, bmp, etc) into a grayscale image.

MATLAB Program for Color to Grayscale Conversion

Step 1:

Initially, you have to define a matrix A with a path of the image that you have to convert. For this purpose, if you can't copy a path of the image file, just install this small software ( after installing this software simply right click on the image you will see an option for copy long URL. OK after copying the image path.

Step 2:

Define matrix B with the image format. In this case jpg. You can change the format you have.

Step 3:

C=rgb2gray(B).   Here rgb stands for RedGreenBlue i.e. color image gray stands for converting it into grayscale.

%tutorial M-file
%created by:
%created on: 20 may 2013

% Load a color .jpg image and convert it into grayscale

A='H:New photoImagesPhoto1619.jpg'; %designate matrix A as the specified file
B=imread(A,'jpg')                            %matrix B loaded with jpg file specified by A
figure (1),imshow(B);                     %show image B in figure window 1
C=rgb2gray(B)                                 %convert color image to grayscale image
figure (2),imshow(C);                    %show image C in figure window 2

MATLAB Image Processing

MATLAB Image Processing

[caption id="" align="aligncenter" width="294"]MATLAB Image Processing MATLAB Image Processing[/caption]

[caption id="" align="aligncenter" width="294"]MATLAB Image Processing MATLAB Image Processing[/caption]

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!