A picture is worth a thousand words

picword.jpg

YES!! A Picture Contributes more information than a lot of words. Since we born we see the world with our eyes and learn to understand the meaning of all that we perceive. But how a computer see and understand ?

Let see a brief analogy between the A human and the computer.

img048

  1. Human has brain to process and a computer has Processor.
  2. Short term memory of human is same as Ram of a computer.
  3. Memory = Hard disk
  4. The main part of human sensory system is EYE. Then how can we provide eyes for computer ?

The answer is Camera.So a camera can see the world for a computer as human see through eyes.

How MATLAB helps you to access camera and acquire images and videos ?

To know the available cameras connected to your computer :

> camAvail = webcamlist

camAvail =

‘ASUS USB2.0 Webcam’

You can access the camera available by creating one camera object as follows :

> cam = webcam(1)

cam =

webcam with properties:

Name: ‘ASUS USB2.0 Webcam’
Resolution: ‘640×480’
AvailableResolutions: {1×6 cell}
WhiteBalance: 4600
Hue: 0
Exposure: -6
ExposureMode: ‘auto’
Gamma: 200
Sharpness: 2
Contrast: 16
BacklightCompensation: 1
WhiteBalanceMode: ‘auto’
Brightness: 0
Saturation: 64

Now see the live preview of camera

> preview(cam);

as it is preview it just shows you what it seeing, if you want to make it capture then :

> capture = snapshot(cam);

Observe your workspace a new variable is created , to check its properties :

> whos capture

Name                    Size              Bytes           Class         Attributes

capture         480x640x3         921600         uint8

The size will tells us it is a 3-Dimensional data. Go back and check the properties of webcam and look for Resolution. It is 640×480 so the Row and Column size of the data. The three dimensions will tell us that the data represents a color image consisting  of Red, Green, Blue (RGB) layers respectively.

Lets put the image data into a simple variable I (just for convenience)

> I = capture;

Alternative ways to read an image file into MATLAB is

>%  I = imread(‘filename.jpg’);         % syntax

> I = imread(‘lena_color_256.tif’);     % reading lena color image into variable I

In order to display image we have a lot of options available

imshow(I)

or

image(I)

or

imagesc(I)

we use the function imshow here,

> imshow(I)

lena_wp

Now we see how can we  get three individual layers of the above

R = I(:,:,1);

G = I(:,:,2);

B = I(:,:,3);

subplot(1,3,1)

imshow(R)

subplot(1,3,2)

imshow(G)

subplot(1,3,3)

imshow(B)

 

rgb_lena

Some of the Image Processing operations are specifically performed on 2-dimensional image rather than 3-D. we can do that by a single line of function i.e., rgb2gray(I)

Gray=0.299*R + 0.587*G + 0.114*B

Igray = rgb2gray(I)

imshow(Igray)

Igray

The pixel values of a gray image lies in the range of [0,255], Technically it is unsigned integer 8bit (uint8) data type so the range is [0 2^8 – 1] .

Lets get a logical or black & white image out of the above by using im2bw(I)

> im2bw(I,thresh)             % syntax

> th = graythresh(I)           % finding a threshold value

 

th =

0.5529

> Ibw = im2bw(I,th);
> imshow(Ibw)

Ibw

we can change the threshold value and observe different output, now the output Ibw consists the pixel values either o or 1, i.e., {0,1}.

%% Original Image

I = imread(‘lena_color_256.tif’);
imshow(I)

%% RGB layers
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
subplot(1,3,1)
imshow(R)
subplot(1,3,2)
imshow(G)
subplot(1,3,3)
imshow(B)

%% Gray Image
Igray = rgb2gray(I);
imshow(Igray)

%% Black and White
th = graythresh(I)
Ibw = im2bw(I,th);
imshow(Ibw)

Standard Image Dataset

Download the data-set images from above link.

References :

http://www.imageprocessingplace.com/root_files_V3/image_databases.htm

http://in.mathworks.com/products/image/?s_tid=srchtitle

 

 

 

Advertisements

3 thoughts on “Understanding Images through MATLAB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s