Learn R Programming

wvtool (version 1.0)

edge.detect: Canny and Sobel Edge detector.

Description

A function detects edges in images by Canny or Sobel operator. Sobel provides approximate intensity of gradients for each pixels, while Canny provides a binary image with thin edges.

Usage

edge.detect(x, thresh1=1, thresh2=15, noise="gaussian", noise.s=3, method="Canny")

Arguments

x
A raster image or a matrix
thresh1
low threshold for edge tracking by hysteresis (0-100). Only used for "Canny" edge detector.
thresh2
high threshold for edge tracking by hysteresis (0-100). Only used for "Canny" edge detector.
noise
a method for noise reduction. "gaussian", "median", and "mean" filters are available. Default is "gaussian".
noise.s
filter size for noise reduction (3 or 5). Default is 3.
method
"Canny" and "Sobel" can be selected. Default is "Canny".

Value

A raster or a matrix

Details

Canny edge detector has four steps. 1. noise reduction/ 2. finding the gradient in images by Sobel operator/ 3. Non-maximum suppression/ 4. Hysteresis threshold. When the method "Sobel" is selected, only step 1 and 2 will be done.

See Also

noise.filter

Examples

Run this code
## Not run: 
# data(camphora)	
# data(cryptomeria)
# cryptomeria <- rgb2gray(cryptomeria)
# img.c1 <- crop(camphora,200,200)
# img.c2 <- crop(cryptomeria,300,300)
# par(mfrow=c(2,2))
# image(rot90c(edge.detect(img.c1,thresh1=1, thresh2=15, noise="gaussian", noise.s=3,
#  method="Canny")),col=gray(c(0:255)/255), main="Canny", useRaster=TRUE, axes=FALSE, asp=1)
# image(rot90c(edge.detect(img.c1,thresh1=1, thresh2=15, noise="gaussian", noise.s=3,
#  method="Sobel")),col=gray(c(0:255)/255), main="Sobel", useRaster=TRUE, axes=FALSE, asp=1)
# image(rot90c(edge.detect(img.c2,thresh1=1, thresh2=15, noise="gaussian", noise.s=3,
#  method="Canny")),col=gray(c(0:255)/255), main="Canny", useRaster=TRUE, axes=FALSE, asp=1)
# image(rot90c(edge.detect(img.c2,thresh1=1, thresh2=15, noise="gaussian", noise.s=3,
#  method="Sobel")),col=gray(c(0:255)/255), main="Sobel", useRaster=TRUE, axes=FALSE, asp=1)
# ## End(Not run)

Run the code above in your browser using DataLab