![Page 1: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/1.jpg)
Working with images in Matlab: the Image Processing Toolbox
![Page 2: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/2.jpg)
Introduction
The image processing toolbox is a collection of functions operating on images. We will discuss:
Reading images in Matlab
Grayscale/RGB/Indexed image formats
Image format conversion
Image display and exploration
Image processing using filters, Fourier transforms, edge detectors, etc.
![Page 3: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/3.jpg)
Documentation and demos
For a list of functions in the image processing toolbox use: doc images (HTML) or the older help images (text).
Use iptdemos to see image processing demos. To read about any function, use doc, e.g.,
doc imread. Help online: http://www.mathworks.com/help/. Complete beginners: run in Matlab: playbackdemo('GettingStartedwithMATLAB',
'toolbox/matlab/demos/html') .
![Page 4: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/4.jpg)
Reading an image
![Page 5: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/5.jpg)
Displaying the image
![Page 6: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/6.jpg)
Converting to grayscale
![Page 7: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/7.jpg)
Image processing applications
![Page 8: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/8.jpg)
Example 1: sharpening
![Page 9: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/9.jpg)
Example 2: denoising
![Page 10: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/10.jpg)
Example 3: deblurring
![Page 11: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/11.jpg)
Example 4: edge detection
![Page 12: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/12.jpg)
Image format: grayscale
![Page 13: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/13.jpg)
Image format: color (RGB)
![Page 14: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/14.jpg)
Image format: color (indexed)
![Page 15: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/15.jpg)
Converting: RGB to indexed
RGB image Indexed image
![Page 16: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/16.jpg)
Image format conversion and
basic data types in Matlab
![Page 17: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/17.jpg)
Exploring the image
Use impixelinfo to display the grayscale/RGB values at each pixel.
Use improfile to display the image profile.
![Page 18: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/18.jpg)
Using the image() function
image requires the use of a colormap. The default is colormap(jet).
For grayscale images use colormap(gray) (16 colors) or colormap(gray(n)) (n colors) .
![Page 19: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/19.jpg)
Image histograms – imhist()
![Page 20: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/20.jpg)
Image histogram equalization – histeq()
![Page 21: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/21.jpg)
LUT operations on an image
hI = imhist(I); LUT = 255*cumsum(hI ) / prod( size(I) ); figure; imshow( uint8( LUT(I) ) );
I = imread('cameraman.tif'); figure; imshow(I);
![Page 22: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/22.jpg)
Spatial filtering in Matlab
![Page 23: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/23.jpg)
Spatial filtering in Matlab – filter2()
![Page 24: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/24.jpg)
Spatial filtering in Matlab – filter2()
![Page 25: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/25.jpg)
Spatial filtering in Matlab – filter2() continued
![Page 26: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/26.jpg)
High pass filtering ( using fspecial() + filter2() )
![Page 27: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/27.jpg)
High pass filtering - continued
![Page 28: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/28.jpg)
Unsharp masking: sharpening the edges
The edges can be enhanced by subtracting a scaled unsharp
(low passed) version of the image from the original one.
![Page 29: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/29.jpg)
Unsharp masking: example
![Page 30: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/30.jpg)
Unsharp masking: example 2
![Page 31: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/31.jpg)
Fourier transforms in Matlab (1D and 2D)
![Page 32: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/32.jpg)
Fourier transforms: example 1
![Page 33: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/33.jpg)
Fourier transforms: example 2
![Page 34: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/34.jpg)
Fourier transforms: example 3
fI = fftshift( fft2(c)); figure; imshow( log( abs(fI ) + eps ), [] );
I = imread('cameraman.tif'); figure; imshow(I);
![Page 35: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/35.jpg)
Image thresholding
• Can be achieved by im2bw () and graythresh() functions as well. BW = im2bw(I, level) ; level = graythresh(I);
![Page 36: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/36.jpg)
Edge detection in images – edge()
![Page 37: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/37.jpg)
Edge detection in images - example 1
![Page 38: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/38.jpg)
Edge detection in images - example 2
![Page 39: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/39.jpg)
Edge detection in images - example 3
![Page 40: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/40.jpg)
Finding the lines in an image After using an edge detector, the resulting edge points will not necessarily form continuous lines and curves. To establish the boundaries between regions line fitting may be employed using the Hough transform.
Hough transform functions: hough() houghpeaks() houghlines()
![Page 41: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/41.jpg)
Hough transform - example BW=edge(rgb2gray(RGB),'canny');
figure; imshow(BW); RGB=imread('gantrycrane.png');
figure; imshow(RGB);
[H,T,R] =
hough(BW,'RhoResolution',0.5,
‘ThetaResolution',0.5);
H( :, T<44 | T>46 )=0;
figure; mesh(H,'XData',T,'YData',R);
xlabel('\theta'), ylabel('\rho');
![Page 42: Working with images in Matlab: the Image Processing Toolbox](https://reader036.vdocuments.us/reader036/viewer/2022082213/589ecf801a28ab784d8b55a9/html5/thumbnails/42.jpg)
Geometric transformations – affine transform