MATLAB® Image Processing Toolbox Rahman Tashakkori, Appalachian Sue Lea, UNCG "A Consortium to Promote Computational Science and High Performance Computing" Workshop – July 26-28, 2004
Image Processing Toolbox The Image Processing Toolbox is a collection of functions that support a wide range of image processing operations, including: Spatial image transformations Morphological operations Neighborhood and block operations Linear filtering and filter design Transforms Image analysis and enhancement Image registration Deblurring Region of interest operations
Reading and displaying images The MATLAB imread allows reading images in several different formats: I = imread(‘filename.ext'); Where the “.ext” refers to the extension for possible formats. Here is the list: bmp, cur, gif, hdf, ico, jpg, jpeg, pbm, pcx, pgm, png, pnm, ppm, ras, tif, tiff, and xwd To display an image we will use imshow(I) The imview function displays an image in a separate Java-based window called the Image Viewer, which provides access to additional tools that aid in navigating around an image, especially large images, and enable the inspection of pixels in an image. More information on supported formats: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/imread.html#713744
Image Types The Image Processing Toolbox supports four basic types of images: Indexed images Intensity images Binary images RGB images Reading and Writing Image Data Reading a Graphics Image Writing a Graphics Image Querying a Graphics File Converting Image Storage Classes Converting Graphics File Formats Reading and Writing DICOM Files
Example: I = imread('pout.tif'); Imshow(I); Produces:
Reading and displaying images You can also get information about variables in the workspace by calling the whos command. whos Name Size Bytes Class I 291x240 69840 uint8 array Grand total is 69840 elements using 69840 bytes To write an image to a disk file, use the imwrite function. If you include the filename extension '.png', the imwrite function writes the image to a file in Portable Network Graphics (PNG) format, but you can specify other formats. imwrite (I2, 'pout2.png'); imwrite(A,filename,fmt) imwrite(X,map,filename,fmt) imwrite(...,filename) imwrite(...,Param1,Val1,Param2,Val2...)
Coordinate Systems Pixel Coordinates Spatial Coordinates
Storage Classes By default, MATLAB stores most data in arrays of class double. The data in these arrays is stored as double-precision (64-bit) floating-point numbers. All MATLAB functions work with these arrays. For image processing, however, this data representation is not always ideal. The number of pixels in an image can be very large; for example, a 1000-by-1000 image has a million pixels. Since each pixel is represented by at least one array element, this image would require about 8 megabytes of memory. To reduce memory requirements, MATLAB supports storing image data in arrays as 8-bit or 16-bit unsigned integers, class uint8 and uint16. These arrays require one eighth or one fourth as much memory as double arrays.
Histogram Equalization As you can see, pout.tif is a somewhat low contrast image. To see the distribution of intensities in pout.tif, we can create a histogram by calling the imhist function imadjdemo
Create a Binary Version of the Image Create a binary version of the image by using thresholding. The function graythresh automatically computes an appropriate threshold to use to convert the intensity image to binary. The im2bw function performs the conversion. level = graythresh(I); bw = im2bw(I,level); imshow(bw)
Determine the Number of Objects in the Image After converting the image to a binary image, we can use the bwlabel function to determine the number of objects in the image. The bwlabel function labels all the components in the binary image bw and returns the number of components it finds in the image in the output value, numObjects. [labeled,numObjects] = bwlabel(bw,4); numObjects ans = 101 The accuracy of the results depends on a number of factors, including The size of the objects Whether or not any objects are touching (in which case they might be labeled as one object) The accuracy of the approximated background The connectivity selected. The parameter 4, passed to the bwlabel function, means that pixels must touch along an edge to be considered connected. In our case: [labeled,numObjects] = bwlabel(bw,4); produces 48
% Image Processing Toolbox --- demos and sample images % dctdemo - 2-D DCT image compression demo. % edgedemo - Edge detection demo. % firdemo - 2-D FIR filtering and filter design demo. % imadjdemo - Intensity adjustment and histogram equalization demo. % landsatdemo - Landsat color composite demo. % nrfiltdemo - Noise reduction filtering demo. % qtdemo - Quadtree decomposition demo. % roidemo - Region-of-interest processing demo. % Extended-examples. % ipexindex - Index of extended examples. % ipexsegmicro - Segmentation to detect microstructures. % ipexsegcell - Segmentation to detect cells. % ipexsegwatershed - Watershed segmentation. % ipexgranulometry - Granulometry of stars. % ipexdeconvwnr - Wiener deblurring. % ipexdeconvreg - Regularized deblurring. % ipexdeconvlucy - Lucy-Richardson deblurring. % ipexdeconvblind - Blind deblurring. % ipextform - Image transform gallery. % ipexshear - Image padding and shearing. % ipexmri - 3-D MRI slices. % ipexconformal - Conformal mapping. % ipexnormxcorr2 - Normalized cross-correlation. % ipexrotate - Rotation and scale recovery. % ipexregaerial - Aerial photo registration.
% Image Processing Toolbox --- demos and sample images % Extended-example helper M-files. % ipex001 - Used by image padding and shearing example. % ipex002 - Used by image padding and shearing example. % ipex003 - Used by MRI slicing example. % ipex004 - Used by conformal mapping example. % ipex005 - Used by conformal mapping example. % ipex006 - Used by conformal mapping example.
Terminology Interpolation Interpolation Methods Image Types Spatial Transformations Terminology Interpolation Interpolation Methods Image Types
Other Spatial Transformations Image Resizing Specifying the Size of the Output Image Specifying the Interpolation Method Using Filters to Prevent Aliasing Image Rotation Specifying the Interpolation Method Specifying the Size of the Output Image Image Cropping Performing General Spatial Transformations Specifying the Transformation Type Performing the Transformation Advanced Spatial Transformation Techniques
Image Registration Terminology Registering an Image Point Mapping Example: Registering to a Digital Orthophoto Types of Supported Transformations Selecting Control Points Using the Control Point Selection Tool Starting the Control Point Selection Tool Viewing the Images Specifying Matching Control Point Pairs Saving Control Points
Linear Filtering and Filter Design Terminology Linear Filtering Convolution Correlation Filtering Using imfilter Using Predefined Filter Types Filter Design FIR Filters Frequency Transformation Method Frequency Sampling Method Windowing Method Creating the Desired Frequency Response Matrix Computing the Frequency Response of a Filter
Transforms Terminology Fourier Transform Definition of Fourier Transform Discrete Fourier Transform Applications of the Fourier Transform Discrete Cosine Transform The DCT Transform Matrix DCT and Image Compression Radon Transform Plotting the Radon Transform Viewing the Radon Transform as an Image Using the Radon Transform to Detect Lines Inverse Radon Transform Example: Reconstructing an Image from Parallel Projection Data Fan-Beam Projection Data Computing Fan-Beam Projection Data Reconstructing an Image from Fan-Beam Projection Data Working with Fan-Beam Projection Data
Morphological Operations Terminology Dilation and Erosion Understanding Dilation and Erosion Structuring Elements Dilating an Image Eroding an Image Combining Dilation and Erosion Dilation- and Erosion-Based Functions Morphological Reconstruction Marker and Mask Pixel Connectivity Flood-Fill Operations Finding Peaks and Valleys Distance Transform Objects, Regions, and Feature Measurement Connected-Component Labeling Selecting Objects in a Binary Image Finding the Area of the Foreground of a Binary Image Finding the Euler Number of a Binary Image Lookup Table Operations
Analyzing and Enhancing Images Terminology Pixel Values and Statistics Pixel Selection Intensity Profile Image Contours Image Histogram Summary Statistics Region Property Measurement Image Analysis Edge Detection Boundary Tracing Quadtree Decomposition Intensity Adjustment Adjusting Intensity Values to a Specified Range Histogram Equalization Contrast-Limited Adaptive Histogram Equalization Decorrelation Stretching Noise Removal Using Linear Filtering Using Median Filtering Using Adaptive Filtering
Region-Based Processing Terminology Specifying a Region of Interest Selecting a Polygon Other Selection Methods Filtering a Region Example: Filtering a Region in an Image Specifying the Filtering Operation Filling a Region
Image Debluring Terminology Understanding Deblurring Causes of Blurring Deblurring Model Using the Deblurring Functions Deblurring with the Wiener Filter Deblurring with a Regularized Filter Deblurring with the Lucy-Richardson Algorithm Deblurring with the Blind Deconvolution Algorithm Creating Your Own Deblurring Functions Avoiding Ringing in Deblurred Images
Color Terminology Working with Different Screen Bit Depths Determining Screen Bit Depth Choosing a Screen Bit Depth Reducing the Number of Colors in an Image Using rgb2ind Reducing Colors in an Indexed Image Dithering Converting Color Data Between Color Spaces Converting Between Device-Independent Color Spaces Performing Profile-Based Conversions Converting Between Device-Dependent Color Spaces
Wavelet Analysis – Wavelet Toolbox Wavelet analysis has become very popular in image processing. The main idea is to break an image into sub-bands in different frequency and time domain. MATLAB provides an excellent toolbox for performing wavelet analysis on both one- and two-dimensional data. Demo:
.m files – Example Hotelling Transform Allows us to create a .m file that contains all the commands we wish to run at once. Then by typing the file name, we can run those commands. Let’s look at one example. C:\course\ImgProcessing\hotelling