Resizing image in R

前端 未结 5 2446
天命终不由人
天命终不由人 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:17

    Inspired by Seily, to resize grey level image.

    resize = function(img, new_width, new_height) {
      new_img = apply(img, 2, function(y){return (spline(y, n = new_height)$y)})
      new_img = t(apply(new_img, 1, function(y){return (spline(y, n = new_width)$y)}))
    
      new_img[new_img < 0] = 0
      new_img = round(new_img)
    
      return (new_img)
    }
    

提交回复
热议问题