Image processing using MATLAB

Slides:



Advertisements
Similar presentations
Filters, Edge Detection and Sharpening Francesca Pizzorni Ferrarese 28/04/2010.
Advertisements

Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Laboratory of Image Processing Pier Luigi Mazzeo
Computational Biology, Part 23 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
Spatial Filtering (Chapter 3)
Chapter 3 Image Enhancement in the Spatial Domain.
Motion illusion, rotating snakes. Slide credit Fei Fei Li.
Sliding Window Filters and Edge Detection Longin Jan Latecki Computer Graphics and Image Processing CIS 601 – Fall 2004.
CS 4487/9587 Algorithms for Image Analysis
Digital Image Processing
Digital Image Processing In The Name Of God Digital Image Processing Lecture3: Image enhancement M. Ghelich Oghli By: M. Ghelich Oghli
Multimedia communications EG 371Dr Matt Roach Multimedia Communications EG 371 and EE 348 Dr Matt Roach Lecture 6 Image processing (filters)
1Ellen L. Walker Edges Humans easily understand “line drawings” as pictures.
Lecture 4 Linear Filters and Convolution
Edge detection. Edge Detection in Images Finding the contour of objects in a scene.
CS 376b Introduction to Computer Vision 02 / 27 / 2008 Instructor: Michael Eckmann.
1 Image Filtering Readings: Ch 5: 5.4, 5.5, 5.6,5.7.3, 5.8 (This lecture does not follow the book.) Images by Pawan SinhaPawan Sinha formal terminology.
Image Enhancement.
Lecture 4: Edge Based Vision Dr Carole Twining Thursday 18th March 2:00pm – 2:50pm.
Linear filtering.
Edge Detection Today’s readings Cipolla and Gee –supplemental: Forsyth, chapter 9Forsyth Watt, From Sandlot ScienceSandlot Science.
© 2010 Cengage Learning Engineering. All Rights Reserved.
2D FOURIER TRANSFORMS AND IMAGE FILTERS DAVID COOPER SUMMER 2014.
Chapter 2. Image Analysis. Image Analysis Domains Frequency Domain Spatial Domain.
CS 376b Introduction to Computer Vision 02 / 26 / 2008 Instructor: Michael Eckmann.
Chapter 5 Neighborhood Processing
Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Image processing.
Filtering and Enhancing Images. Major operations 1. Matching an image neighborhood with a pattern or mask 2. Convolution (FIR filtering)
Image Arithmetic Image arithmetic is the implementation of standard arithmetic operations, such as addition, subtraction, multiplication, and division,
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
SHINTA P. Juli What are edges in an image? Edge Detection Edge Detection Methods Edge Operators Matlab Program.
Digital Image Processing Lecture 10: Image Restoration March 28, 2005 Prof. Charlene Tsai.
Chapter 5: Neighborhood Processing
Linear filtering. Motivation: Noise reduction Given a camera and a still scene, how can you reduce noise? Take lots of images and average them! What’s.
Digital Image Processing Lecture 10: Image Restoration
Spatial Filtering (Applying filters directly on Image) By Engr. Muhammad Saqib.
Digital Image Processing, 3rd ed. © 1992–2008 R. C. Gonzalez & R. E. Woods Gonzalez & Woods Chapter 3 Intensity Transformations.
EE 4780 Edge Detection.
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
October 7, 2014Computer Vision Lecture 9: Edge Detection II 1 Laplacian Filters Idea: Smooth the image, Smooth the image, compute the second derivative.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
Edge Detection and Geometric Primitive Extraction Jinxiang Chai.
Mestrado em Ciência de Computadores Mestrado Integrado em Engenharia de Redes e Sistemas Informáticos VC 15/16 – TP7 Spatial Filters Miguel Tavares Coimbra.
Chapter 5: Neighborhood Processing 5.1 Introduction
Chapter 9: Image Segmentation
October 1, 2013Computer Vision Lecture 9: From Edges to Contours 1 Canny Edge Detector However, usually there will still be noise in the array E[i, j],
CSE 6367 Computer Vision Image Operations and Filtering “You cannot teach a man anything, you can only help him find it within himself.” ― Galileo GalileiGalileo.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities May 2, 2005 Prof. Charlene Tsai.
Course 5 Edge Detection. Image Features: local, meaningful, detectable parts of an image. edge corner texture … Edges: Edges points, or simply edges,
Digital Image Processing Lecture 17: Segmentation: Canny Edge Detector & Hough Transform Prof. Charlene Tsai.
Machine Vision Edge Detection Techniques ENT 273 Lecture 6 Hema C.R.
Instructor: Mircea Nicolescu Lecture 7
Linear filtering. Motivation: Image denoising How can we reduce noise in a photograph?
CSE 185 Introduction to Computer Vision Image Filtering: Spatial Domain.
M ATLAB L ECTURE 3 Histogram Processing. H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in.
September 26, 2013Computer Vision Lecture 8: Edge Detection II 1Gradient In the one-dimensional case, a step edge corresponds to a local peak in the first.
Sliding Window Filters Longin Jan Latecki October 9, 2002.
Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis.
Image Enhancement in the Spatial Domain.
Miguel Tavares Coimbra
Laboratory of Image Processing Pier Luigi Mazzeo
Fundamentals of Spatial Filtering:
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
Digital Image Processing Lecture 10: Image Restoration
Detection of discontinuity using
Image Enhancement in the
Computer Vision Lecture 9: Edge Detection II
Image Filtering Readings: Ch 5: 5. 4, 5. 5, 5. 6, , 5
IT472 Digital Image Processing
Presentation transcript:

Image processing using MATLAB MAE 587 Optomechatronics 2005. 10. 14 Hyunki Lee mradam1004@kaist.ac.kr

Contents What is MATLAB? Image reading and showing Image Histogram Histogram equalization Noise add and filtering Salt & pepper noise -> median filtering Gaussian noise -> mean filtering Thresholding Feature extraction Edge detection Sobel operator LoG Hough Transform 2005 Optomechatronics

What is MATLAB? Script language MATrix LABoratory Numerical Analysis, Matrix computation, Signal Processing and GUI Advantage of MATLAB : "Life is too short to spend writing DO loops" 2005 Optomechatronics

Composition of MATLAB run M-file command line SIMULINK 2005 Optomechatronics

Preparation of programming Copy images to “work” folder C://MATLAB/work/ 2005 Optomechatronics

Images for testing kaist.jpg lib.bmp lib2.bmp rerc.bmp tool.bmp lena.bmp 2005 Optomechatronics

Image reading and showing image_r_s.m %image reading I = imread( ‘tao.jpg’ ); %image showing figure; imshow(I); 2005 Optomechatronics

Image Histogram image_histogram.m %estimating the histogram H = imhist( I ); %histogram showing figure; bar(H); 2005 Optomechatronics

Histogram equalization image_histogram_eq.m %histogram equalization J = histeq(I); figure; imshow(J); 2005 Optomechatronics

HISTEQ Enhance contrast using histogram equalization. HISTEQ enhances the contrast of images by transforming the values in an intensity image, or the values in the colormap of an indexed image, so that the histogram of the output image approximately matches a specified histogram. J = HISTEQ(I,HGRAM) transforms the intensity image I so that the histogram of the output image J with length(HGRAM) bins approximately matches HGRAM. The vector HGRAM should contain integer counts for equally spaced bins with intensity values in the appropriate range: [0,1] for images of class double, [0,255] for images of class uint8, and [0,65535] for images of class uint16. HISTEQ automatically scales HGRAM so that sum(HGRAM) = prod(size(I)). The histogram of J will better match HGRAM when length(HGRAM) is much smaller than the number of discrete levels in I. J = HISTEQ(I,N) transforms the intensity image I, returning in J an intensity image with N discrete levels. A roughly equal number of pixels is mapped to each of the N levels in J, so that the histogram of J is approximately flat. (The histogram of J is flatter when N is much smaller than the number of discrete levels in I.) The default value for N is 64. [J,T] = HISTEQ(I) returns the gray scale transformation that maps gray levels in the intensity image I to gray levels in J. NEWMAP = HISTEQ(X,MAP,HGRAM) transforms the colormap associated with the indexed image X so that the histogram of the gray component of the indexed image (X,NEWMAP) approximately matches HGRAM. HISTEQ returns the transformed colormap in NEWMAP. length(HGRAM) must be the same as size(MAP,1). NEWMAP = HISTEQ(X,MAP) transforms the values in the colormap so that the histogram of the gray component of the indexed image X is approximately flat. It returns the transformed colormap in NEWMAP. NEWMAP,T] = HISTEQ(X,...) returns the gray scale transformation T that maps the gray component of MAP to the gray component of NEWMAP. 2005 Optomechatronics

Noise add and filtering Salt & pepper noise -> median filtering salt_pepper_median.m %Salt & pepper noise add J = imnoise(I,'salt & pepper', 0.02); figure; imshow(J); %median filtering f2=medfilt2(J,[3 3]); figure; imshow(f2); 2005 Optomechatronics

2005 Optomechatronics IMNOISE Add noise to image. J = IMNOISE(I,TYPE,...) Add noise of a given TYPE to the intensity image I. TYPE is a string that can have one of these values: 'gaussian' Gaussian white noise with constant mean and variance 'localvar' Zero-mean Gaussian white noise with an intensity-dependent variance 'poisson' Poisson noise 'salt & pepper' "On and Off" pixels 'speckle' Multiplicative noise Depending on TYPE, you can specify additional parameters to IMNOISE. All numerical parameters are normalized; they correspond to operations with images with intensities ranging from 0 to 1. J = IMNOISE(I,'gaussian',M,V) adds Gaussian white noise of mean M and variance V to the image I. When unspecified, M and V default to 0 and 0.01 respectively. J = imnoise(I,'localvar',V) adds zero-mean, Gaussian white noise of local variance, V, to the image I. V is an array of the same size as I. J = imnoise(I,'localvar',IMAGE_INTENSITY,VAR) adds zero-mean, Gaussian noise to an image, I, where the local variance of the noise is a function of the image intensity values in I. IMAGE_INTENSITY and VAR are vectors of the same size, and PLOT(IMAGE_INTENSITY,VAR) plots the functional relationship between noise variance and image intensity. IMAGE_INTENSITY must contain normalized intensity values ranging from 0 to 1. J = IMNOISE(I,'poisson') generates Poisson noise from the data instead of adding artificial noise to the data. In order to respect Poisson statistics, the intensities of uint8 and uint16 images must correspond to the number of photons (or any other quanta of information). Double-precision images are used when the number of photons per pixel can be much larger than 65535 (but less than 10^12); the intensities values vary between 0 and 1 and correspond to the number of photons divided by 10^12. J = IMNOISE(I,'salt & pepper',D) adds "salt and pepper" noise to the image I, where D is the noise density. This affects approximately D*PROD(SIZE(I)) pixels. The default for D is 0.05. J = IMNOISE(I,'speckle',V) adds multiplicative noise to the image I, using the equation J = I + n*I, where n is uniformly distributed random noise with mean 0 and variance V. The default for V is 0.04. 2005 Optomechatronics

MEDFILT2 Perform 2-D median filtering. B = MEDFILT2(A,[M N]) performs median filtering of the matrix A in two dimensions. Each output pixel contains the median value in the M-by-N neighborhood around the corresponding pixel in the input image. MEDFILT2 pads the image with zeros on the edges, so the median values for the points within [M N]/2 of the edges may appear distorted. B = MEDFILT2(A) performs median filtering of the matrix A using the default 3-by-3 neighborhood. B = MEDFILT2(...,PADOPT) controls how the matrix boundaries are padded. PADOPT may be 'zeros' (the default), 'symmetric', or 'indexed'. If ADOPT is 'zeros', A is padded with zeros at the boundaries. If PADOPT is 'symmetric', A is symmetrically extended at the boundaries. If PADOPT is 'indexed', A is padded with ones if it is double; otherwise it is padded with zeros. 2005 Optomechatronics

Gaussian noise -> mean filtering gaussian_mean.m %Gaussian noise add J = imnoise(I, 'gaussian', 0, 0.001); figure; imshow(J); %mean filtering H = fspecial('average', [3 3] ); f2 = imfilter(I,H); figure; imshow(f2); 2005 Optomechatronics

2005 Optomechatronics FSPECIAL Create 2-D special filters. H = FSPECIAL(TYPE) creates a two-dimensional filter H of the specified type. Possible values for TYPE are: 'average' averaging filter 'disk' circular averaging filter 'gaussian' Gaussian lowpass filter 'laplacian' filter approximating the 2-D Laplacian operator 'log' Laplacian of Gaussian filter 'motion' motion filter 'prewitt' Prewitt horizontal edge-emphasizing filter 'sobel' Sobel horizontal edge-emphasizing filter 'unsharp' unsharp contrast enhancement filter Depending on TYPE, FSPECIAL may take additional parameters which you can supply. These parameters all have default values. H = FSPECIAL('average',HSIZE) returns an averaging filter H of size HSIZE. HSIZE can be a vector specifying the number of rows and columns in H or a scalar, in which case H is a square matrix. The default HSIZE is [3 3]. H = FSPECIAL('disk',RADIUS) returns a circular averaging filter (pillbox) within the square matrix of side 2*RADIUS+1. The default RADIUS is 5. H = FSPECIAL('gaussian',HSIZE,SIGMA) returns a rotationally symmetric Gaussian lowpass filter of size HSIZE with standard deviation SIGMA (positive). HSIZE can be a vector specifying the number of rows and columns in H or a scalar, in which case H is a square matrix. The default HSIZE is [3 3], the default SIGMA is 0.5. H = FSPECIAL('laplacian',ALPHA) returns a 3-by-3 filter approximating the shape of the two-dimensional Laplacian operator. The parameter ALPHA controls the shape of the Laplacian and must be in the range 0.0 to 1.0. The default ALPHA is 0.2. H = FSPECIAL('log',HSIZE,SIGMA) returns a rotationally symmetric Laplacian of Gaussian filter of size HSIZE with standard deviation SIGMA (positive). HSIZE can be a vector specifying the number of rows and columns in H or a scalar, in which case H is a square matrix. The default HSIZE is [5 5], the default SIGMA is 0.5. H = FSPECIAL('motion',LEN,THETA) returns a filter to approximate, once convolved with an image, the linear motion of a camera by LEN pixels, with an angle of THETA degrees in a counter-clockwise direction. The filter becomes a vector for horizontal and vertical motions. The default LEN is 9, the default THETA is 0, which corresponds to a horizontal motion of 9 pixels. H = FSPECIAL('prewitt') returns 3-by-3 filter that emphasizes horizontal edges by approximating a vertical gradient. If you need to emphasize vertical edges, transpose the filter H: H'. [1 1 1;0 0 0;-1 -1 -1]. H = FSPECIAL('sobel') returns 3-by-3 filter that emphasizes horizontal edges utilizing the smoothing effect by approximating a vertical gradient. If you need to emphasize vertical edges, transpose the filter H: H'. [1 2 1;0 0 0;-1 -2 -1]. H = FSPECIAL('unsharp',ALPHA) returns a 3-by-3 unsharp contrast enhancement filter. FSPECIAL creates the unsharp filter from the negative of the Laplacian filter with parameter ALPHA. ALPHA controls the shape of the Laplacian and must be in the range 0.0 to 1.0. The default ALPHA is 0.2. 2005 Optomechatronics

2005 Optomechatronics IMFILTER Multidimensional image filtering. B = IMFILTER(A,H) filters the multidimensional array A with the multidimensional filter H. A can be logical or it can be a nonsparse numeric array of any class and dimension. The result, B, has the same size and class as A. Each element of the output, B, is computed using double-precision floating point. If A is an integer or logical array, then output elements that exceed the range of the given type are truncated, and fractional values are rounded. B = IMFILTER(A,H,OPTION1,OPTION2,...) performs multidimensional filtering according to the specified options. Option arguments can have the following values: - Boundary options X : Input array values outside the bounds of the array are implicitly assumed to have the value X. When no boundary option is specified, IMFILTER uses X = 0. 'symmetric‘ : Input array values outside the bounds of the array are computed by mirror-reflecting the array across the array border. 'replicate‘ : Input array values outside the bounds of the array are assumed to equal the nearest array border value. 'circular' : Input array values outside the bounds of the array are computed by implicitly assuming the input array is periodic. - Output size options (Output size options for IMFILTER are analogous to the SHAPE option in the functions CONV2 and FILTER2.) 'same' : The output array is the same size as the input array. This is the default behavior when no output size options are specified. 'full‘ : The output array is the full filtered result, and so is larger than the input array. - Correlation and convolution 'corr‘ : IMFILTER performs multidimensional filtering using correlation, which is the same way that FILTER2 performs filtering. When no correlation or convolution option is specified, IMFILTER uses correlation. 'conv‘ : IMFILTER performs multidimensional filtering using convolution. 2005 Optomechatronics

Thresholding threshold.m clear all % reading image File image = imread( ‘kaist.jpg' ); [y,x] = size(image); threshold=128; % defined by user % threshold for i=1:x for j=1:y if image(j,i) > threshold image_th(j,i) = 255; else image_th(j,i) = 0; end % showing image figure subplot(1,2,1), imshow(image) subplot(1,2,2), imshow(image_th) 2005 Optomechatronics

J=im2bw( I, 0.5 ); figure; imshow(J); IM2BW Convert image to binary image by thresholding. IM2BW produces binary images from indexed, intensity, or RGB images. To do this, it converts the input image to grayscale format (if it is not already an intensity image), and then converts this grayscale image to binary by thresholding. The output binary image BW has values of 0 (black) for all pixels in the input image with luminance less than LEVEL and 1 (white) for all other pixels. (Note that you specify LEVEL in the range [0,1], regardless of the class of the input image.) BW = IM2BW(I,LEVEL) converts the intensity image I to black and white. BW = IM2BW(X,MAP,LEVEL) converts the indexed image X with colormap MAP to black and white. BW = IM2BW(RGB,LEVEL) converts the RGB image RGB to black and white. Note that the function GRAYTHRESH can be used to compute LEVEL automatically. J=im2bw( I, 0.5 ); figure; imshow(J); 2005 Optomechatronics

Threshold value 0.1 0.3 0.7 0.9 2005 Optomechatronics

background object threshold value = 120 2005 Optomechatronics

Feature extraction Corner * * SUSAN corner detector Harris corner detector …………………………. * * * * Center Point feature_center.m 2005 Optomechatronics

Edge detection Sobel operator edge_sobel.m %Sobel operator BW=edge(I, 'sobel' ); figure; imshow(BW); 2005 Optomechatronics

2005 Optomechatronics EDGE Find edges in intensity image. EDGE takes an intensity or a binary image I as its input, and returns a binary image BW of the same size as I, with 1's where the function finds edges in I and 0's elsewhere. EDGE supports six different edge-finding methods: The Sobel method finds edges using the Sobel approximation to the derivative. It returns edges at those points where the gradient of I is maximum. The Prewitt method finds edges using the Prewitt approximation to the derivative. It returns edges at those points where the gradient of I is maximum. The Roberts method finds edges using the Roberts approximation to the derivative. It returns edges at those points where the gradient of I is maximum. The Laplacian of Gaussian method finds edges by looking for zero crossings after filtering I with a Laplacian of Gaussian filter. The zero-cross method finds edges by looking for zero crossings after filtering I with a filter you specify. The Canny method finds edges by looking for local maxima of the gradient of I. The gradient is calculated using the derivative of a Gaussian filter. The method uses two thresholds, to detect strong and weak edges, and includes the weak edges in the output only if they are connected to strong edges. This method is therefore less likely than the others to be "fooled" by noise, and more likely to detect true weak edges. The parameters you can supply differ depending on the method you specify. If you do not specify a method, EDGE uses the Sobel method. Sobel Method ------------ BW = EDGE(I,'sobel') specifies the Sobel method. BW = EDGE(I,'sobel',THRESH) specifies the sensitivity threshold for the Sobel method. EDGE ignores all edges that are not stronger than THRESH. If you do not specify THRESH, or if THRESH is empty ([]), EDGE chooses the value automatically. BW = EDGE(I,'sobel',THRESH,DIRECTION) specifies directionality for the Sobel method. DIRECTION is a string specifying whether to look for 'horizontal' or 'vertical' edges, or 'both' (the default). [BW,thresh] = EDGE(I,'sobel',...) returns the threshold value. Prewitt Method -------------- BW = EDGE(I,'prewitt') specifies the Prewitt method. BW = EDGE(I,'prewitt',THRESH) specifies the sensitivity threshold for the Prewitt method. EDGE ignores all edges that are not stronger than THRESH. If you do not specify THRESH, or if THRESH is empty ([]), EDGE chooses the value automatically. BW = EDGE(I,'prewitt',THRESH,DIRECTION) specifies directionality for the Prewitt method. DIRECTION is a string specifying whether to look for 'horizontal' or 'vertical' edges, or 'both' (the default). [BW,thresh] = EDGE(I,'prewitt',...) returns the threshold value. 2005 Optomechatronics

2005 Optomechatronics Roberts Method -------------- BW = EDGE(I,'roberts') specifies the Roberts method. BW = EDGE(I,'roberts',THRESH) specifies the sensitivity threshold for the Roberts method. EDGE ignores all edges that are not stronger than THRESH. If you do not specify THRESH, or if THRESH is empty ([]), EDGE chooses the value automatically. [BW,thresh] = EDGE(I,'roberts',...) returns the threshold value. Laplacian of Gaussian Method ---------------------------- BW = EDGE(I,'log') specifies the Laplacian of Gaussian method. BW = EDGE(I,'log',THRESH) specifies the sensitivity threshold for the Laplacian of Gaussian method. EDGE ignores all edges that are not stronger than THRESH. If you do not specify THRESH, or if THRESH is empty ([]), EDGE chooses the value automatically. BW = EDGE(I,'log',THRESH,SIGMA) specifies the Laplacian of Gaussian method, using SIGMA as the standard deviation of the LoG filter. The default SIGMA is 2; the size of the filter is N-by-N, where N=CEIL(SIGMA*3)*2+1. [BW,thresh] = EDGE(I,'log',...) returns the threshold value. Zero-cross Method ----------------- BW = EDGE(I,'zerocross',THRESH,H) specifies the zero-cross method, using the specified filter H. If THRESH is empty ([]), EDGE chooses the sensitivity threshold automatically. [BW,THRESH] = EDGE(I,'zerocross',...) returns the threshold value. Canny Method BW = EDGE(I,'canny') specifies the Canny method. BW = EDGE(I,'canny',THRESH) specifies sensitivity thresholds for the Canny method. THRESH is a two-element vector in which the first element is the low threshold, and the second element is the high threshold. If you specify a scalar for THRESH, this value is used for the high threshold and 0.4*THRESH is used for the low threshold. If you do not specify THRESH, or if THRESH is empty ([]), EDGE chooses low and high values automatically. BW = EDGE(I,'canny',THRESH,SIGMA) specifies the Canny method, using SIGMA as the standard deviation of the Gaussian filter. The default SIGMA is 1; the size of the filter is chosen automatically, based on SIGMA. [BW,thresh] = EDGE(I,'canny',...) returns the threshold values as a two-element vector. 2005 Optomechatronics

LoG ( Laplacian of Gaussian ) edge_LOG.m %LoG BW=edge(I, 'log'); figure; imshow(BW); 2005 Optomechatronics

Hough Transform Using “hough.m” original image parameter space result 2005 Optomechatronics