Tuesday, 13 March 2012

Lab 2 - Image Acquisition and Basic Operation

,
Objective: To learn the basic operations related to image acquisition

Question 1:

a) Copy image, 'Porsche.tiff' into any directory. Example; C:\Users\abc\Desktop. Also can use another pictures. Read the file. How large is the image (rows, columns)?

Porsche.tiff

Answer:

- Use command imread to read the file. Refer to Lab 1 in previous entry (click here).
- Before that, make sure your current directory in Matlab is the same as the location of the image ('Porsche.tiff') that have been saved. Example; C:\Users\abc\Desktop


  >> I=imread('Porsche.tiff')

To check how large is the image (rows and columns), go to Matlab workspace.


Value = <342x546 uint8>
Rows = 342
Columns = 546

Or, double click (open I) I in workspace.


Variable editor of I will be displayed.


You can scroll the scroll bar to check the rows and columns.

b) Answer the following questions about the image:

How big is the file (bytes)?
- Use whos command

  >> whos


Answer: 186732 Bytes

- How large is the image (rows, columns)?

Answer: Rows = 342, Columns = 546

- What are the minimum and maximum grey values?

Check at workspace.

Answer: Min = 0, Max = 240


Question 2

Part I: Image Acquisition
- Use your own picture.

baby.jpg

Part II: Read the image into Matlab
- Use imread command to read the image you have acquired in Part I.

  >> I=imread('baby.jpg')

- Display the information of matrix I.

  >> whos


The class should be "uint8" and the third dimension of I should be 3, which denotes it is a color image (the three components correspond to R,G,B channels respectively - e.g; blue channel is given by I(:,:,3).

- Display image to see the original colour.

  >>imshow(I)


- Convert the image into grayscale.

  >> I2 = I(:,:,3);

Then, display the new I2 to see how the image converted into grayscale mode.

  >> imshow(I2)


- Display the green channel of the image.

   Use grayscale image (I2).

  >> figure, imshow(I2),colormap([zeros(256,1),[0:1/255:1]',zeros(256,1)]),colorbar




*Additional task - convert into red channel.

  >> figure, imshow(I2),colormap([[0:1/255:1]', zeros(256,1),zeros(256,1)]),colorbar




Part III: Basic Image Operations

-Transport the image and display it.


  >> I3=ctranspose(I2);
  >> imshow(I3)


- Crop the top-left quarter of the image and display it.


  >> I4 = imcrop(I,[60 40 80 90]);
  >> imshow(I4)



- Flip the image left to right and display it.


  >> I5 = fliplr(I2);
  >> imshow(I5)



Lab 1 - Image Processing Toolbox Tutorial

,
This tutorial consists of:
  • Read and display an image
  • Check how the image appears in workspace
  • Perform histogram equalization on the image
  • Write the image to a disk file
  • Get information about a graphics file
1. Read and display an image

First, clear the Matlab of any variables and close open figure windows

  >> clear, close all

To read an image, use imread command. Let's read in a TIFF image name pout.tif (which is one of the sample images that is supplied with the Image Processing Toolbox, and stored it in array named.

  >> I=imread('pout.tif');

* If you do not put the semicolon (;) after the command, the command window will display like in image below:


Next, to display the image, use imshow command.

  >> imshow(I) 

*(I) = I value in the bracket is depend on variable name that you have declared in the above command.

An image will be displayed;


2. Check the image in memory

Enter the whos command to see how I is stored in memory.

  >> whos

Matlab responds with


pout.tif stored is stored as a 291-by-240 array. Since pout.tif was an 8-bit image, it gets stored in memory as an uint8 array. Matlab can store images in memory as uint8, uint16 or double arrays.

3. Perform Histogram Equalization

pout.tif is in low contrast image. To see the distribution of intensities in pout.tif in its current state, we can create histogram by using the imhist function. And use figure command to see the distribution in figure window. Precede imhist function with figure.

  >> figure, imhist(I) %Display a histogram of I in a new figure


From the above figure, the intensity is narrow and does not cover the potential range [0,255], and is missing the high and low values that would result in good contrast.

So, call histeq to spread the intensity values over the full range, thereby improve the contrast of I. Return the modified image in the variable I2.

  >> I2=histeq(I); %Equalize I and output in new array I2.

Display the I2 image to see the difference of contrastness.


Call imhist again for I2 to see the difference of distribution.


We can see how the intensity and pixel expanded accross the full range of possible values.

* The storage class of uint8, the full range is: 
    
The storage class of uint16, the full range is:  
The storage class of double, the full range is:  
    

4. Write the image

Write the newly adjusted image I2 back to disk. And specify a filename that includes the extension, example as .png, .jpeg and so on.

  >> imwrite (I2, 'pout2.png');

The Matlab will write the image into disk. It wrote as 8-bit image because it was stored as uint8 intensity image in memory.

If image is in RGB and class uint8, it will be written as 24-bit image.

If we want to set the bit depth of the output image, use BitDepth parameter with imwrite.

  >> imwrite (I2, 'pout2.png', 'BitDepth', 4);

Example above writes a 4-bit PNG file.


5. Check the contents of the newly written file

Type the command below
  
  >> imfinfo ('pout2.png')

Matlab responds with;

ans = 

                  Filename: 'pout2.png'
               FileModDate: '16-Mar-2012 19:08:41'
                  FileSize: 20325
                    Format: 'png'
             FormatVersion: []
                     Width: 240
                    Height: 291
                  BitDepth: 4
                 ColorType: 'grayscale'

                  ..............

 

FairuZatul Copyright © 2011 -- Template created by O Pregador -- Powered by Blogger Templates