kernel density - R: Shift of resulting image after kernel2d -
i've strange problem after applying kernel2d r code on images. resulting density plot shifted several pixels (up & right side). load image, threshold (until images overlapping). generate list of pixels > 0.
listpospixels=which(thiv>0, arr.ind = true);
which serves input kernel2d function. w , height set dimensions of input image. h i've chosen different values seem not correlated shifts.
res <- kernel2d(as.points(listpospixels), poly=cbind(c(0, d[1], d[1], 0), c(0, 0, d[2], d[2])), h0=h, nx=w, ny=height);
the image stored png
png(paste('kerneldensity.png', sep=''), width=w, height=height) par(mar=c(0,0,0,0)) contour(res, add=f, drawlabels=f, col='green',xaxt='n', yaxt='n')
any hints? thanks! durin
full code example:
library(ebimage) require(splancs) options(max.contour.segments=50000); thiv<-readimage('shiftedinput.jpg'); thiv<-flip(thiv); #due plotting listpospixels=which(thiv>0, arr.ind = true); d=dim(thiv); w <-d[1]; height <- d[2]; res <- kernel2d(as.points(listpospixels), poly=cbind(c(0, d[1], d[1], 0), c(0, 0, d[2], d[2])), h0=20, nx=w, ny=height); png(paste('kerneldensity.png', sep=''), width=w, height=height) par(mar=c(0,0,0,0)) contour(res, add=f, drawlabels=f, col='green',xaxt='n', yaxt='n') dev.off()
Comments
Post a Comment