# make up an image
X <- setcov(unit.square())
plot(X)
# a rectangular subset
W <- owin(c(0,0.5),c(0.2,0.8))
X[W] <- 2
plot(X)
# a polygonal subset
R <- affine(letterR, diag(c(1,1)/2), c(-2,-0.7))
X[R] <- 3
plot(X)
# a point pattern
X[cells] <- 10
plot(X)
# change pixel value at a specific location
X[list(x=0.1,y=0.2)] <- 7
# matrix indexing --- single vector index
X[1:2570] <- 10
plot(X)
# matrix indexing using double indices
X[1:257,1:10] <- 5
plot(X)
# matrix indexing using a matrix of indices
X[cbind(1:257,1:257)] <- 10
X[cbind(257:1,1:257)] <- 10
plot(X)
# Blank indices
Y <- as.im(letterR)
plot(Y)
Y[] <- 42 # replace values only inside the window 'R'
plot(Y)
Y[drop=FALSE] <- 7 # replace all values in the rectangle
plot(Y)
Z <- as.im(letterR)
Z[] <- raster.x(Z, drop=TRUE) # excludes NA
plot(Z)
Z[drop=FALSE] <- raster.y(Z, drop=FALSE) # includes NA
plot(Z)
Run the code above in your browser using DataLab