42
Working with images in Matlab: the Image Processing Toolbox

Working with images in Matlab: the Image Processing Toolboxbrd4.ort.org.il/~ksamuel/ImProc.31651/Lectures.For Students/Image... · Introduction The image processing toolbox is a collection

  • Upload
    lediep

  • View
    220

  • Download
    2

Embed Size (px)

Citation preview

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.

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') .

Reading an image

Displaying the image

Converting to grayscale

Image processing applications

Example 1: sharpening

Example 2: denoising

Example 3: deblurring

Example 4: edge detection

Image format: grayscale

Image format: color (RGB)

Image format: color (indexed)

Converting: RGB to indexed

RGB image Indexed image

Image format conversion and

basic data types in Matlab

Exploring the image

Use impixelinfo to display the grayscale/RGB values at each pixel.

Use improfile to display the image profile.

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) .

Image histograms – imhist()

Image histogram equalization – histeq()

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);

Spatial filtering in Matlab

Spatial filtering in Matlab – filter2()

Spatial filtering in Matlab – filter2()

Spatial filtering in Matlab – filter2() continued

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

High pass filtering - continued

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.

Unsharp masking: example

Unsharp masking: example 2

Fourier transforms in Matlab (1D and 2D)

Fourier transforms: example 1

Fourier transforms: example 2

Fourier transforms: example 3

fI = fftshift( fft2(c)); figure; imshow( log( abs(fI ) + eps ), [] );

I = imread('cameraman.tif'); figure; imshow(I);

Image thresholding

• Can be achieved by im2bw () and graythresh() functions as well. BW = im2bw(I, level) ; level = graythresh(I);

Edge detection in images – edge()

Edge detection in images - example 1

Edge detection in images - example 2

Edge detection in images - example 3

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()

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');

Geometric transformations – affine transform