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
I use the following code to resample matrices. If you have a jpeg object, you might do that for each color channel individual.
The strategy is as follows:
Given a matrix m with the dimensions a and b and the new dimensions a.new and b.new
x.new <- seq(1,a,length.out=a.new) y.new <- seq(1,a,length.out=b.new)
x and in y directionV <- apply(V,2,FUN=function(y,x,xout) return(spline(x,y,xout=xout)$y),x,x.new) V <- t(apply(V,1,FUN=function(y,x,xout) return(spline(x,y,xout=xout)$y),d,y.new))
Here I choose the spline-interpolation but you can also use a linear one with apporx(). You will gain additionally an x- and y-axis for plotting with the image(x = x.new, y = y.new, z = V) function.
Best.