Top Banner
Working with images in Matlab: the Image Processing Toolbox
42

Working with images in Matlab: the Image Processing Toolbox

Feb 11, 2017

Download

Documents

nguyenhuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Working with images in Matlab: the Image Processing Toolbox

Working with images in Matlab: the Image Processing Toolbox

Page 2: Working with images in Matlab: the Image Processing Toolbox

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

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

Reading an image

Page 5: Working with images in Matlab: the Image Processing Toolbox

Displaying the image

Page 6: Working with images in Matlab: the Image Processing Toolbox

Converting to grayscale

Page 7: Working with images in Matlab: the Image Processing Toolbox

Image processing applications

Page 8: Working with images in Matlab: the Image Processing Toolbox

Example 1: sharpening

Page 9: Working with images in Matlab: the Image Processing Toolbox

Example 2: denoising

Page 10: Working with images in Matlab: the Image Processing Toolbox

Example 3: deblurring

Page 11: Working with images in Matlab: the Image Processing Toolbox

Example 4: edge detection

Page 12: Working with images in Matlab: the Image Processing Toolbox

Image format: grayscale

Page 13: Working with images in Matlab: the Image Processing Toolbox

Image format: color (RGB)

Page 14: Working with images in Matlab: the Image Processing Toolbox

Image format: color (indexed)

Page 15: Working with images in Matlab: the Image Processing Toolbox

Converting: RGB to indexed

RGB image Indexed image

Page 16: Working with images in Matlab: the Image Processing Toolbox

Image format conversion and

basic data types in Matlab

Page 17: Working with images in Matlab: the Image Processing Toolbox

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

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

Image histograms – imhist()

Page 20: Working with images in Matlab: the Image Processing Toolbox

Image histogram equalization – histeq()

Page 21: Working with images in Matlab: the Image Processing Toolbox

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

Spatial filtering in Matlab

Page 23: Working with images in Matlab: the Image Processing Toolbox

Spatial filtering in Matlab – filter2()

Page 24: Working with images in Matlab: the Image Processing Toolbox

Spatial filtering in Matlab – filter2()

Page 25: Working with images in Matlab: the Image Processing Toolbox

Spatial filtering in Matlab – filter2() continued

Page 26: Working with images in Matlab: the Image Processing Toolbox

High pass filtering ( using fspecial() + filter2() )

Page 27: Working with images in Matlab: the Image Processing Toolbox

High pass filtering - continued

Page 28: Working with images in Matlab: the Image Processing Toolbox

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

Unsharp masking: example

Page 30: Working with images in Matlab: the Image Processing Toolbox

Unsharp masking: example 2

Page 31: Working with images in Matlab: the Image Processing Toolbox

Fourier transforms in Matlab (1D and 2D)

Page 32: Working with images in Matlab: the Image Processing Toolbox

Fourier transforms: example 1

Page 33: Working with images in Matlab: the Image Processing Toolbox

Fourier transforms: example 2

Page 34: Working with images in Matlab: the Image Processing Toolbox

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

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

Edge detection in images – edge()

Page 37: Working with images in Matlab: the Image Processing Toolbox

Edge detection in images - example 1

Page 38: Working with images in Matlab: the Image Processing Toolbox

Edge detection in images - example 2

Page 39: Working with images in Matlab: the Image Processing Toolbox

Edge detection in images - example 3

Page 40: Working with images in Matlab: the Image Processing Toolbox

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

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

Geometric transformations – affine transform