Monday, September 12, 2011

How To Generate Half Black and White image using matlab

Digital image and matrix both have the common structure. As digital image can be represented as a two dimensional matrix , we can also convert 2-dimensional matrix into a image using matlab,which use the matrix as its basic data structure.

In this tutorial we are going to make a image whose half portion will be black and half portion will be white. So let's start,(assume that the size of the image which we are going to generate is 256x256)

Step1:
          form a matrix equal to the size of 256x128 and initialize it  to 0.In matlab this work can be done in one step by using following code

            row_column1 = zeros(256,128); %zeros is the predefined function that form the %matrix of mxn size and initializes it to zero


            form another matrix 0f size 256x128 and initializes it to 1.In matlab we can do that by using following code

          row_column2 = ones(256,128); %ones is predefined function that form the matrix                                                           %of mxn      order

Step2:
                 Now combine row_column1 and row_column2 matrix for generating row_column matrix that will represent our matrix for image

         row_column = [row_column1 row_column2];

Step3: As our matrix is ready for representing our digital image now we need  FUNCTION that could convert our matrix into image. In matlab be have function mat2gray(matrix) which take matrix as input and return handle to a gray scale image related to matrix.As we have our row_column matrix ready we will convert it into grayscale image using following code.

      gray_image = mat2gray(row_column);

Step4:
              Our digital image corresponding to matrix row_column is ready and we have to save that on  disk.Matlab have have function imwrite(image,'image_name.extension') ,imwrite have many variants but we are using simplest one. image in imwrite function is the handle to the image ,e.g. gray_image in our case, image_name is name which we want to give the image on the disk and extension is a three char word that specify the type of image,eg jpg,png,tif etc any format which is supported by the matlab.We are saving our image by name Black_White.tif, this can be done by using following CODE

 imwrite(gray_image,'Black_White.tif');

Step5:
             We saved our image we haven't know how our image look like.Show for seeing a image matlab uses a function named imshow(image),it has variants but we are using simplest one, wherw image is handle to the image.

                imshow(gray_image)

Now we have generated our first gray scale image using matlab.

Full Coding:
row_column1 = zeros(256,128);
row_column2 = ones(256,128);
row_column   = [row_column1 rowcolumn2];
gray_image   = mat2gray(row_column);
imwrite(gray_image,'Black_White.tif');
imshow(gray_image)



Friday, September 9, 2011

Welcome to the World of Image Processing and Computer Vision

Good morning friends, today in the morning I was feeling not well because I want to do  something new but didn't know what to do. I have a deep interest in Image Processing and Computer Vision so I decided to start blogging about it.
This is my blog related to Image Processing and Computer Vision, I will try to share my understandings related to Image Processing and Computer Vision. May be I will be wrong at many places but that doesn't matter as you are here to correct me. We will try to share our knowledge here.Please comment on my posts, if you think it is not just a waste of time for you.
So friends let's start blogging by saying hello world!



""
"HELLO WORLD"

Now from next post we will start Image Processing concept using Matlab.