Total Pageviews

Translate

September 16, 2015

Image Processing - Get a start with MATLAB

by 4hathacker  |  in Image Processing at  6:28 AM

Image Processing - Let's begin...



We have seen a lot of images since childhood. But we know a very little about them. Images are nothing but a collection of pixels. Pixels are picture elements. The smallest addressible element that can be altered in an image.

Before going much deeper, lets get an initial start with image processing in MATLAB.
In MATLAB, there are some special toolboxes for image processing like image acquistion toolbox, image processing toolbox, computer vision system toolbox.

We are just learning about how to read, write and check the information about an image using MATLAB. Let us do it with an example program(Rather than just copying the program please try to understand the what the fuction is really doing):

function image_fundamentals_formats
    x = imread('peppers.png');            
    imfinfo('peppers.png')
    imwrite(x,'peppers.jpg','jpg');
    imfinfo('peppers.jpg')
    figure;
    subplot(211);imshow(x);
    subplot(212);imshow('peppers.jpg');

We have created a function 'image_fundamentals_formats' in which we are learning about how to read an image, how to write it and then noticing the size of two different formats of images.
Here 'x' is a varible which stores the image matrix returned by the function. This matrix can be seen in the command window of MATLAB if we omit the use of  semicolon after the function. Then 'imfinfo()' gives the information of the graphic file. 'imwrite' function is used to write the image in graphics file whose name is also passed in the function(here it is peppers.jpg) and the type is also given. 'figure' command is used to get the images shown in a figure window. 'subplot(211)' refers to the figure window with 2 rows, 1 column, and then its 1st part. 'imshow()' in which the variable 'x' is passed to get the image on screen inside the figure.

After running this function, you got some images on screen inside the figure window and some information about the images as,

>> image_fundamentals_formats

ans =

                  Filename: [1x51 char]
               FileModDate: '16-Dec-2002 06:10:58'
                  FileSize: 287677
                    Format: 'png'
             FormatVersion: []
                     Width: 512
                    Height: 384
                  BitDepth: 24
                 ColorType: 'truecolor'
           FormatSignature: [137 80 78 71 13 10 26 10]
                  Colormap: []
                 Histogram: []
             InterlaceType: 'none'
              Transparency: 'none'
    SimpleTransparencyData: []
           BackgroundColor: []
           RenderingIntent: []
            Chromaticities: []
                     Gamma: []
               XResolution: []
               YResolution: []
            ResolutionUnit: []
                   XOffset: []
                   YOffset: []
                OffsetUnit: []
           SignificantBits: []
              ImageModTime: '16 Jul 2002 16:46:41 +0000'
                     Title: []
                    Author: []
               Description: 'Zesty peppers'
                 Copyright: [1x29 char]
              CreationTime: []
                  Software: []
                Disclaimer: []
                   Warning: []
                    Source: []
                   Comment: []
                 OtherText: []


ans =

           Filename: 'C:\MATLAB\R2012b\bin\peppers.jpg'
        FileModDate: '15-Sep-2015 13:37:39'
           FileSize: 23509
             Format: 'jpg'
      FormatVersion: ''
              Width: 512
             Height: 384
           BitDepth: 24
          ColorType: 'truecolor'
    FormatSignature: ''
    NumberOfSamples: 3
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}


The information you will get is in 'ans' default variable of the MATLAB.



NOTE: The size of image you will observe is different for both the images which appears to be same in the figure window. Why is that so ???

It is so because we have taken a .png image file and when we are writing it we have taken it as .jpg file. These are file formats for images like as we have for text files e.g. .txt, .pdf, .xls, etc.

To learn more about images, please do let us know in the comments.

We will be continuing with the image processing in the next post. Till then discover more default images present in the MATLAB itself and find out what are their properties. Making it easier anyway, just get some fb images downloaded and get their information for further analysis.You can also get help from MATLAB Help.

0 comments:

Like Our Facebook Page

Nitin Sharma's DEV Profile
Proudly Designed by 4hathacker.