image processing using matlab
TRANSCRIPT
Workshop on “Image processing using MATLAB”
Presented byAmarjeetsingh ThakurAsst. ProfessorDept. of Electronics & Communication
Engg. S.G.B.I.T. Belgaum
Outline What is MATLAB? Image Processing tool box Image formats How to read an image? Image conversion Arithmetic operations on images Conversion of an image into different formats Image rotation Image blurring and deblurring Fill in ROI in grayscale image References
What is MATLAB?• MATLAB = MATrix LABoratory
• “MATLAB is a high-level language and interactive environment that enables us to perform computationally intensive tasks faster than with traditional programming languages such as C, C++ and Fortran.”
• MATLAB is an interactive, interpreted language that is designed for fast numerical matrix calculations.
Key Industries
Aerospace and defense Automotive Biotech and pharmaceutical Communications Computers Education Electronics and semiconductors Energy production Industrial automation and machinery Medical devices
The MATLAB Environment MATLAB window
components:Workspace
> Displays all the defined variables
Command Window > To execute
commands in the MATLAB environment
Command History> Displays record of
the commands usedFile Editor Window
> Define functions
MATLAB Help• MATLAB Help is an
extremely powerful assistance to learning MATLAB
• Help not only contains the theoretical background, but also shows demos for implementation
• MATLAB Help can be opened by using the HELP pull-down menu
MATLAB Help (cont.)• Any command
description can be found by typing the command in the search field
• As shown above, the command to take square root (sqrt) is searched
• We can also utilize MATLAB Help from the command window as shown
What is the Image Processing Toolbox?
• The Image Processing Toolbox is a collection of functions that extend the capabilities of the MATLAB’s numeric computing environment. The toolbox supports a wide range of image processing operations, including:– Geometric operations– Linear filtering and filter design– Transforms– Image analysis and enhancement– Binary image operations– Region of interest operations
Images in MATLAB• MATLAB can
import/export several image formats:– BMP (Microsoft
Windows Bitmap)– GIF (Graphics
Interchange Files)– HDF (Hierarchical Data
Format)– JPEG (Joint
Photographic Experts Group)
– PCX (Paintbrush)– PNG (Portable Network
Graphics)– TIFF (Tagged Image
File Format)– XWD (X Window
Dump)– raw-data and other
types of image data
• Data types in MATLAB– Double (64-bit double-
precision floating point)
– Single (32-bit single-precision floating point)
– Int32 (32-bit signed integer)
– Int16 (16-bit signed integer)
– Int8 (8-bit signed integer)
– Uint32 (32-bit unsigned integer)
– Uint16 (16-bit unsigned integer)
– Uint8 (8-bit unsigned integer)
Images in MATLAB• Binary images : {0,1}• Intensity images : [0,1] or uint8, double etc. • RGB images : m × n × 3• Multidimensional images: m × n × p (p is the number of layers)
Binary ImagesThey are also called “ Black & White ”
images , containing ‘1’ for white and ‘0’(zero) for black
MATLAB code
Intensity ImagesThey are also called ‘ Gray Scale images ’ ,
containging numbers in the range of 0 to 255
Indexed ImagesThese are the color images and also
represented as ‘RGB image’. In RGB Images there exist three indexed
images.First image contains all the red portion of the
image, second green and third contains the blue portion.
Images and Matrices
Column 1 to 256
Row 1 to 256
o
[0, 0]
o
[256, 256]
How to build a matrix
(or image)?Intensity Image:
row = 256;col = 256;img = zeros(row, col);img(100:105, :) = 0.5;img(:, 100:105) = 1;figure;imshow(img);
Image Conversion• gray2ind - intensity image to index image• im2bw - image to binary• im2double - image to double precision• im2uint8 - image to 8-bit unsigned
integers• im2uint16 - image to 16-bit unsigned
integers• ind2gray - indexed image to intensity
image• mat2gray - matrix to intensity image• rgb2gray - RGB image to grayscale• rgb2ind - RGB image to indexed image
Arithmetic operations on images1. Imadd Syntax : Z = imadd(X,Y) Description: Z = imadd(X,Y) adds
each element in array X with the corresponding element in array Y and returns the sum in the corresponding element of the output array Z.
Contd..2. imsubtractSyntax : Z = imsubtract(X,Y)Description: Z = imsubtract(X,Y) subtracts
each element in array Y from the corresponding element in array X and returns the difference in the corresponding element of the output array Z
Contd..3. immultiplySyntax : Z = immultiply(X,Y)Description: Z = immultiply(X,Y)
multiplies each element in array X by the corresponding element in array Y and returns the product in the corresponding element of the output array Z.
Contd..4. imdivideSyntax : Z = immultiply(X,Y)Description: Z = imdivide(X,Y) divides
each element in the array X by the corresponding element in array Y and returns the result in the corresponding element of the output array Z.
Converting RGB image to gray formatI=imread(‘Sachin.jpg'); % Read
an imageI=rgb2gray(I); % RGB to gray
conversionfigure % Figure windowimshow(I) % Display figure
on figure window
Image rotation by some angleI=imread('steve.jpg');J=imrotate(I,45); % Rotate
image anticlockwise by an angle 45
K=imrotate(I,-45); % Rotate image clockwise by
an angle 45 imshow(J)Imshow(K)
Commands for blurring the imagePSF=fspecial('motion');Blurred=imfilter(I,PSF,'circula
r','conv');figure, imshow(Blurred)
Commands for deblurring the imagewnr1=deconvwnr(Blurred,PS
F); figure, imshow(wnr1);title('Restored image');
Fill in specified region of interest (ROI) polygon in grayscale image
I = imread('eight.tif');J = roifill(I);figure, imshow(J)
ROI fillI=imread('C:\Documents and
Settings\All Users.WINDOWS\Documents\My Pictures\Sample Pictures\avataar.jpg');
figureimshow(I)J=rgb2gray(I);figureimshow(J)
Applications of image processingBIOLOGICAL: automated systems for analysis of
samples.DEFENSE/INTELLIGENCE: enhancement and
interpretation of images to find and track targets.DOCUMENT PROCESSING: scanning, archiving,
transmission.FACTORY AUTOMATION: visual inspection of products.• MATERIALS TESTING: detection and quantification of
cracks, impurities, etc. MEDICAL: disease detection and monitoring,
therapy/surgery planning
Referenceswww.mathworks.com “Digital Image Processing using
MATLAB” by Rafael C. Gonzalez, Richard E. Woods, Steven L. Eddins.