Digital Image Processing LAB # 01 Introduction To Image Processing Using Matlab
Digital Image Processing LAB # 01 Introduction To Image Processing Using Matlab
LAB # 01
INTRODUCTION TO IMAGE PROCESSING USING MATLAB
Submitted To
Submitted By
Date of Submission
Objective:
The objective of todays lab is to practice the point processing techniques discussed as
followed:
1. Reading an image
2. Writing an image
3. Image Display
4. Perform image subtraction
5. Perform image addition
6. Reading an image and performing Image negative transform
7. Reading an image and performing Log transform
8. Reading an image and performing power law transform
1. Reading Image Data
To import an image from any supported graphics image file format, in any of the
supported bit depths, use the imread function.
Syntax
A = imread (filename,fmt)
Description
A = imread (filename,fmt) reads a greyscale or colour image from the file specified by the
string filename, where the string fmt specifies the format of the file. If the file is not in the
current directory or in a directory in the MATLAB path, specify the full pathname of the
location on your system.
2. Writing an Image
imwrite Write image to graphics file
Syntax
Imwrite (A,filename,fmt)
Example
a=imread ('pout.tif');
imwrite (a,gray(256),'b.bmp');
imshow ('b.bmp') % imshow is used to display image
How to get no. of rows and columns of image?
Function size gives the rows and columns dimension of image
[r,c]=size (a)
r =
291
c =
240
3. Image Display
imshow(f,g) % f is an image array & g is no of intensity levels used to
display it
imshow('pout.tif') % here by default intensity level is 256
pixval % displays the Euclidean distance between the initial and
current cursor conditions
imshow(f,[low high])
Displays as black all values less than or equal to low and as white all values greater than
or equal to high
Example::
imshow(a,[100 150])
4. Perform image subtraction
5. Perform image addition
6. Reading an image and performing Image negative transform
The negative of an image with grey levels in the range [0, L-1] is obtained by the negative
transformation shown in figure above, which is given by the expression,
s = L - 1 - r
This expression results in reversing of the grey level intensities of the image thereby
producing a negative like image. The output of this function can be directly mapped into the
grey scale lookup table consisting values from 0 to L-1.
7. Reading an image and performing Log transform
The log transformation curve shown in fig. A, is given by the expression,
s = c log(1 + r)
where c is a constant and it is assumed that r0. The shape of the log curve in fig. A tells that
this transformation maps a narrow range of low-level grey scale intensities into a wider range
of output values. And similarly maps the wide range of high-level grey scale intensities into a
narrow range of high level output values. The opposite of this applies for inverse-log
transform. This transform is used to expand values of dark pixels and compress values of
bright pixels.
8. Reading an image and performing power law transform
The nth power and nth root curves shown in fig. A can be given by the expression,
s = cr
This transformation function is also called as gamma correction. For various values of
different levels of enhancements can be obtained. This technique is quite commonly called as
Gamma Correction. If you notice, different display monitors display images at different
intensities and clarity. That means, every monitor has built-in gamma correction in it with
certain gamma ranges and so a good monitor automatically corrects all the images displayed
on it for the best contrast to give user the best experience.
The difference between the log-transformation function and the power-law functions is
that using the power-law function a family of possible transformation curves can be
obtained just by varying the .
These are the three basic image enhancement functions for grey scale images that can be
applied easily for any type of image for better contrast and highlighting. Using the image
negation formula given above, it is not necessary for the results to be mapped into the grey
scale range [0, L-1]. Output of L-1-r automatically falls in the range of [0, L-1]. But for the
Log and Power-Law transformations resulting values are often quite distinctive, depending
upon control parameters like and logarithmic scales. So the results of these values should be
mapped back to the grey scale range to get a meaningful output image. For example, Log
function s = c log(1 + r) results in 0 and 2.41 for r varying between 0 and 255, keeping c=1.
So, the range [0, 2.41] should be mapped to [0, L-1] for getting a meaningful image.