Difference-of-Gaussians??
Closed this issue · 3 comments
Hi,
I am new to using the CImg library and am doing so via an R package called imageR. What I would like to do in R is implement an edge filter, commonly called EDGE DOG. (I'll eventually need the SOBEL as well). I was wondering if anyone has implemented these using the CImg library and if so is there code or help that could be shared? My initial read of the documentation suggested that the "blur" function was not an actual gaussian blur. So I thought perhaps there was some nuance I was missing.
I would also be interested in any extended DoG implementations, such as seen and referenced here
https://code.google.com/archive/p/xdog-demo/downloads
https://github.com/gonzojive/xdog
Thanks in advance,
Matt Considine
Randolph, Vermont, USA
To achieve a gaussian blur, I'd suggest you use the CImg<T>::blur()
function (described here : http://cimg.eu/reference/structcimg__library_1_1CImg.html#ab8cdbb6b936d773a27df0ac93b2c949f),
with the boolean parameter is_gaussian
set to true
.
Another way to simulate a gaussian blur is to apply several iterations (3 or 4 is enough) of the box filter (function CImg<T>::blur_box()
, as described here : http://cimg.eu/reference/structcimg__library_1_1CImg.html#af141a153e5db7ce88bdea183f913900f), so something like :
img.blur_box(sigma).blur_box(sigma).blur_box(sigma);
is a good and fast way to obtain a gaussian blur.
The DOG filter in imager is just this:
dog <- function(im,sigma) im-isoblur(im,sigma,gaussian=TRUE)
load.example("parrots") %>% grayscale %>% dog(3) %>% plot
isoblur calls the blur function David mentions above, which in turn uses the Vanvliet-Young filter (a very good IIR approximation to the Gaussian).
Sobel filtering along the y axis looks like this:
sobel <- matrix(c(-3,-10,-3,0,0,0,3,10,3),3,3) %>% as.cimg
load.example("parrots") %>% grayscale %>% convolve(sobel) %>% plot
Rotate the filter to filter along the y direction.
Perhaps I am mistaken, but I think the DoG filter should be something like
dog <- function(im, sigma1, sigma2) isoblur(im,sigma1,gaussian=TRUE) - isoblur(im,sigma2,gaussian=TRUE)
followed by some thresholding/normalization. Or have I misread some of the references in the links above? The idea is to get at edge detection ...
Thanks again for the replies.
Matt
(edit to fix cut-and-paste mistake)