Resizing image in R

前端 未结 5 2464
天命终不由人
天命终不由人 2020-12-25 14:56

I am trying to work with some image data in R, and cannot figure out how to resize the images I have to ensure they are all the same size.

In Python, I approached th

5条回答
  •  轮回少年
    2020-12-25 15:21

    Do these options cover what you need:

    library(jpeg)
    
    img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
    
    # Set image size in pixels
    for (i in 3:6) {
      jpeg(paste0("Pixels",i,".jpeg"), width=200*i, height=200*i)
      plot(as.raster(img))
      dev.off()
    }
    
    # Set image size in inches (also need to set resolution in this case)
    for (i in 3:6) {
      jpeg(paste0("Inches",i,".jpeg"), width=i, height=i, unit="in", res=600)
      plot(as.raster(img))
      dev.off()
    }
    

    You can also save in other formats; png, bmp, tiff, pdf. ?jpeg will display help for saving in bitmap formats. ?pdf for help on saving as pdf.

提交回复
热议问题