Learning & Reasoning/R

Erratum in "The art of R programming"

이현봉 2013. 2. 8. 14:07

Erratum in the "The art of R programming" Chapter3

blurpart <- function(img,rows,cols,q) { # img: image passed, rows: rows to edit, cols: col to edit, q: weight
lrows <- length(rows)
lcols <- length(cols)
newimg <- img
randomnoise <- matrix(nrow=lrows, ncol=ncols,runif(lrows*lcols))   # runif(): uniform dist.
newimg@grey <-  (1-q) * img@grey + q * randomnoise 
return(newimg)
}

shoud be modified to ; 

blurpart <- function(img,rows,cols,q) {
lrows <- length(rows)
lcols <- length(cols)
newimg <- img
randomnoise <- matrix(data=runif(lrows*lcols), nrow=lrows, ncol=lcols)  
newimg@grey[rows, cols] <-  (1-q) * img@grey[rows, cols] + q * randomnoise 
return(newimg)
}