BlobsDemo

BlobsDemo - Demo to illustrate simple blob detection...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
%------------------------------------------------------------------------------- ----------------- % Demo to illustrate simple blob detection, measurement, and filtering. % Requires the Image Processing Toolbox (IPT) because it demonstates some functions % supplied by that toolbox, plus it uses the "coins" demo image supplied with that toolbox. % If you have the IPT (you can check by typing ver on the command line), you should be able to % run this demo code simply by copying and pasting this code into a new editor window, % and then clicking the green "run" triangle on the toolbar. % Running time = 7.5 seconds the first run and 2.5 seconds on subsequent runs. % A similar Mathworks demo: % http://www.mathworks.com/products/image/demos.html? file=/products/demos/shipping/images/ipexprops.html % Code written and posted by ImageAnalyst, July 2009. %------------------------------------------------------------------------------- ----------------- % function BlobsDemo() % echo on; % Startup code. tic; % Start timer. clc; % Clear command window. clear all; % Get rid of variables from prior run of this m-file. disp('Running BlobsDemo.m. ..'); % Message sent to command window. workspace; % Show panel with all the variables. % Change the current folder to the folder of this m-file. % (The line of code below is from Brett Shoelson of The Mathworks.) if(~isdeployed) cd(fileparts(which(mfilename))); end % Read in standard MATLAB demo image originalImage = imread('coins.png'); subplot(3, 3, 1); imshow(originalImage); % Maximize the figure window. set(gcf, 'Position', get(0, 'ScreenSize')); % Force it to display RIGHT NOW (otherwise it might not display until it's all done, unless you've stopped at a breakpoint.) drawnow; caption = sprintf('Original "coins" image showing\n6 nickels (the larger coins) and 4 dimes (the smaller coins).'); title(caption); axis square; % Make sure image is not artificially stretched because of screen's aspect ratio. % Just for fun, let's get its histogram. [pixelCount grayLevels] = imhist(originalImage); subplot(3, 3, 2); bar(pixelCount); title('Histogram of original image'); xlim([0 grayLevels(end)]); % Scale x axis manually. % Threshold the image to get a binary image (only 0's and 1's) of class "logical." % Method #1: using im2bw() % normalizedThresholdValue = 0.4; % In range 0 to 1. % thresholdValue = normalizedThresholdValue * max(max(originalImage)); % Gray Levels. % binaryImage = im2bw(originalImage, normalizedThresholdValue); % One way to threshold to binary % Method #2: using a logical operation.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
thresholdValue = 100; binaryImage = originalImage > thresholdValue; % Bright objects will be the chosen if you use >. % binaryImage = originalImage < thresholdValue; % Dark objects will be the chosen if you use <. % Do a "hole fill" to get rid of any background pixels inside the blobs.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

BlobsDemo - Demo to illustrate simple blob detection...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online