## curvature goes as the inverse of the radius of a circle
range=seq(3.5,33.5,by=2)
plotRange=seq(0.5,33.5,length=100)
circleRes=array(dim=length(range))
names(circleRes)=range
for (i in seq_along(1:length(range))) {
y=as.Image(makeBrush('disc', size=2*range[i]))
y=ocontour(y)[[1]]
circleRes[i]=abs(mean(localCurvature(x=y,h=range[i])$curvature, na.rm=TRUE))
}
plot(range, circleRes, ylim=c(0,max(circleRes, na.rm=TRUE)), xlab='Circle Radius', ylab='Curvature', type='p', xlim=range(plotRange))
points(plotRange, 1/plotRange, type='l')
## Calculate curvature
x = readImage(system.file("images", "shapes.png", package="EBImage"))[25:74, 60:109]
x = resize(x, 200)
y = gblur(x, 3) > .3
display(y)
contours = ocontour(bwlabel(y))
c = localCurvature(x=contours[[1]], h=11)
i = c$curvature >= 0
pos = neg = array(0, dim(x))
pos[c$contour[i,]+1] = c$curvature[i]
neg[c$contour[!i,]+1] = -c$curvature[!i]
display(10*(rgbImage(pos, , neg)), title = "Image curvature")
Run the code above in your browser using DataLab