Improve edge detection of image
Show older comments
i need function or code in matlab to Improve and edge detection this image
2 Comments
Image Analyst
on 31 Oct 2014
What do you need to find? The outline of the whole foot, or the small fine lines and wrinkles within the foot.
per isakson
on 31 Oct 2014
It's not a good idea to call many questions "welcome please help me". I renamed this one.
Answers (1)
Image Analyst
on 31 Oct 2014
Didn't hear from you so I just guessed.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
%===============================================================================
% Read in a standard MATLAB color demo image.
folder = 'C:\Users\fatima\Documents\Temporary';
baseFileName = 'foot.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% 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.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
binaryImage = blueChannel < 118;
% Display the original color image.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Initial Binary Image', 'FontSize', fontSize);
% Clean it up.
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Get rid of small blobs.
binaryImage = bwareaopen(binaryImage, 10000);
% Smooth border
binaryImage = imclose(binaryImage, true(5));
% Display the original color image.
subplot(2, 2, 3);
imshow(binaryImage);
axis on;
title('Cleaned Binary Image', 'FontSize', fontSize);
% Get the boundary and outline it over the original image.
boundaries = bwboundaries(binaryImage);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
% Display the original color image.
subplot(2, 2, 4);
imshow(rgbImage);
title('Outline over Original Color Image', 'FontSize', fontSize);
% Plot boundaries over it.
hold on;
plot(x, y, 'g-', 'LineWidth', 2);

14 Comments
fatima ali
on 31 Oct 2014
Image Analyst
on 31 Oct 2014
You can use rgb2gray to convert to grayscale, but you'd probably be better off using the blue channel which will have higher contrast
grayImage = rgbImage(:, :, 3); % Extract blue channel.
OK, next you say "i need to ... improve". Here are links for improving your matlab skills: http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
Next you say "i need ... edge detection". Well if you didn't like what I did for you, and want something like the two images you showed, then play around with various arguments of the edge() function.
Good luck.
fatima ali
on 1 Nov 2014
Edited: fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
Which image do you want to improve - the original RGB image, or the edge detection image? And what would improvement look like to you? Like having a black background on the RGB image instead of white? Like not having broken or small segments on the edge image? You need to say which image needs improvement and what it would look like . Then we can try to figure out a way to get there.
fatima ali
on 1 Nov 2014
Edited: fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
Try changing the parameters or use different edge detection methods like Sobel, Canny, etc. Keep trying until you get something closer. Don't just assume you have to start with that bad image on top. Adjust parameters then there will be less to fix up to get to the bottom image. Is there any particular reason that you didn't like the method I originally suggested? It looked pretty good to me. Please explain why it is unacceptable.
fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
Again, why did you not like my method?
fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
The 71 lines of code in my initial answer. Just scroll up to see it. There is also a screenshot of 4 images with the final outline in green. You can hardly miss it.
fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
That is simple. Notice that virtually every line has a comment explaining what it does. Not every image processing application can be done in 2 or 3 lines. Don't be scared - mostly it's slightly long because of comments and fancy display stuff. I'm sure that you, as a smart engineer, can understand it completely if you just go down line by line and read the comments. If any line is confusing or not explained by a comment let me know or look up the function in the help.
fatima ali
on 1 Nov 2014
Image Analyst
on 1 Nov 2014
Your edge detection images were binary images. Why is it okay for you to use a binary image to get the outline but I can't? Anyway, who cares if there's a binary image involved as long as you get the outline you want? What difference does it make? It works and that's all that counts.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


