function nimg = nma_zoom_image(img,k) %nma_zoom(img,fileName,k) %zooms an image by factor k. %INPUT: % img: 2D image only (single channel) % k: an integer to zoom img with % %OUTPUT: % nimg: image which is k times as large as img % %Algorithm: nearest neighbor The nearest neighbor method where the value %of each new pixel added to the new image is obtained from the value of %the pixel in the original image by finding the closest pixel in the %original image to the new pixel in the new image. % %By Nasser M. Abbasi %Free to use at your own risk %no error checking on input [M,N] = size(img); newM = M*k; newN = N*k; nimg = zeros(newM,newN); deltay = (M-1)/(newM-1); deltax = (N-1)/(newN-1); for i = 1:newM yp = i*deltay; whole_yp = floor(yp); fraction = yp-whole_yp; if fraction <= 0.5 D = 0; else D = 1; end y = whole_yp+D; y = y+1; for j = 1:newN xp = j*deltax; whole_xp = floor(xp); fraction = xp-whole_xp; if fraction<=.5 D = 0; else D = 1; end x = whole_xp+D; x = x+1; nimg(i,j) = img(y,x); end end end