MATLAB Answers


1 view (last 30 days)
tarun on 9 May 2013
Commented: Image Analyst on 14 May 2016
I have to write a matlab code to implement the above edge detection scheme.
Can someone please give me an idea how to start coding it? how should I proceed ?
Below is the brief theory.
Localization of edges is done by this method. The concept behind it is to threshold a gray level image using local mean to make a binary image. It recognizes nearly all-actual edges and edges due to noise. To remove noise edges another approach is used.
I would appreciate any help.

Accepted Answer

Image Analyst
Image Analyst on 9 May 2013
See my demo. Feel free to adapt it as needed.
close all;
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
baseFileName = 'pout.tif';
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Get the local mean and subtract the original from it
% This is the Laplacian
edgeImage = conv2(double(grayImage), [-1, -1, -1; -1, 8, -1; -1, -1, -1]/8, 'same');
% Display the image.
subplot(2, 2, 2);
imshow(edgeImage, []);
title('Edge Image', 'FontSize', fontSize);
% Let's compute and display the histogram.
[pixelCount, grayLevels] = hist(edgeImage(:), 100);
subplot(2, 2, 3);
bar(grayLevels, pixelCount);
grid on;
title('Histogram of edge image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Threshold the image.
binaryImage = edgeImage > 10;
% Display the image.
subplot(2, 2, 4);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
Image Analyst
Image Analyst on 14 May 2016
hani, you'd have to create a feature vector consisting of things like the color, mean texture, circularity, area, etc. Then you could use a classifier like treebagger to determine the coin, or just do it manually with a bunch of if/else statements.
Or maybe you could use the cascade detector in the Computer Vision System Toolbox.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!