dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

Blob detection scaling correction in vignette #166

Open fischer-fjd opened 1 year ago

fischer-fjd commented 1 year ago

Hi,

thanks for the great package!

Just a quick note on section 5 in the vignette (“blob detection”) on https://cran.rstudio.com/web/packages/imager/vignettes/gettingstarted.html. I think there is a small error in how the Hessian determinant is scaled:

#Compute determinant at scale "scale".
hessdet <- function(im,scale=1) isoblur(im,scale) %>% imhessian %$% { scale^2*(xx*yy - xy^2) }
#Note the scaling (scale^2) factor in the determinant
plot(hessdet(hub,1),main="Determinant of the Hessian at scale 1")

As far as I understand, the scale factor here is not defined as sigma^2, but as sigma (where sigma is the sd of the Gaussian blur), so the scaling of the hessian determinant should be with sigma^4, and not with sigma^2.

hessdet <- function(im,scale=1) isoblur(im, scale) %>% imhessian %$% { scale^4*(xx*yy - xy^2) }

I tested this out in practice, and only a scale^4 factor yields the expected behavior (e.g. recognizing roughly the same objects under image rescaling).

Best,

Fabian