0% found this document useful (0 votes)
59 views

The Image Processing Toolbox at A Glance

Uploaded by

misbah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

The Image Processing Toolbox at A Glance

Uploaded by

misbah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

The Image Processing Toolbox at a

glance
What will we learn?
 How do I read an image from a file using MATLAB?
 What are the main data classes used for image
representation and how can I convert from one to
another?
 Why is it important to understand the data class
and range of pixel values of images stored in
memory?
 How do I display an image using MATLAB?
 How can I explore the pixel contents of an image?
 How do I save an image to a file using MATLAB?

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
The Image Processing Toolbox (IPT)
 IPT: A collection of functions (.m files most of the time inspectable )
that extend the basic capability of Matlab environment to
enable specialzed signal and image processing operations,
such as the following:
 Spatial Transformation
IPT Help:
 Image Analysis and Enhancement doc  IPT
 Neighborhood and Block Operations  Functions
 Linear Filtering and Filter Design  Examples

 Mathematical Transforms  Tutorial


For Example:
 Deblurring
doc  IPT  Examples 
 Morphological Operations Measuring Image Features 
Identifying Round Objects
 Color Image Processing
Run each section at a time
and focus on what each
section does, rather than
how it is done.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions & features
 The IPT includes functions used to perform the
following essential image processing operations:
 Displaying information about an image file
 Reading an image file
 Data classes and data conversions
 Displaying the contents of an image
 Exploring the contents of an image
 Writing the resulting image onto a file

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 imfinfo: Displays information about an image file
 Without opening
 Without storing its contents in workspace
 Try: imfinfo('pout.tif‘)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 imread: opens and reads the contents of an image file in most popular
formats (e.g., TIFF, JPEG, BMP, GIF, and PNG).
 Before an image can be processed, it must first be loaded into memory.
 Binary, intensity, and truecolor images can ALL be read with the imread( ).
 When reading in an indexed image, we must specify variables for both
the image and its color map.

 Examples: imread('pout.tif'); OR I = imread(‘coins.png’); OR


[X , map] = imread('trees.tif');

 IPT also contains some functions for reading specialized image format like:

 dicomread – to read “Digital Imaging and Communications in Medicine” image files

 nitfread – to read “National Imagery Transmission Format” image files

 hdrread – to read “High Dynamic Range” image files

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Data classes and data conversions
 It’s imperative to understand how image contents are stored
in memory
 Most common data classes for images:
 uint8 – 1 byte per pixel, in the [0 , 255] range
 double – 8 bytes per pixel, usually in the [0.0 , 1.0] range
 logical – 1 byte per pixel either true(1) or false (0)

 Once the contents of an image have been read and stored into
one or more variables, inspect the data class of these
variables and their range of values.
 MATLAB allows data class conversion (typecasting) but this
type of conversion does not handle the range problem and is
usually not what you want to do.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Data classes and data conversions
 IPT Functions to Perform Image Data Class Conversions

The input data class for these functions can be logical, uint8, uint16, int16, single, or double.
im2bw – data class conversion + global thresholding algo
im2frame – an image to movie frame conversion
frame2im – returns image data associated with image frame
movie – plays recorded movie frames
mat2gray – a matrix to gray-scale image
Example: imshow(mat2gray(rand(50,150)))
imshow(im2bw(mat2gray(rand(50,150))))
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Typecasting Examples

 IntArray = uint8(array)
conversion consisted of truncation (all
negative values became zero) & rounding
 off

It treated the original values as if they


were in the [0, 1] range for data class
 I2 = im2uint8(I1) double, and hence 0.5 became 128
(midrange point), anything less than or
 equal to 0 was truncated to 0, and
anything greater than or equal to 1 was
truncated to 255.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Typecasting Examples
There was no data class
convention (A already ‘double’)
 I = mat2gray(A) but simply a range
conversion – the smallest
 value (−8.0) became 0.0, the
largest value (4.0) became 1.0,
and all intermediate values were
scaled within the new range.

2/3 12 = 8 -8.0 0 4.0


2/3 1 = 0.6667
====================

17/2412= 8.5
17/241 = 0.7083
(2/3 + 1/24 = 17/24)
0.0 1.0
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Typecasting Examples
 bwI = im2bw(I, level) Any value greater than 0.4
becomes 1 (true), otherwise it
becomes 0 (false).

 Since im2bw expects a


threshold luminance
level=0.4
level as a nonnegative number
between 0 and 1, it
implicitly assumes that the
input variable is a
normalized grayscale image
of class double.

That is, if you try to use A as an


 input image where A=[-8 4; 0
0.5]
level=0.4
(E = im2bw(A, 0.4)), im2bw
will work without any error or
warning, but the result may not
make sense.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Data conversions
 IPT also includes functions to convert between RGB
(truecolor), indexed image, and grayscale image, which are
listed below .
 Some operations require data conversion e.g., performing image adjustments on
an indexed image may produce wrong results because the calculations are
performed on the index values (and not the representative RGB values.) To make
this an easier task, we can convert the indexed image to an RGB image using
ind2rgb.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Displaying the contents of an image

 image: displays an image using the current colormap.

 imagesc: scales image data to the full range of the current colormap
(cmap=colormap;) and displays the image.

 imshow: displays an image and contains a number of optimizations and


optional parameters for property settings associated with image
display.

 imtool: displays an image and contains a number of associated tools


that can be used to explore the image contents.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Displaying the contents of an image
 Examples:

 load mandrill;
image(X); colormap(map)
=======================================

 load clown ;
subplot(121); image(X); colormap(gray);
subplot(122); imagesc(X), colormap(gray)
======================================= For midrange expansion
 I = imread('pout.tif'); subplot(131); imshow(I); See: example_imagesc.m

subplot(132); imshow(I,[ ]);


subplot(133); imshow(I,[100 160]);
=======================================

 I = imread('pout.tif'); imtool(I);
OR I=imread('peppers.png'); imtool(I)
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Exploring the contents of an image
 Imtool

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Exploring the contents of an image
 Often need of inspecting the image contents more closely
 Usually done using imtool function
 imtool provides:
 Image display capabilities of imshow, e.g, I=imread('cameraman.tif');
imtool(I); figure; imtool(I,[0 80]);
 other tools like
 Pixel Region Tool
 Image Information Tool
 Adjust Contrast Tool
 These tools can also be directly accessed using their library functions
impixelinfo, imageinfo, and imcontrast, respectively.
Examples: imshow('hestain.png'); impixelinfo;
imshow('pout.tif'); imdistline;
I = imread('pout.tif'); P = impixel(I) [Mouse click(s) to select and then press Enter]
RGB = imread(’peppers.png’); [c,r,p] = impixel(RGB);
Obsolete: imshow('hestain.png'); pixval on;
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Exploring the contents of an image
More Examples:
 For indexed image: [X,map]=imread('trees.tif');
imshow(X,map),impixelinfo;

 RGB = imread(’peppers.png’); [c,r,p] = impixel(RGB); where ‘c’


and ‘r’ gives the pixel(s) coordinates and ‘p’ gives the RGB values of
that pixel.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Writing the Resulting Image onto a File
 imwrite function is used to write the contents of an image in
one of the most popular graphic file formats.
 If the output file format uses lossy compression (e.g., JPEG), imwrite allows
the specification of a quality parameter, used as a trade-off between the
resulting image’s subjective quality and the file size.

Example:
I = imread(’peppers.png’);
imwrite(I, ’pep75.jpg’); % Default 75.
imwrite(I, ’pep05.jpg’, ’quality’, 5); % Poor Quality, Small Size
imwrite(I, ’pep95.jpg’, ’quality’, 95); % Better Quality, Large Size

Open and Observe the written files!!!

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Intensity Values along a line (or multiline path)
 improfile function is used to compute and plot the inensity
values along a line or a multiline path in an image.

Example:
r1 = 17; c1 = 17; r2 = 201; c2 = 201;
I = imread('coins.png'); imshow(I);
line([c1, c2], [r1, r2], 'Color', 'g', 'LineWidth', 2);
figure(2);
improfile(I, [c1, c2], [r1, r2]); grid;
ylabel('Gray Level');

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Displaying Multiple Images Within One Figure Window
 subplot function is used to display multiple images within one
figure window.
 The Syntax is:
 subplot(m,n,p);
 One associated problem
is that images with different
colormaps cannot be properly
displayed.
 The Solution is subimage.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
IPT’s Essential functions and features
 Displaying Multiple Images Within One Figure Window
 Subimage function converts the image to an equivalent RGB
image and then displays that image.
 We can easily do this ourselves, but there is no direct conversion
 from intensity to RGB, so we must first convert from intensity to
indexed, and then from indexed to RGB (gray2ind  ind2rgb).

Using
subplot()

Using
subimage()

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

You might also like