waits for the user to click a point within a graph and returns the exact
coordinates of that point. In this manner, I found that Roosevelt’s portion
of the picture is in rows 84 through 163 and columns 135 through 177.
(Note that row numbers inpixmapobjects increase from the top of the pic-
ture to the bottom, the opposite of the numbering used bylocator().) So,
to blot out that part of the image, we set all the pixels in that range to 1.0.
mtrush2 <- mtrush1
mtrush2@grey[84:163,135:177] <- 1
plot(mtrush2)
The result is shown in Figure 3-2.
Figure 3-2: Mount Rushmore, with President Roosevelt removed
What if we merely wanted to disguise President Roosevelt’s identity? We
could do this by adding random noise to the picture. Here’s code to do that:
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(lrowslcols))
newimg@grey <- (1-q)img@grey + q*randomnoise
return(newimg)
}
Matrices and Arrays 65