EDGE function ERROR

44 Ansichten (letzte 30 Tage)
Eulises Ulloa
Eulises Ulloa am 17 Nov. 2011
I'm trying to perform the following operation
%Load the image into matlab
A = imread('before3.jpg');
%Show the image
I = edge(A, 'sobel');
Using this high pass filter I expect to find the edges of my image but I get the following error while using the edge function.
??? Function EDGE expected its first input, I, to be two-dimensional.
Error in ==> edge>parse_inputs at 564
Error in ==> edge at 197
[a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(varargin{:});
Error in ==> image1 at 21
I = edge(A,'sobel');
The image 'before3.jpg' has value
<1728x2304x3 uint8>
The error says to use a 2 dimensional input but I have not been able to find a way to change my image to a 2 dimensional matrix and keep at the same time the original edges.
I tried
[X, map] = rgb2ind(A,256);
I used as the map a 'gray' scale but it did not work.
Please if you have a different approach that you can recommend me I will be very grateful.

Antworten (7)

JOEL am 1 Okt. 2014
Bearbeitet: DGM am 11 Feb. 2023
%para leer una imagen
I = imread('casa.jpg');
%% convertir a escalas grises
%hallando contorno
BW = edge(I);
%mostrando contorno
Joel Villavicencio
  3 Kommentare
Muddasar Khan
Muddasar Khan am 19 Feb. 2018
Yes, You are right. We should convert colored image to gray image then edges should be detected
princess sofiya
princess sofiya am 12 Apr. 2020
thanks too.

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 17 Nov. 2011
rgb2gray() rather than rgb2ind()

Jan am 17 Nov. 2011
In the help text of edge I find:
W = edge(I) takes a grayscale or a binary image I as its input...
I'd expect rgb2gray to perform a proper conversion.

Alex am 17 Nov. 2011
according to the documentation, using imread with a jpeg object results in RGB scale. As in, each pixel is represented by a 3 element vector ['red value' 'green value' 'blue value'];
  1 Kommentar
Walter Roberson
Walter Roberson am 19 Feb. 2018
Not universally true. There are true grayscale jpeg images. But I have only ever encountered one, apart from test images to prove that they exist. Jpeg is nearly always rgb. Never pseudocolor though.

Melden Sie sich an, um zu kommentieren.

Eulises Ulloa
Eulises Ulloa am 17 Nov. 2011
Thank you guys, that really helped.
However, using the edge function after converting my image to gray scale does not give good result in my case. I have seem some examples on the web and even on the documentation of the function in where they use the edge function right after "imread". I always get the needs 2 dimensional input error. Can you tell me if you know other approach for finding the edges of a image.
e.g I would like to perform the edge detection operation on the original image.
  3 Kommentare
Jan am 17 Nov. 2011
If you want to use the edge-detection on an RGB image, you cannot use the EDGE function. There are a lot of edge-detection methods in the FEX: http://www.mathworks.com/matlabcentral/fileexchange/?term=edge
There are other methods to convert the image to gray-scale also. Consider to sharpen the edges in the HSV color-space at first.
Eulises Ulloa
Eulises Ulloa am 17 Nov. 2011

Melden Sie sich an, um zu kommentieren.

Priscil23 am 15 Feb. 2018
Just as everyone said, first convert your rgb2gray then to view the output after your desired edge functions use imshow to view the image. I faced the same problem.

priyanka nale
priyanka nale am 30 Dez. 2019
close all;
clear ;
c= edge(I,'sobel');

Community Treasure Hunt

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

Start Hunting!

Translated by