16 views

Uploaded by Akash Deep

- COGENT Toolbox Manual v125
- MATLAB
- MATLAB Primer
- Simulink Tutorial
- Matblaid
- Matlab Part1 Getting Started
- Matlab Tutorial
- Introduction to MatLab
- UCLA Graduate Portfolio 2012
- ELEC483 6061 Outline Winter 2015
- matlab dasi
- 2016-Scientific Computing With MATLAB-Paul Gribble-Math Eng Chap01
- Ch 2 Getting Started With MATLAB
- Mat Lab Plotting 2
- Python for Scientists and Engineers-Description
- T55.04
- Control Tutorials for MATLAB and Simulink - MATLAB Basics Tutorial
- Introduction to DSP simulations in MATLAB.pdf
- Lab01 Get Start Simulink
- Compression is Tough on All Sharp Edges in the Image

You are on page 1of 15

The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB numeric computing environment. The toolbox supports 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

Many of the toolbox functions are MATLAB M-files, a series of MATLAB statements that implement specialized image processing algorithms. You can view the MATLAB code for these functions using the statement

type function_name

You can extend the capabilities of the Image Processing Toolbox by writing your own M-files, or by using the toolbox in combination with other toolboxes, such as the Signal Processing Toolbox and the Wavelet Toolbox.

Clear the MATLAB workspace of any variables and close open figure windows.

clear, close all

To read an image, use the imread command. Let's read in a TIFF image named pout.tif (which is one of the sample images that is supplied with the Image Processing Toolbox), and store it in an array named I.

I=imread('pout.tif');

imshow(I)

Enter the whos command to see how I is stored in memory.

whos

Name I Size 291x240 Bytes 69840 Class uint8 array

As you can see, pout.tif is a somewhat low contrast image. To see the distribution of intensities in pout.tif in its current state, you can create a histogram by calling the imhist function. (Precede the

call to imhist with the figure command so that the histogram does not overwrite the display of the image I in the current figure window.)

figure, imhist(I) % Display a histogram of I in a new figure.

Notice how the intensity range is rather narrow. It does not cover the potential range of [0, 255], and is missing the high and low values that would result in good contrast. Now call histeq to spread the intensity values over the full range, thereby improving the contrast of I. Return the modified image in the variable I2.

I2 = histeq(I); % Equalize I and output in new array I2.

figure, imshow(I2) % Display the new equalized image I2.

figure, imhist(I2) % Show the histogram for the new image I2.

See how the pixel values now extend across the full range of possible values.

Write the newly adjusted image I2 back to disk. Let's say you'd like to save it as a PNG file. Use imwrite and specify a filename that includes the extension 'png'.

imwrite (I2, 'pout2.png');

Now, use the imfinfo function to see what was written to disk. Be sure not to end the line with a semicolon so that MATLAB displays the results. Also, be sure to use the same path (if any) as you did for the call to imwrite, above.

imfinfo('pout2.png')

Filename: FileModDate: FileSize: Format: 'pout2.png' '03-Jun-1999 15:50:25' 36938 'png' ans =

Clear the MATLAB workspace of any variables and close open figure windows. Read and display the intensity image rice.tif.

clear, close all

I = imread('rice.tif'); imshow(I)

Notice that the background illumination is brighter in the center of the image than at the bottom. Use the imopen function to estimate the background illumination.

background = imopen(I,strel('disk',15));

imshow(background)

Use the surf command to create a surface display of the background approximation, background. The surf function requires data of class double, however, so you first need to convert background using the double command.

figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]); set(gca,'ydir','reverse');

The example uses MATLAB indexing syntax to view only 1 out of 8 pixels in each direction; otherwise the surface plot would be too dense. The example also sets the scale of the plot to better match the range of the uint8 data and reverses the y-axis of the display to provide a better view of the data (the pixels at the bottom of the image appear at the front of the surface plot).

Now subtract the background image, background, from the original image, I, to create a more uniform background.

I2 = imsubtract(I,background);

figure, imshow(I2)

The image is now a bit too dark. Use imadjust to adjust the contrast.

I3 = imadjust(I2, stretchlim(I2), [0 1]);

figure, imshow(I3);

Create a new binary thresholded image, bw, by using the functions graythresh and im2bw.

level = graythresh(I3); bw = im2bw(I3,level); figure, imshow(bw)

Now call the whos command to see what type of array the thresholded image bw is.

whos

Name I I2 I3 background bw level Size 256x256 256x256 256x256 256x256 256x256 1x1 Bytes 65536 65536 65536 65536 65536 8 Class uint8 array uint8 array uint8 array uint8 array logical array double array

To determine the number of grains of rice in the image, use the bwlabel function. This function labels all of the connected components in the binary image bw and returns the number of objects it finds in the image in the output value, numobjects.

[labeled,numObjects] = bwlabel(bw,4);% Label components. numObjects = 80

The size of the objects The accuracy of your approximated background Whether you set the connectivity parameter to 4 or 8 Whether or not any objects are touching (in which case they may be labeled as one object) In the example, some grains of rice are touching, so bwlabel treats them as one object.

You may find it helpful to take a closer look at labeled to see what bwlabel has created. Use the imcrop command to select and display pixels in a region of labeled that includes an object and some background. To ensure that the output is displayed in the MATLAB window, do not end the line with a semicolon. In addition, choose a small rectangle for this exercise, so that the displayed pixel values don't wrap in the MATLAB command window. The syntax shown below makes imcrop work interactively. Your mouse cursor becomes a cross-hair when placed over the image. Click at a position in labeled where you would like to select the upper left corner of a region. Drag the mouse to create the selection rectangle, and release the button when you are done.

grain = imcrop(labeled) % Crop a portion of labeled.

We chose the left edge of a grain and got the following results.

grain = 0 0 0 0 0 0 0 60 60

0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0

0 60 60 60 60 60 0 0 0

0 60 60 60 60 60 0 0 0

60 60 60 60 60 60 60 0 0

60 60 60 60 60 60 60 0 0

60 60 60 60 60 60 60 0 0

60 60 60 60 60 60 60 0 0

A good way to view a label matrix is to display it as a pseudo-color indexed image. In the pseudo-color image, the number that identifies each object in the label matrix maps to a different color in the associated colormap matrix. When you view a label matrix as an RGB image, the objects in the image are easier to distinguish. To view a label matrix in this way, use the label2rgb function. Using this function, you can specify the colormap, the background color, and how objects in the label matrix map to colors in the colormap.

RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle'); imshow(RGB_label);

The regionprops command measures object or region properties in an image and returns them in a structure array. When applied to an image with labeled components, it creates one structure element for each component. Use regionprops to create a structure array containing some basic properties for labeled.

graindata = regionprops(labeled,'basic')

graindata = 80x1 struct array with fields: Area Centroid BoundingBox

To find the area of the component labeled with 51's, use dot notation to access the Area field in the 51st element in the graindata structure array. Note that structure field names are case sensitive, so you need to capitalize the name as shown.

graindata(51).Area

ans = 296

To find the smallest possible bounding box and the centroid (center of mass) for the same component, use this code:

graindata(51).BoundingBox, graindata(51).Centroid ans = 142.5000 ans = 155.3953 89.5000 24.0000 26.0000

102.1791

To create a new vector, allgrains, which holds just the area measurement for each grain, use this code:

allgrains = [graindata.Area]; whos allgrains

Call the whos command to see how MATLAB allocated the allgrains variable.

Name Size Bytes Class

allgrains

1x80

640

double array

is a one-row array of 80 elements, where each element contains the area measurement of a grain. Check the area of the 51st element of allgrains.

allgrains allgrains(51)

returns

ans = 296

Now use MATLAB functions to calculate some statistical properties of the thresholded objects. First use max to find the size of the largest grain. (If you have followed all of the steps in this exercise, the "largest grain" is actually two grains that are touching and have been labeled as one object).

max(allgrains)

returns

ans = 695

Use the find command to return the component label of this large-sized grain.

biggrain = find(allgrains==695)

returns

biggrain =

68

mean(allgrains)

returns

ans = 249

Make a histogram containing 20 bins that show the distribution of rice grain sizes.

hist(allgrains,20)

References:

www.mathworks.com/products/image/ www.mathtools.net/MATLAB/Image_Processing/ www.amath.colorado.edu/courses/4720/2000Spr/Labs/Worksheets/Matlab_tutorial/matlabimpr.html www.imageprocessingplace.com/DIPUM/dipum_book_description/book_description.htm

- COGENT Toolbox Manual v125Uploaded byLlassimo
- MATLABUploaded byTan Cheehou
- MATLAB PrimerUploaded bystreetcribdealer
- Simulink TutorialUploaded bysivakkumar14
- MatblaidUploaded bySunny Brown
- Matlab Part1 Getting StartedUploaded byreza rahmad
- Matlab TutorialUploaded byKhaled Ismaiil
- Introduction to MatLabUploaded byibrahimsadek87
- UCLA Graduate Portfolio 2012Uploaded byasasdfasdfasfasdfasdfasdfasdfasdfasdfasdfsadfasdfsadfasdfasdfasdfasdf
- ELEC483 6061 Outline Winter 2015Uploaded byPhil
- matlab dasiUploaded byRaymond Wade
- 2016-Scientific Computing With MATLAB-Paul Gribble-Math Eng Chap01Uploaded byhieuhuech
- Ch 2 Getting Started With MATLABUploaded by김상권
- Mat Lab Plotting 2Uploaded bySathish Selvamani
- Python for Scientists and Engineers-DescriptionUploaded byRKKhatri
- T55.04Uploaded bynayabhamirani
- Control Tutorials for MATLAB and Simulink - MATLAB Basics TutorialUploaded byMohammed
- Introduction to DSP simulations in MATLAB.pdfUploaded byZARGHAM KHAN
- Lab01 Get Start SimulinkUploaded bySpin Fotonio
- Compression is Tough on All Sharp Edges in the ImageUploaded byJoshua Reed
- Fianl Matlab File.docgggUploaded byGurpreet Singh
- DIP LAB 2Uploaded byZeeshan Khalid
- Lecture 2, Bahman MoraffahUploaded byElham
- Matlab TutorialUploaded bymuhammadnaumair
- Assignment 1Uploaded byViralBipinchandraRathod
- Critical speed of shaft_Program C code.pdfUploaded bykiran2381
- vv advertising package web versionUploaded byapi-238476909
- Image FilesUploaded byanon-516746
- Mat PowerUploaded byJavier Pancho Bautista Garcia
- Mex HelpUploaded byRamón Mireles

- WIRE SHARK User Guide a4Uploaded byJuan_Manuel_Te_6091
- Big-Oh NotationUploaded byvijayakumarvarma
- 26709_b Protech Gii ImUploaded bymetalshock
- Based AAA Subsystem.pdfUploaded bybehzad
- Chapter_4Uploaded byPeilin Tee
- Boss BR-1600 Turbo StartUploaded byetg4
- ADDMATH FORM 4Uploaded byNor Hanina
- Chapter_20_Final.pdfUploaded bypatelssp
- Accenture Test 4Uploaded byVeeraragavan Subramaniam
- Options and PacksUploaded bywilly321
- How to setup VMware vSphere Lab in VMwareUploaded byStefanus E Prasst
- TkexamplUploaded bySandeep Kumar Pradhan
- 4 GUploaded bySruthi Honey
- chp 2 tetsUploaded byBen Juin
- “Missing Mass” in Dynamic Analysis - Structural Analysis and Design Wiki - Structural Analysis and Design - Be Communities by Bentley.pdfUploaded bychondroc11
- MT6582 Android Scatter EmmcUploaded byManil Kumar
- Interview FaqsUploaded byKumar Perabattula
- Generation of MIS Report Using Data WarehouseUploaded byEditor IJRITCC
- OpenSAP Lum1 Week 2 Unit 1 Create Stories PresentationUploaded bymaroof khatib
- ICS Lecture 1Uploaded bydoğancan
- 85446716 Customer Preparation Guide to iManager M2000 and PRS NASTAR VNP Installation 20110425 B 5 24Uploaded bymushtaqkhawar
- 1HDLC ControllerUploaded byHardik Trivedi
- Onkyo HT-R940 ManualUploaded byreez123
- Installation Guide - WT210 WiHART Sensor r1Uploaded bysarkaft
- uefi bootableUploaded byAnonymous lt2LFZH
- Replacing Wall Warts With PC Power Supplies _ the Silicon UndergroundUploaded byPaul D Carrier
- The Jeppesen FSUploaded byflakiten
- Number_03_LX_Service_ManualUploaded byAlex Cantrell
- International Congress on Database System 2014 CFPUploaded byadminasdf
- TM502 User GuideUploaded byMiles Lewitt