SlideShare a Scribd company logo
G.KARTHIGAM.SC INFO TECH
DEPARTMENT OF CS &IT
NADAR SARASWATHI COLLEGE OF
ARTS AND SCIENCE,THENI
 Matlab is optimised for operating on
matrices
 Images are matrices!
 Many useful built-in functions in the
Matlab Image Processing Toolbox
 Very easy to write your own image
processing functions
Image Processing using Matlab
Sumitha Balasuriya 2
>> I=imread('mandrill.bmp','bmp'); % load image
>> image(I) % display image
>> whos I
Name Size Bytes Class
I 512x512x3 786432 uint8 array
Grand total is 786432 elements using 786432 bytes
Image Processing using Matlab
Sumitha Balasuriya 3
image filename
as a string
image format
as a stringMatrix with
image data
Dimensions of I (red, green
and blue intensity information)
Matlab can only perform
arithmetic operations on
data with class double!
Display the left
half of the
mandrill image
 Images are just an array of numbers
>> I % ctrl+c to halt output!
 Intensity of each pixel is represented by the pixel
element’s value in the red, green and blue matrices
>> I(1,1,:) % RGB values of element (1,1)
ans(:,:,1) =
135
ans(:,:,2) =
97
ans(:,:,3) =
33
Image Processing using Matlab
Sumitha Balasuriya 4
Images where the pixel value in the image
represents the intensity of the pixel are called
intensity images.
Red
Green
Blue
 An indexed image is where the pixel values are indices to elements in a
colour map or colour lookup table.
 The colour map will contain entries corresponding to red, green and
blue intensities for each index in the image.
>> jet(20) % Generate a jet colourmap for 20 indices
ans =
0 0 0.6000
0 0 0.8000
0 0 1.0000
0 0.2000 1.0000
0 0.4000 1.0000
0 0.6000 1.0000
0 0.8000 1.0000
0 1.0000 1.0000
0.2000 1.0000 0.8000
0.4000 1.0000 0.6000
0.6000 1.0000 0.4000
0.8000 1.0000 0.2000
1.0000 1.0000 0
1.0000 0.8000 0
1.0000 0.6000 0
1.0000 0.4000 0
1.0000 0.2000 0
1.0000 0 0
0.8000 0 0
0.6000 0 0 Image Processing using Matlab
Sumitha Balasuriya 5
RGB Entry for index value 3
3 4 7 3 6 1 9 8 9 1 2
5 6 14 4 2 5 6 1 4 5
2 8 9 4 2 13 7 8 4 5
5 1 11 5 6 4 1 7 4 4
1 9 5 6 5 5 1 4 4 6 5
5 9 2 1 11 1 3 6 1 9
7 6 8 18 1 8 1 9 1 3 3
9 2 3 7 2 9 8 1 6 6 4
7 8 6 7 4 15 8 2 1 3
7 5 10 8 4 10 4 3 6 4
Values can range
from 0.0 to 1.0
Red, green and blue intensities of
the nearest index in the colourmap
are used to display the image.
>> I2=I(:,:,2); % green values of I
>> image(I2)
>> colorbar % display colourmap
Image Processing using Matlab
Sumitha Balasuriya 6
Matlab considers I2 as an indexed image as it doesn’t
contain entries for red, green and blue entries
Index
Associated
color
Colour
Lookup
Table
 change colourmap
>> colormap(gray)
 scale colourmap
>> imagesc(I2)
Image Processing using Matlab
Sumitha Balasuriya 7
Type >>help graph3d to get a list of built-in
colourmaps. Experiment with different
built-in colourmaps.
Define your own colourmap mymap by
creating a matrix (size m x 3 ) with red,
green, blue entries. Display an image using
your colourmap.
Red =1.0,
Green = 1.0,
Blue =1.0,
corresponds to
index 64
Red =1.0,
Green = 1.0,
Blue =1.0,
corresponds to
index 255
Red =0.0,
Green = 0.0,
Blue = 0.0,
corresponds to
index 1
Red =0.0,
Green = 0.0,
Blue = 0.0,
corresponds to
index 0
>> axis image % plot fits to data
>> h=axes('position', [0 0 0.5 0.5]);
>> axes(h);
>> imagesc(I2)
Image Processing using Matlab
Sumitha Balasuriya 8
Investigate axis and axes
functions using Matlab’s help
 Frequency of the intensity values of the
image
 Quantise frequency into intervals (called
bins)
 (Un-normalised) probability density
function of image intensities
Image Processing using Matlab
Sumitha Balasuriya 9
>>hist(reshape(double(Lena(:,:,2)),[512*512
1]),50)
Image Processing using Matlab
Sumitha Balasuriya 10
Convert image into a 262144 by
1 distribution of values
Histogram
function
Number of bins
Histogram equalisation works by equitably distributing the pixels among the
histogram bins. Histogram equalise the green channel of the Lena image
using Matlab’s histeq function. Compare the equalised image with the
original. Display the histogram of the equalised image. The number of pixels
in each bin should be approximately equal.
Generate the histograms of the green channel of the Lena image using the
following number of bins : 10, 20, 50, 100, 200, 500, 1000
>>surf(double(imresize(Lena(:,:,2),[50 50])))
Image Processing using Matlab
Sumitha Balasuriya 11
Remember to reduce
size of image!
Use Matlab’s built-in mesh and
shading surface visualisation
functions
Change type to
double precision
 Convert image to grayscale
>>Igray=rgb2gray(I);
 Resize image
>>Ismall=imresize(I,[100 100], 'bilinear');
 Rotate image
>>I90=imrotate(I,90);
Image Processing using Matlab
Sumitha Balasuriya 12
Image Processing using Matlab
Sumitha Balasuriya 13
Convert polar coordinates to
cartesian coordinates
>>pol2cart(rho,theta)
Check if a variable is null
>>isempty(I)
Trigonometric functions
sin, cos, tan
Convert polar coordinates to
cartesian coordinates
>>cart2pol(x,y)
Find indices and elements in a
matrix
>>[X,Y]=find(I>100)
Fast Fourier Transform
Get size of matrix
>>size(I)
Change the dimensions of a
matrix
>>reshape(rand(10,10),[100 1])
Discrete Cosine Transform
Add elements of a Matrix
(columnwise addition in matrices)
>>sum(I)
Exponentials and Logarithms
exp
log
log10
fft2(I)
dct(I)
Bit of theory! Convolution of two functions f(x) and
g(x)
Discrete image processing 2D form
Image Processing using Matlab
Sumitha Balasuriya 14
( ) ( ) ( ) ( ) ( )h x f x g x f r g x r dr


   
convolution
operator
Image Filter
(mask/kernel)
Support region
of filter where
g(x-r) is nonzero
Output
filtered image
1 1
( , ) ( , ) ( , )
height width
j i
H x y I i j M x i y j
 
   
Compute the convolution where
there are valid indices in the kernel
Image Processing using Matlab
Sumitha Balasuriya 15
Write your own convolution function
myconv.m to perform a convolution.
It should accept two parameters – the
input matrix (image) and convolution
kernel, and output the filtered matrix.

1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9
i
j
Filter (M)
Image (I)
197 199 195 194 189 190 132 90 112 101
194 194 198 201 189 196 150 85 87 97
194 194 198 195 186 191 109 90 90 124
197 187 195 198 185 186 115 78 81 96
194 190 198 193 187 177 88 86 94 69
194 194 190 190 179 177 93 99 95 100
201 194 191 186 186 181 74 110 82 76
196 194 195 191 183 164 77 119 84 88
192 194 199 192 191 174 89 164 103 129
201 190 187 189 178 168 90 82 88 84
0 0 0 0 0 0 0 0 0 0
0 196 196 194 192 170 137 105 97 0
0 195 196 194 192 167 133 98 92 0
0 194 194 193 189 158 124 92 90 0
0 193 193 191 186 154 122 92 89 0
0 194 192 189 184 149 121 91 90 0
0 194 192 188 182 146 122 93 95 0
0 195 193 190 183 147 128 100 106 0
0 194 192 189 181 146 125 100 105 0
0 0 0 0 0 0 0 0 0 0
=
1 1
( , ) ( , ) ( , )
height width
j i
H x y I i j M x i y j
 
   
http://www.s2.chalmers.se/undergraduate/courses0203/ess060/PDFdocuments/ForScreen/Notes/Convolution.pdf
Image Processing using Matlab
Sumitha Balasuriya 16
Horizontal slice from Mandrill image
0.01 0.08 0.24 0.34 0.24 0.08 0.01
1D Gaussian filter
 =
Filtered Signal
Image Processing using Matlab
Sumitha Balasuriya 17
0.11 0.11 0.11
0.11 0.11 0.11
0.11 0.11 0.11
Arithmetic mean
filter (smoothing)
>>fspecial('average')
-0.17 -0.67 -0.17
-0.67 3.33 -0.67
-0.17 -0.67 -0.17
Laplacian (enhance edges)
>>fspecial('laplacian')
-0.17 -0.67 -0.17
-0.67 4.33 -0.67
-0.17 -0.67 -0.17
Sharpening filter
>>fspecial('unsharp')
0.01 0.08 0.01
0.08 0.62 0.08
0.01 0.08 0.01
Gaussian filter
(smoothing)
>>fspecial('gaussian')
Investigate the listed kernels in Matlab by
performing convolutions on the Mandrill and
Lena images. Study the effects of different
kernel sizes (3x3, 9x9, 25x25) on the output.
1 2 1
0 0 0
-1 -2 -1
1 0 -1
2 0 -2
1 0 -1
Sobel operators (edge detection in x
and y directions)
>>fspecial('sobel')
>>fspecial('sobel')’
The median filter is used for noise reduction. It works by
replacing a pixel value with the median of its neighbourhood
pixel values (vs the mean filter which uses the mean of the
neighbourhood pixel values). Apply Matlab’s median filter
function medfilt2 on the Mandrill and Lena images. Remember
to use different filter sizes (3x3, 9x9, 16x16).
 Generate useful filters for convolution
>>fspecial('gaussian',[kernel_height kernel_width],sigma)
 1D convolution
>>conv(signal,filter)
 2D convolution
>>conv2(double(I(:,:,2)),fspecial('gaussian‘,[kernel_height kernel_width]
,sigma),'valid')
Image Processing using Matlab
Sumitha Balasuriya 18
Perform the convolution of an image using Gaussian
kernels with different sizes and standard deviations
and display the output images.
Border padding optionskernelimage
1) Type the code in this handout in Matlab and investigate the results.
2) Do the exercises in the notes.
3) Create a grating2d.m function that generates a 2D steerable spatial
frequency. Compute spatial frequencies with an amplitude =1 and
the following parameters
frequency = 1/50, 1/25, 1/10, 1/5 cycles per pixel,
phase= 0, pi/5, pi/4, pi/3, pi/2, pi
theta = 0, pi/5, pi/4, pi/3, pi/2, pi
The value for pi is returned by the in-built matlab function pi.
Display your gratings using the in-built gray colourmap. (figure 1)
3) Create a superposition of two or more gratings with different
frequencies and thetas and display the result. You can do this by
simply adding the images you generated with grating2d (figure 2)
frequency = (1/10 and 1/20), (1/20 and 1/30)
theta = (pi/2 and pi/5), (pi/10 and pi/2), (pi/2 and pi)
Make sure you examine combinations of different frequencies and
theta values. (figure 3).
Visualise the intensity surface of the outputs that you have
generated. (figure 4)
4) Write a matlab function that segments a greyscale image based on a
given threshold (i.e. display pixels values greater than the threshold
value, zero otherwise). The function should accept two inputs, the
image matrix and the threshold value, and output the thresholded
image matrix. (figure 5)
Image Processing using Matlab
Sumitha Balasuriya 19
function H=grating2d(f,phi,theta,A)
% function to generate a 2D grating image
% f = frequency
% phi = phase
% theta = angle
% A = amplitude
% H=grating2d(f,phi,theta,A)
% size of grating
height=100;
width=100;
wr=2*pi*f; % angular frequency
wx=wr*cos(theta);
wy=wr*sin(theta);
for y=1:height
for x=1:width
H(x,y)=A*cos(wx*(x)+phi+wy*(y));
end
end
Figure 1 Figure 3Figure 2 Figure 4
Figure 5
Ad

More Related Content

What's hot (20)

Lect 02 second portion
Lect 02  second portionLect 02  second portion
Lect 02 second portion
Moe Moe Myint
 
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Majd Khaleel
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
Ali Ghanbarzadeh
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG
Sulaf Almagooshi
 
Image processing on matlab presentation
Image processing on matlab presentationImage processing on matlab presentation
Image processing on matlab presentation
Naatchammai Ramanathan
 
Image processing
Image processingImage processing
Image processing
Pooya Sagharchiha
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Shaleen Saini
 
Simple Matlab tutorial using matlab inbuilt commands
Simple Matlab tutorial using matlab inbuilt commandsSimple Matlab tutorial using matlab inbuilt commands
Simple Matlab tutorial using matlab inbuilt commands
Lakshmi Sarvani Videla
 
Image Texture Analysis
Image Texture AnalysisImage Texture Analysis
Image Texture Analysis
lalitxp
 
Introduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab ToolboxIntroduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab Toolbox
Shahriar Yazdipour
 
paper
paperpaper
paper
Amr Mohammed Rashid
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
Jagan Raja
 
Images in matlab
Images in matlabImages in matlab
Images in matlab
Ali Alvi
 
Dip Morphological
Dip MorphologicalDip Morphological
Dip Morphological
Mubbasher Khaliq
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Azharo7
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing Basics
Nam Le
 
Digital Image Fundamentals
Digital Image FundamentalsDigital Image Fundamentals
Digital Image Fundamentals
Dr. A. B. Shinde
 
Anish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_ReportAnish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_Report
anish h
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphics
Amol Gaikwad
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
minhtaispkt
 
Lect 02 second portion
Lect 02  second portionLect 02  second portion
Lect 02 second portion
Moe Moe Myint
 
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Image Processing using Matlab ( using a built in Matlab function(Histogram eq...
Majd Khaleel
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
Ali Ghanbarzadeh
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG
Sulaf Almagooshi
 
Image processing on matlab presentation
Image processing on matlab presentationImage processing on matlab presentation
Image processing on matlab presentation
Naatchammai Ramanathan
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Shaleen Saini
 
Simple Matlab tutorial using matlab inbuilt commands
Simple Matlab tutorial using matlab inbuilt commandsSimple Matlab tutorial using matlab inbuilt commands
Simple Matlab tutorial using matlab inbuilt commands
Lakshmi Sarvani Videla
 
Image Texture Analysis
Image Texture AnalysisImage Texture Analysis
Image Texture Analysis
lalitxp
 
Introduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab ToolboxIntroduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab Toolbox
Shahriar Yazdipour
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
Jagan Raja
 
Images in matlab
Images in matlabImages in matlab
Images in matlab
Ali Alvi
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Azharo7
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing Basics
Nam Le
 
Digital Image Fundamentals
Digital Image FundamentalsDigital Image Fundamentals
Digital Image Fundamentals
Dr. A. B. Shinde
 
Anish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_ReportAnish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_Report
anish h
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphics
Amol Gaikwad
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
minhtaispkt
 

Similar to Image processing using matlab (20)

Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
Ashok Kumar
 
Image processing in MATLAB
Image processing in MATLABImage processing in MATLAB
Image processing in MATLAB
Amarjeetsingh Thakur
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
Aman Gupta
 
Image processing using matlab
Image processing using matlabImage processing using matlab
Image processing using matlab
dedik dafiyanto
 
Matlab dip
Matlab dipMatlab dip
Matlab dip
Jeevan Reddy
 
Performance Anaysis for Imaging System
Performance Anaysis for Imaging SystemPerformance Anaysis for Imaging System
Performance Anaysis for Imaging System
Vrushali Lanjewar
 
Project 1
Project 1Project 1
Project 1
Wael Sharba
 
Image processing
Image processingImage processing
Image processing
maheshpene
 
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLABFAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
Journal For Research
 
Image Processing - Unit II - Image Enhancement discussed
Image Processing - Unit II - Image Enhancement discussedImage Processing - Unit II - Image Enhancement discussed
Image Processing - Unit II - Image Enhancement discussed
MsCNSavithri
 
image enhancement.pptx
image enhancement.pptximage enhancement.pptx
image enhancement.pptx
Arid Agriculture University, Rawalpindi
 
BMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorialBMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorial
potaters
 
Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLAB
vkn13
 
Matlab intro
Matlab introMatlab intro
Matlab intro
fvijayami
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portion
Moe Moe Myint
 
Image enhancement techniques
Image enhancement techniques Image enhancement techniques
Image enhancement techniques
Arshad khan
 
Image enhancement techniques
Image enhancement techniquesImage enhancement techniques
Image enhancement techniques
Saideep
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET Journal
 
imageenhancementtechniques-140316011049-phpapp01 (1).pptx
imageenhancementtechniques-140316011049-phpapp01 (1).pptximageenhancementtechniques-140316011049-phpapp01 (1).pptx
imageenhancementtechniques-140316011049-phpapp01 (1).pptx
salutiontechnology
 
Programming in matlab lesson5
Programming in matlab lesson5Programming in matlab lesson5
Programming in matlab lesson5
najmah17
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
Ashok Kumar
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
Aman Gupta
 
Image processing using matlab
Image processing using matlabImage processing using matlab
Image processing using matlab
dedik dafiyanto
 
Performance Anaysis for Imaging System
Performance Anaysis for Imaging SystemPerformance Anaysis for Imaging System
Performance Anaysis for Imaging System
Vrushali Lanjewar
 
Image processing
Image processingImage processing
Image processing
maheshpene
 
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLABFAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
FAST AND EFFICIENT IMAGE COMPRESSION BASED ON PARALLEL COMPUTING USING MATLAB
Journal For Research
 
Image Processing - Unit II - Image Enhancement discussed
Image Processing - Unit II - Image Enhancement discussedImage Processing - Unit II - Image Enhancement discussed
Image Processing - Unit II - Image Enhancement discussed
MsCNSavithri
 
BMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorialBMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorial
potaters
 
Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLAB
vkn13
 
Matlab intro
Matlab introMatlab intro
Matlab intro
fvijayami
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portion
Moe Moe Myint
 
Image enhancement techniques
Image enhancement techniques Image enhancement techniques
Image enhancement techniques
Arshad khan
 
Image enhancement techniques
Image enhancement techniquesImage enhancement techniques
Image enhancement techniques
Saideep
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET Journal
 
imageenhancementtechniques-140316011049-phpapp01 (1).pptx
imageenhancementtechniques-140316011049-phpapp01 (1).pptximageenhancementtechniques-140316011049-phpapp01 (1).pptx
imageenhancementtechniques-140316011049-phpapp01 (1).pptx
salutiontechnology
 
Programming in matlab lesson5
Programming in matlab lesson5Programming in matlab lesson5
Programming in matlab lesson5
najmah17
 
Ad

More from SangeethaSasi1 (20)

L4 multiplexing & multiple access 16
L4 multiplexing & multiple access 16L4 multiplexing & multiple access 16
L4 multiplexing & multiple access 16
SangeethaSasi1
 
Mc ppt
Mc pptMc ppt
Mc ppt
SangeethaSasi1
 
Mc ppt
Mc pptMc ppt
Mc ppt
SangeethaSasi1
 
Dip pppt
Dip ppptDip pppt
Dip pppt
SangeethaSasi1
 
Web techh
Web techhWeb techh
Web techh
SangeethaSasi1
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Vani wt
Vani wtVani wt
Vani wt
SangeethaSasi1
 
Vani dbms
Vani dbmsVani dbms
Vani dbms
SangeethaSasi1
 
Hema wt (1)
Hema wt (1)Hema wt (1)
Hema wt (1)
SangeethaSasi1
 
Hema rdbms
Hema rdbmsHema rdbms
Hema rdbms
SangeethaSasi1
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Dbms
DbmsDbms
Dbms
SangeethaSasi1
 
Vani
VaniVani
Vani
SangeethaSasi1
 
Hema se
Hema seHema se
Hema se
SangeethaSasi1
 
Software
SoftwareSoftware
Software
SangeethaSasi1
 
Operating system
Operating systemOperating system
Operating system
SangeethaSasi1
 
Dataminng
DataminngDataminng
Dataminng
SangeethaSasi1
 
System calls
System callsSystem calls
System calls
SangeethaSasi1
 
Java
JavaJava
Java
SangeethaSasi1
 
Ad

Recently uploaded (20)

Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 

Image processing using matlab

  • 1. G.KARTHIGAM.SC INFO TECH DEPARTMENT OF CS &IT NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE,THENI
  • 2.  Matlab is optimised for operating on matrices  Images are matrices!  Many useful built-in functions in the Matlab Image Processing Toolbox  Very easy to write your own image processing functions Image Processing using Matlab Sumitha Balasuriya 2
  • 3. >> I=imread('mandrill.bmp','bmp'); % load image >> image(I) % display image >> whos I Name Size Bytes Class I 512x512x3 786432 uint8 array Grand total is 786432 elements using 786432 bytes Image Processing using Matlab Sumitha Balasuriya 3 image filename as a string image format as a stringMatrix with image data Dimensions of I (red, green and blue intensity information) Matlab can only perform arithmetic operations on data with class double! Display the left half of the mandrill image
  • 4.  Images are just an array of numbers >> I % ctrl+c to halt output!  Intensity of each pixel is represented by the pixel element’s value in the red, green and blue matrices >> I(1,1,:) % RGB values of element (1,1) ans(:,:,1) = 135 ans(:,:,2) = 97 ans(:,:,3) = 33 Image Processing using Matlab Sumitha Balasuriya 4 Images where the pixel value in the image represents the intensity of the pixel are called intensity images. Red Green Blue
  • 5.  An indexed image is where the pixel values are indices to elements in a colour map or colour lookup table.  The colour map will contain entries corresponding to red, green and blue intensities for each index in the image. >> jet(20) % Generate a jet colourmap for 20 indices ans = 0 0 0.6000 0 0 0.8000 0 0 1.0000 0 0.2000 1.0000 0 0.4000 1.0000 0 0.6000 1.0000 0 0.8000 1.0000 0 1.0000 1.0000 0.2000 1.0000 0.8000 0.4000 1.0000 0.6000 0.6000 1.0000 0.4000 0.8000 1.0000 0.2000 1.0000 1.0000 0 1.0000 0.8000 0 1.0000 0.6000 0 1.0000 0.4000 0 1.0000 0.2000 0 1.0000 0 0 0.8000 0 0 0.6000 0 0 Image Processing using Matlab Sumitha Balasuriya 5 RGB Entry for index value 3 3 4 7 3 6 1 9 8 9 1 2 5 6 14 4 2 5 6 1 4 5 2 8 9 4 2 13 7 8 4 5 5 1 11 5 6 4 1 7 4 4 1 9 5 6 5 5 1 4 4 6 5 5 9 2 1 11 1 3 6 1 9 7 6 8 18 1 8 1 9 1 3 3 9 2 3 7 2 9 8 1 6 6 4 7 8 6 7 4 15 8 2 1 3 7 5 10 8 4 10 4 3 6 4 Values can range from 0.0 to 1.0 Red, green and blue intensities of the nearest index in the colourmap are used to display the image.
  • 6. >> I2=I(:,:,2); % green values of I >> image(I2) >> colorbar % display colourmap Image Processing using Matlab Sumitha Balasuriya 6 Matlab considers I2 as an indexed image as it doesn’t contain entries for red, green and blue entries Index Associated color Colour Lookup Table
  • 7.  change colourmap >> colormap(gray)  scale colourmap >> imagesc(I2) Image Processing using Matlab Sumitha Balasuriya 7 Type >>help graph3d to get a list of built-in colourmaps. Experiment with different built-in colourmaps. Define your own colourmap mymap by creating a matrix (size m x 3 ) with red, green, blue entries. Display an image using your colourmap. Red =1.0, Green = 1.0, Blue =1.0, corresponds to index 64 Red =1.0, Green = 1.0, Blue =1.0, corresponds to index 255 Red =0.0, Green = 0.0, Blue = 0.0, corresponds to index 1 Red =0.0, Green = 0.0, Blue = 0.0, corresponds to index 0
  • 8. >> axis image % plot fits to data >> h=axes('position', [0 0 0.5 0.5]); >> axes(h); >> imagesc(I2) Image Processing using Matlab Sumitha Balasuriya 8 Investigate axis and axes functions using Matlab’s help
  • 9.  Frequency of the intensity values of the image  Quantise frequency into intervals (called bins)  (Un-normalised) probability density function of image intensities Image Processing using Matlab Sumitha Balasuriya 9
  • 10. >>hist(reshape(double(Lena(:,:,2)),[512*512 1]),50) Image Processing using Matlab Sumitha Balasuriya 10 Convert image into a 262144 by 1 distribution of values Histogram function Number of bins Histogram equalisation works by equitably distributing the pixels among the histogram bins. Histogram equalise the green channel of the Lena image using Matlab’s histeq function. Compare the equalised image with the original. Display the histogram of the equalised image. The number of pixels in each bin should be approximately equal. Generate the histograms of the green channel of the Lena image using the following number of bins : 10, 20, 50, 100, 200, 500, 1000
  • 11. >>surf(double(imresize(Lena(:,:,2),[50 50]))) Image Processing using Matlab Sumitha Balasuriya 11 Remember to reduce size of image! Use Matlab’s built-in mesh and shading surface visualisation functions Change type to double precision
  • 12.  Convert image to grayscale >>Igray=rgb2gray(I);  Resize image >>Ismall=imresize(I,[100 100], 'bilinear');  Rotate image >>I90=imrotate(I,90); Image Processing using Matlab Sumitha Balasuriya 12
  • 13. Image Processing using Matlab Sumitha Balasuriya 13 Convert polar coordinates to cartesian coordinates >>pol2cart(rho,theta) Check if a variable is null >>isempty(I) Trigonometric functions sin, cos, tan Convert polar coordinates to cartesian coordinates >>cart2pol(x,y) Find indices and elements in a matrix >>[X,Y]=find(I>100) Fast Fourier Transform Get size of matrix >>size(I) Change the dimensions of a matrix >>reshape(rand(10,10),[100 1]) Discrete Cosine Transform Add elements of a Matrix (columnwise addition in matrices) >>sum(I) Exponentials and Logarithms exp log log10 fft2(I) dct(I)
  • 14. Bit of theory! Convolution of two functions f(x) and g(x) Discrete image processing 2D form Image Processing using Matlab Sumitha Balasuriya 14 ( ) ( ) ( ) ( ) ( )h x f x g x f r g x r dr       convolution operator Image Filter (mask/kernel) Support region of filter where g(x-r) is nonzero Output filtered image 1 1 ( , ) ( , ) ( , ) height width j i H x y I i j M x i y j       Compute the convolution where there are valid indices in the kernel
  • 15. Image Processing using Matlab Sumitha Balasuriya 15 Write your own convolution function myconv.m to perform a convolution. It should accept two parameters – the input matrix (image) and convolution kernel, and output the filtered matrix.  1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 i j Filter (M) Image (I) 197 199 195 194 189 190 132 90 112 101 194 194 198 201 189 196 150 85 87 97 194 194 198 195 186 191 109 90 90 124 197 187 195 198 185 186 115 78 81 96 194 190 198 193 187 177 88 86 94 69 194 194 190 190 179 177 93 99 95 100 201 194 191 186 186 181 74 110 82 76 196 194 195 191 183 164 77 119 84 88 192 194 199 192 191 174 89 164 103 129 201 190 187 189 178 168 90 82 88 84 0 0 0 0 0 0 0 0 0 0 0 196 196 194 192 170 137 105 97 0 0 195 196 194 192 167 133 98 92 0 0 194 194 193 189 158 124 92 90 0 0 193 193 191 186 154 122 92 89 0 0 194 192 189 184 149 121 91 90 0 0 194 192 188 182 146 122 93 95 0 0 195 193 190 183 147 128 100 106 0 0 194 192 189 181 146 125 100 105 0 0 0 0 0 0 0 0 0 0 0 = 1 1 ( , ) ( , ) ( , ) height width j i H x y I i j M x i y j       http://www.s2.chalmers.se/undergraduate/courses0203/ess060/PDFdocuments/ForScreen/Notes/Convolution.pdf
  • 16. Image Processing using Matlab Sumitha Balasuriya 16 Horizontal slice from Mandrill image 0.01 0.08 0.24 0.34 0.24 0.08 0.01 1D Gaussian filter  = Filtered Signal
  • 17. Image Processing using Matlab Sumitha Balasuriya 17 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 Arithmetic mean filter (smoothing) >>fspecial('average') -0.17 -0.67 -0.17 -0.67 3.33 -0.67 -0.17 -0.67 -0.17 Laplacian (enhance edges) >>fspecial('laplacian') -0.17 -0.67 -0.17 -0.67 4.33 -0.67 -0.17 -0.67 -0.17 Sharpening filter >>fspecial('unsharp') 0.01 0.08 0.01 0.08 0.62 0.08 0.01 0.08 0.01 Gaussian filter (smoothing) >>fspecial('gaussian') Investigate the listed kernels in Matlab by performing convolutions on the Mandrill and Lena images. Study the effects of different kernel sizes (3x3, 9x9, 25x25) on the output. 1 2 1 0 0 0 -1 -2 -1 1 0 -1 2 0 -2 1 0 -1 Sobel operators (edge detection in x and y directions) >>fspecial('sobel') >>fspecial('sobel')’ The median filter is used for noise reduction. It works by replacing a pixel value with the median of its neighbourhood pixel values (vs the mean filter which uses the mean of the neighbourhood pixel values). Apply Matlab’s median filter function medfilt2 on the Mandrill and Lena images. Remember to use different filter sizes (3x3, 9x9, 16x16).
  • 18.  Generate useful filters for convolution >>fspecial('gaussian',[kernel_height kernel_width],sigma)  1D convolution >>conv(signal,filter)  2D convolution >>conv2(double(I(:,:,2)),fspecial('gaussian‘,[kernel_height kernel_width] ,sigma),'valid') Image Processing using Matlab Sumitha Balasuriya 18 Perform the convolution of an image using Gaussian kernels with different sizes and standard deviations and display the output images. Border padding optionskernelimage
  • 19. 1) Type the code in this handout in Matlab and investigate the results. 2) Do the exercises in the notes. 3) Create a grating2d.m function that generates a 2D steerable spatial frequency. Compute spatial frequencies with an amplitude =1 and the following parameters frequency = 1/50, 1/25, 1/10, 1/5 cycles per pixel, phase= 0, pi/5, pi/4, pi/3, pi/2, pi theta = 0, pi/5, pi/4, pi/3, pi/2, pi The value for pi is returned by the in-built matlab function pi. Display your gratings using the in-built gray colourmap. (figure 1) 3) Create a superposition of two or more gratings with different frequencies and thetas and display the result. You can do this by simply adding the images you generated with grating2d (figure 2) frequency = (1/10 and 1/20), (1/20 and 1/30) theta = (pi/2 and pi/5), (pi/10 and pi/2), (pi/2 and pi) Make sure you examine combinations of different frequencies and theta values. (figure 3). Visualise the intensity surface of the outputs that you have generated. (figure 4) 4) Write a matlab function that segments a greyscale image based on a given threshold (i.e. display pixels values greater than the threshold value, zero otherwise). The function should accept two inputs, the image matrix and the threshold value, and output the thresholded image matrix. (figure 5) Image Processing using Matlab Sumitha Balasuriya 19 function H=grating2d(f,phi,theta,A) % function to generate a 2D grating image % f = frequency % phi = phase % theta = angle % A = amplitude % H=grating2d(f,phi,theta,A) % size of grating height=100; width=100; wr=2*pi*f; % angular frequency wx=wr*cos(theta); wy=wr*sin(theta); for y=1:height for x=1:width H(x,y)=A*cos(wx*(x)+phi+wy*(y)); end end Figure 1 Figure 3Figure 2 Figure 4 Figure 5