require(OpenImageR)
path = system.file("tmp_images", "landscape.jpg", package = "OpenImageR")
img = readImage(path)
img = img * 255
#.............................
# compute the affine transform
#.............................
r = ncol(img)
c = nrow(img)
offset = 50
original_points = matrix(data = c(0, 0, r, 0, 0, c),
nrow = 3,
ncol = 2,
byrow = TRUE)
transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset),
nrow = 3,
ncol = 2,
byrow = TRUE)
M_aff = getAffineTransform(original_points = original_points,
transformed_points = transformed_points)
#..............
# 2-dimensional
#..............
img_2d = rgb_2gray(img)
res_2d = warpAffine(img = img_2d,
M = M_aff,
R = r,
C = c,
threads = 1,
verbose = TRUE)
# imageShow(res_2d)
#..............
# 3-dimensional
#..............
res_3d = warpAffine(img = img,
M = M_aff,
R = r,
C = c,
verbose = TRUE)
# imageShow(res_3d)
Run the code above in your browser using DataLab