我正在阅读“R编程的艺术”并遇到了这篇文章:
# adds random noise to img, at the range rows,cols of img; img and the
# return value are both objects of class pixmap; the parameter q
# controls the weight of the noise, with the result being 1-q times the
# original image plus q times the random noise
blurpart <- function(img,rows,cols,q) {
lrows <- length(rows)
lcols <- length(cols)
newimg <- img
randomnoise <- matrix(nrow=lrows, ncol=ncols,runif(lrows*lcols))
newimg@grey <- (1-q) * img@grey + q * randomnoise
return(newimg)
}
我的问题是关于这条线:
newimg@grey <- (1-q) * img@grey + q * randomnoise
如何newimg@grey
最终与img@grey
. 由于randomnoise
是较小的矩阵,该newimg@grey
部分如何识别图像的哪个部分要模糊。
我认为它应该是这样的:
newimg <- img
newimg@grey[rows,cols] <- (1-q) * img@grey[rows,cols] + q * randomnoise