Edge detection: image to grayscale

12 views (last 30 days)
Peter
Peter on 26 Aug 2014
Commented: Image Analyst on 26 Aug 2014
What is the proper procedure for implementing edge detection (edge.m) on an image file (*.bmp, *.png, *.jpg)? My efforts thus far have not yielded results. I am using R2013a on Windows 7.
The appropriate method for using edge detection appears to be to convert the RGB (3D) image into grayscale and then run edge.m on the converted image. If this does not happen, an error is produced (i.e., attempt edge detection on the original file):
Error using edge
Expected input number 1, I, to be
two-dimensional.
So, considering the following code, for example:
Irgb = imread('input.bmp');
%Irgb = imread('input.png');
%Irgb = imread('input.jpg');
figure;
image(Irgb);
axis equal;
Igray = rgb2gray(Irgb);
figure;
image(Igray);
axis equal;
Iedge = edge(Igray, 'canny');
figure;
image(Iedge);
axis equal;
The input files are in three formats, and each produces poor results. It does not appear to be converting the image files correctly into grayscale. The output after conversion to grayscale for each of these formats is also attached.
Any help or direction would be appreciated. Thank you.

Answers (1)

Image Analyst
Image Analyst on 26 Aug 2014
I know I've seen these images before - perhaps a classmate of yours? Like I told them, you don't need edge detection if you want measurements like area, perimeter, etc. But, yes, edge detection needs a grayscale image usually, though I do have one that looks at the delta E (color difference) if anyone is interested. Anyway, I don't know what results you think would be "not poor" so I can't advise you further until I know what you're expecting.
  2 Comments
Peter
Peter on 26 Aug 2014
Image Analyst,
Apologies, but I created those images 2 hours ago in Inkscape while doing other tasks as a busy post-doctoral researcher unfamiliar with image processing and struggling to connect the dots for such purposes in MATLAB. Please, can we avoid unprofessionalism?
My images were not properly converted to grayscale, and were not then further "edge detected." Please see the output images.
If you have any advice on why this is the case, I would appreciate your kind response. Thank you.
Image Analyst
Image Analyst on 26 Aug 2014
I don't know Inkscape, or if it's professional or unprofessional. I use Photoshop. Again, I don't know what the desired output is. Do you want to find each solid shape? Do you want the outlines of each shape? Do you want the outlines of the union or intersection of each shape? Do you want a gray scale version of your color image? Each of your shapes is outlined in another shape - a thin band of contrasting color. How is that supposed to be handled? As a separate shape because it's a different color? Or just ignored? Please clarify.
Can you use Inkscape, Photoshop, or Gimp to mock up something that would be exactly what you hope to get?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!