1

I have to read some tif files and modify them by rotating, cutting or inversing them. I figured out how to import my file and I can modify it by translating the data into a matrix but now I don't know how to make a tif file with the information I stored into this matrix.

I searched for a while but it seems that nobody asked this so, could someone give me some ideas to complete this task pls?

Here is my code.

rotation = function(Matrice){
  res = matrix(c(rep(NA, length(Matrice))), nrow = ncol(Matrice), ncol = nrow(Matrice))
  for (i in 1:nrow(Matrice)){
    res[,(nrow(Matrice) - i + 1)] = Matrice[i,]
  }
  return(res)
}

photo = readTIFF("../DataSqueletted/1.tif")
photo2 = matrix(photo, ncol = 1280, nrow = 960)
photo2 = rotation(photo2)

"photo" is a large array while "photo2" is a matrix butwhen i type "View(photo)" i've got the exact same structure.

  • 1
    why not just work with `raster()`? https://stackoverflow.com/questions/55814806/how-to-load-tif-raster-files-in-r – D.J Apr 08 '21 at 14:27
  • 1
    ... or delegate the image manipulation for something designed for image manipulation? Like [ImageMagick](https://imagemagick.org/index.php). The structure of a TIFF file is not straightforward... – Limey Apr 08 '21 at 14:45
  • Also, if you install ImageMagick on your computer, you can access it through R with the `magick` package. – dcarlson Apr 08 '21 at 15:08

0 Answers0