Image Processing using Matlab

Slides:



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

Digital Image Processing
Introduction to Matlab
Environmental Remote Sensing GEOG 2021 Lecture 2 Image display and enhancement.
Environmental Remote Sensing GEOG 2021
Basis beeldverwerking (8D040) dr. Andrea Fuster dr. Anna Vilanova Prof.dr.ir. Marcel Breeuwer Filtering.
1 ECE 495 – Integrated System Design I Introduction to Image Processing ECE 495, Spring 2013.
Point Processing Histograms. Histogram Equalization Histogram equalization is a powerful point processing enhancement technique that seeks to optimize.
Chapter 15 Complex Numbers
Medical Image Analysis Dr. Mohammad Dawood Department of Computer Science University of Münster Germany.
Computer Vision Lecture 7: The Fourier Transform
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Laboratory of Image Processing Pier Luigi Mazzeo
Image Enhancement in the Frequency Domain (2)
Neighborhood Processing
November 12, 2013Computer Vision Lecture 12: Texture 1Signature Another popular method of representing shape is called the signature. In order to compute.
Image Display MATLAB functions for displaying image Bit Planes
Computational Biology, Part 23 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
Topic 6 - Image Filtering - I DIGITAL IMAGE PROCESSING Course 3624 Department of Physics and Astronomy Professor Bob Warwick.
Image Processing Lecture 4
CS & CS Multimedia Processing Lecture 2. Intensity Transformation and Spatial Filtering Spring 2009.
Transforming images to images
Chapter 3 Image Enhancement in the Spatial Domain.
July 27, 2002 Image Processing for K.R. Precision1 Image Processing Training Lecture 1 by Suthep Madarasmi, Ph.D. Assistant Professor Department of Computer.
Digital Image Processing
Image enhancement in the spatial domain. Human vision for dummies Anatomy and physiology Wavelength Wavelength sensitivity.
Advanced Computer Vision Chapter 3 Image Processing (1) Presented by: 傅楸善 & 張乃婷
Chapter 3: Image Enhancement in the Spatial Domain
Digital Image Processing
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 2. Intensity Transformation and Spatial Filtering
Introduction to Image Processing Grass Sky Tree ? ? Review.
Chapter 2. Image Analysis. Image Analysis Domains Frequency Domain Spatial Domain.
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.
EE663 Image Processing Dr. Samir H. Abdul-Jauwad Electrical Engineering Department King Fahd University of Petroleum & Minerals.
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Chapter 5: Neighborhood Processing
Digital Image Processing (Digitaalinen kuvankäsittely) Exercise 2
Spatial Filtering (Applying filters directly on Image) By Engr. Muhammad Saqib.
COMP322/S2000/L171 Robot Vision System Major Phases in Robot Vision Systems: A. Data (image) acquisition –Illumination, i.e. lighting consideration –Lenses,
Edge Detection and Geometric Primitive Extraction Jinxiang Chai.
Image Transforms Transforming images to images. Classification of Image Transforms Point transforms –modify individual pixels –modify pixels’ locations.
Visual Computing Computer Vision 2 INFO410 & INFO350 S2 2015
CMPS1371 Introduction to Computing for Engineers IMAGES.
Chapter 5: Neighborhood Processing 5.1 Introduction
Image processing using MATLAB
İmage enhancement Prepare image for further processing steps for specific applications.
CS Spring 2010 CS 414 – Multimedia Systems Design Lecture 4 – Audio and Digital Image Representation Klara Nahrstedt Spring 2010.
Machine Vision Edge Detection Techniques ENT 273 Lecture 6 Hema C.R.
Sharpening Spatial Filters ( high pass)  Previously we have looked at smoothing filters which remove fine detail  Sharpening spatial filters seek to.
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
M ATLAB L ECTURE 3 Histogram Processing. H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in.
Image: Susanne Rafelski, Marshall lab Introduction to Digital Image Analysis Part I: Digital Images Kurt Thorn NIC UCSF.
Image Enhancement in the Spatial Domain.
Masaki Hayashi 2015, Autumn Visualization with 3D CG Digital 2D Image Basic.
Computer Application in Engineering Design
Digital 2D Image Basic Masaki Hayashi
Image Enhancement in the
Fourier Transform.
Histogram Histogram is a graph that shows frequency of anything. Histograms usually have bars that represent frequency of occuring of data. Histogram has.
EE/CSE 576 HW 1 Notes.
Lecture 3 (2.5.07) Image Enhancement in Spatial Domain
EE/CSE 576 HW 1 Notes.
Enhancement.
ECE/CSE 576 HW 1 Notes.
Presentation transcript:

Image Processing using Matlab Sumitha Balasuriya http//www.dcs.gla.ac.uk/~sumitha/

Images in Matlab 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

Loading and displaying images >> 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 format as a string Matrix with image data image filename as a string Matlab can only perform arithmetic operations on data with class double! Display the left half of the mandrill image Dimensions of I (red, green and blue intensity information) Image Processing using Matlab Sumitha Balasuriya

Representation of Images 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 Red Images where the pixel value in the image represents the intensity of the pixel are called intensity images. Green Blue Image Processing using Matlab Sumitha Balasuriya

Indexed images 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 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 RGB Entry for index value 3 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. Image Processing using Matlab Sumitha Balasuriya

Displaying indexed images >> I2=I(:,:,2); % green values of I >> image(I2) >> colorbar % display colourmap 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 Image Processing using Matlab Sumitha Balasuriya

Displaying indexed images (continued) Red =1.0, Green = 1.0, Blue =1.0, corresponds to index 64 change colourmap >> colormap(gray) scale colourmap >> imagesc(I2) Red =0.0, Green = 0.0, Blue = 0.0, corresponds to index 1 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 255 Red =0.0, Green = 0.0, Blue = 0.0, corresponds to index 0 Image Processing using Matlab Sumitha Balasuriya

Useful functions for displaying images >> axis image % plot fits to data >> h=axes('position', [0 0 0.5 0.5]); >> axes(h); >> imagesc(I2) Investigate axis and axes functions using Matlab’s help Image Processing using Matlab Sumitha Balasuriya

Histograms 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

Computing histograms of images in Matlab >>hist(reshape(double(Lena(:,:,2)),[512*512 1]),50) Convert image into a 262144 by 1 distribution of values Histogram function Number of bins Generate the histograms of the green channel of the Lena image using the following number of bins : 10, 20, 50, 100, 200, 500, 1000 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. Image Processing using Matlab Sumitha Balasuriya

Visualising the intensity surface >>surf(double(imresize(Lena(:,:,2),[50 50]))) Change type to double precision Remember to reduce size of image! Use Matlab’s built-in mesh and shading surface visualisation functions Image Processing using Matlab Sumitha Balasuriya

Useful functions for manipulating images 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

Other useful functions Convert polar coordinates to cartesian coordinates >>pol2cart(rho,theta) Check if a variable is null >>isempty(I) Trigonometric functions sin, cos, tan >>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) Image Processing using Matlab Sumitha Balasuriya

Support region of filter where g(x-r) is nonzero Convolution Bit of theory! Convolution of two functions f(x) and g(x) Discrete image processing 2D form Support region of filter where g(x-r) is nonzero Image convolution operator Filter (mask/kernel) Output filtered image Compute the convolution where there are valid indices in the kernel Image Processing using Matlab Sumitha Balasuriya

Convolution example  = Image (I) Filter (M) j i 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. http://www.s2.chalmers.se/undergraduate/courses0203/ess060/PDFdocuments/ForScreen/Notes/Convolution.pdf Image Processing using Matlab Sumitha Balasuriya

Convolution example in 1D Horizontal slice from Mandrill image Filtered Signal 1D Gaussian filter  = Image Processing using Matlab Sumitha Balasuriya

Common convolution kernels Arithmetic mean filter (smoothing) >>fspecial('average') Gaussian filter (smoothing) >>fspecial('gaussian') Laplacian (enhance edges) >>fspecial('laplacian') Sharpening filter >>fspecial('unsharp') 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. 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). Image Processing using Matlab Sumitha Balasuriya

Useful functions for convolution 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 kernel Border padding options Perform the convolution of an image using Gaussian kernels with different sizes and standard deviations and display the output images. Image Processing using Matlab Sumitha Balasuriya

Tutorial 2 Image Processing using Matlab Sumitha Balasuriya 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 Type the code in this handout in Matlab and investigate the results. Do the exercises in the notes. 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) 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) Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Image Processing using Matlab Sumitha Balasuriya