Learn R Programming

imager (version 0.42.10)

hough_circle: Circle detection using Hough transform

Description

Detects circles of known radius in a pixset. The output is an image where the pixel value at (x,y) represents the amount of evidence for the presence of a circle of radius r at position (x,y). NB: in the current implementation, does not detect circles centred outside the limits of the pixset.

Usage

hough_circle(px, radius)

Arguments

px

a pixset (e.g., the output of a Canny detector)

radius

radius of circle

Value

a histogram of Hough scores, with the same dimension as the original image.

Examples

Run this code
# NOT RUN {
im <- load.example('coins')
px <- cannyEdges(im)
#Find circles of radius 20
hc <- hough_circle(px,20)
plot(hc)
#Clean up, run non-maxima suppression
nms <- function(im,sigma) { im[dilate_square(im,sigma) != im] <- 0; im}
hc.clean <- isoblur(hc,3) %>% nms(50)
#Top ten matches
df <- as.data.frame(hc.clean) %>%
dplyr::arrange(desc(value)) %>% head(10)
with(df,circles(x,y,20,fg="red",lwd=3))
# }

Run the code above in your browser using DataLab