Intermediate result using edge(canny).

1 次查看(过去 30 天)
Matlab Version : 7.8.0(R2009a)
I am getting edges from an image by using Canny edge detector using standard 'edge' function. But for my project I need to get intermediate Gradient Magnitude matrix. I.e. gradient magnitude values for each pixel.
I know we could do it manually, But I don't know the implementation used by Matlab for Canny. I need the exact values computed by edge function. Is there any way to do it or do I have to implement canny from scratch?
Background: I am basically changing Gray scale values for some pixels on the edge detected by canny. I need to know that after the change will they still come under Threshold values
  1 个评论
mangat rai
mangat rai 2012-9-27
By the way found the answer. We can access and edit Edge function by following command in work space.
edit edge

请先登录,再进行评论。

回答(2 个)

Kapil Nagwanshi
Kapil Nagwanshi 2012-9-27
if you tpe the help it will show following I think it is much better
EDGE Find edges in intensity image. EDGE takes an intensity or a binary image I as its input, and returns a binary image BW of the same size as I, with 1's where the function finds edges in I and 0's elsewhere.
EDGE supports six different edge-finding methods:
The Sobel method finds edges using the Sobel approximation to the
derivative. It returns edges at those points where the gradient of
I is maximum.
The Prewitt method finds edges using the Prewitt approximation to
the derivative. It returns edges at those points where the gradient
of I is maximum.
The Roberts method finds edges using the Roberts approximation to
the derivative. It returns edges at those points where the gradient
of I is maximum.
The Laplacian of Gaussian method finds edges by looking for zero
crossings after filtering I with a Laplacian of Gaussian filter.
The zero-cross method finds edges by looking for zero crossings
after filtering I with a filter you specify.
The Canny method finds edges by looking for local maxima of the
gradient of I. The gradient is calculated using the derivative of a
Gaussian filter. The method uses two thresholds, to detect strong
and weak edges, and includes the weak edges in the output only if
they are connected to strong edges. This method is therefore less
likely than the others to be "fooled" by noise, and more likely to
detect true weak edges.
The parameters you can supply differ depending on the method you
specify. If you do not specify a method, EDGE uses the Sobel method.
Sobel Method
------------
BW = EDGE(I,'sobel') specifies the Sobel method.
BW = EDGE(I,'sobel',THRESH) specifies the sensitivity threshold for
the Sobel method. EDGE ignores all edges that are not stronger than
THRESH. If you do not specify THRESH, or if THRESH is empty ([]),
EDGE chooses the value automatically.
BW = EDGE(I,'sobel',THRESH,DIRECTION) specifies directionality for the
Sobel method. DIRECTION is a string specifying whether to look for
'horizontal' or 'vertical' edges, or 'both' (the default).
BW = EDGE(I,'sobel',...,OPTIONS) provides an optional string
input. String 'nothinning' speeds up the operation of the algorithm by
skipping the additional edge thinning stage. By default, or when
'thinning' string is specified, the algorithm applies edge thinning.
[BW,thresh] = EDGE(I,'sobel',...) returns the threshold value.
[BW,thresh,gv,gh] = EDGE(I,'sobel',...) returns vertical and
horizontal edge responses to Sobel gradient operators. You can
also use these expressions to obtain gradient responses:
if ~(isa(I,'double') || isa(I,'single')); I = im2single(I); end
gh = imfilter(I,fspecial('sobel') /8,'replicate'); and
gv = imfilter(I,fspecial('sobel')'/8,'replicate');
Prewitt Method
--------------
BW = EDGE(I,'prewitt') specifies the Prewitt method.
BW = EDGE(I,'prewitt',THRESH) specifies the sensitivity threshold for
the Prewitt method. EDGE ignores all edges that are not stronger than
THRESH. If you do not specify THRESH, or if THRESH is empty ([]),
EDGE chooses the value automatically.
BW = EDGE(I,'prewitt',THRESH,DIRECTION) specifies directionality for
the Prewitt method. DIRECTION is a string specifying whether to look
for 'horizontal' or 'vertical' edges, or 'both' (the default).
BW = EDGE(I,'prewitt',...,OPTIONS) provides an optional string
input. String 'nothinning' speeds up the operation of the algorithm by
skipping the additional edge thinning stage. By default, or when
'thinning' string is specified, the algorithm applies edge thinning.
[BW,thresh] = EDGE(I,'prewitt',...) returns the threshold value.
[BW,thresh,gv,gh] = EDGE(I,'prewitt',...) returns vertical and
horizontal edge responses to Prewitt gradient operators. You can
also use these expressions to obtain gradient responses:
if ~(isa(I,'double') || isa(I,'single')); I = im2single(I); end
gh = imfilter(I,fspecial('prewitt') /6,'replicate'); and
gv = imfilter(I,fspecial('prewitt')'/6,'replicate');
Roberts Method
--------------
BW = EDGE(I,'roberts') specifies the Roberts method.
BW = EDGE(I,'roberts',THRESH) specifies the sensitivity threshold for
the Roberts method. EDGE ignores all edges that are not stronger than
THRESH. If you do not specify THRESH, or if THRESH is empty ([]),
EDGE chooses the value automatically.
BW = EDGE(I,'roberts',...,OPTIONS) provides an optional string
input. String 'nothinning' speeds up the operation of the algorithm by
skipping the additional edge thinning stage. By default, or when
'thinning' string is specified, the algorithm applies edge thinning.
[BW,thresh] = EDGE(I,'roberts',...) returns the threshold value.
[BW,thresh,g45,g135] = EDGE(I,'roberts',...) returns 45 degree and
135 degree edge responses to Roberts gradient operators. You can
also use these expressions to obtain gradient responses:
if ~(isa(I,'double') || isa(I,'single')); I = im2single(I); end
g45 = imfilter(I,[1 0; 0 -1]/2,'replicate'); and
g135 = imfilter(I,[0 1;-1 0]/2,'replicate');
Laplacian of Gaussian Method
----------------------------
BW = EDGE(I,'log') specifies the Laplacian of Gaussian method.
BW = EDGE(I,'log',THRESH) specifies the sensitivity threshold for the
Laplacian of Gaussian method. EDGE ignores all edges that are not
stronger than THRESH. If you do not specify THRESH, or if THRESH is
empty ([]), EDGE chooses the value automatically.
BW = EDGE(I,'log',THRESH,SIGMA) specifies the Laplacian of Gaussian
method, using SIGMA as the standard deviation of the LoG filter. The
default SIGMA is 2; the size of the filter is N-by-N, where
N=CEIL(SIGMA*3)*2+1.
[BW,thresh] = EDGE(I,'log',...) returns the threshold value.
Zero-cross Method
-----------------
BW = EDGE(I,'zerocross',THRESH,H) specifies the zero-cross method,
using the specified filter H. If THRESH is empty ([]), EDGE chooses
the sensitivity threshold automatically.
[BW,THRESH] = EDGE(I,'zerocross',...) returns the threshold value.
Canny Method
----------------------------
BW = EDGE(I,'canny') specifies the Canny method.
BW = EDGE(I,'canny',THRESH) specifies sensitivity thresholds for the
Canny method. THRESH is a two-element vector in which the first element
is the low threshold, and the second element is the high threshold. If
you specify a scalar for THRESH, this value is used for the high
threshold and 0.4*THRESH is used for the low threshold. If you do not
specify THRESH, or if THRESH is empty ([]), EDGE chooses low and high
values automatically.
BW = EDGE(I,'canny',THRESH,SIGMA) specifies the Canny method, using
SIGMA as the standard deviation of the Gaussian filter. The default
SIGMA is 1; the size of the filter is chosen automatically, based
on SIGMA.
[BW,thresh] = EDGE(I,'canny',...) returns the threshold values as a
two-element vector.
Class Support
-------------
I is a nonsparse numeric array. BW is of class logical.
Remarks
-------
For the 'log' and 'zerocross' methods, if you specify a
threshold of 0, the output image has closed contours, because
it includes all of the zero crossings in the input image.

Kapil Nagwanshi
Kapil Nagwanshi 2012-9-27
and finally you can use the following example
Find the edges of the circuit.tif image using the Prewitt and Canny
methods:
I = imread('circuit.tif');
BW1 = edge(I,'prewitt');
BW2 = edge(I,'canny');
figure, imshow(BW1)
figure, imshow(BW2)
  1 个评论
mangat rai
mangat rai 2012-9-27
I already knew this all. This wasn't my question. I actually needed to customize Canny detector for my use.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by