resizeImageNN <- function ( imx, width, height ) #*****************************************************************************80 # ## resizeImageNN resizes an image using nearest neighbor interpolation. # # Licensing: # # Copyright 2016 James P. Howard, II # # The computer code and data files on this web page are distributed under # https://opensource.org/licenses/BSD-2-Clause, the BSD-2-Clause license. # # Modified: # # 28 February 2020 # # Author: # # Original R code by James Howard; # Modifications by John Burkardt. # # Reference: # # James Howard, # Computational Methods for Numerical Analysis with R, # CRC Press, 2017, # ISBN13: 978-1-4987-2363-3. # { imx.dim <- dim ( imx ) # layers <- imx.dim[3] w.scale <- width / ( imx.dim[1] - 1 ) h.scale <- height / ( imx.dim[2] - 1 ) # nn <- array ( 0, c ( height, width, layers ) ) nn <- array ( 0, c ( height, width ) ) # for ( l in 1 : layers ) # { for ( h in 0 : height ) { y <- round ( h / h.scale ) + 1 for ( w in 0 : width ) { x <- round ( w / w.scale ) + 1 # nn[h,w,l] <- imx[y,x,l] nn[h,w] <- imx[y,x] } } # } return ( nn ) }