# 鏡映 library(imager) im <- grayscale(boats) dim0 <- dim(im) # cimg変数で処理すると遅いので配列で処理する g0 <- array(im, dim0) g1 <- array(0, dim0) # 移動量 bx <- -dim0[1] by <- 0 # 水平反転と平行移動 for (x1 in 1 : dim0[1]) { x0 <- -x1 - bx # 水平反転と平行移動 if (x0 < 1 || x0 > dim0[1]) next for (y1 in 1 : dim0[2]) { y0 <- y1 - by if (y0 < 1 || y0 > dim0[2]) next g1[x1, y1, ,] <- g0[x0, y0, ,] } } # 配列→cimg変数 im.flip_x <- as.cimg(g1) # 同時に2枚並べるレイアウト layout(t(1 : 2)) plot(im, interpolate = FALSE, main = "元の画像") plot(im.flip_x, interpolate = FALSE, main = "水平反転後の画像") # レイアウトを元に戻す layout(1)