FUNCTION MagnifyArray, array_in, mag, undo=undo, dims=dims ;+ ; NAME: ; MagnifyArray ; PURPOSE: ; Rebin an image to a integer multiple of its original size by ; copying pixel values ; CATEGORY: ; Tricks ; CALLING SEQUENCE: ; result = MagnifyArray(array [, mag, /undo]) ; INPUTS: ; array array[n,m]; type: any ; any 2-dimensional array ; OPTIONAL INPUT PARAMETERS: ; mag scalar; type: integer; default: 2 ; magnification factor; must be an integer ; /undo undoes a previous magnification operation (the magnification ; factor must be the same to retrieve the original array) ; OUTPUTS: ; result array[n*magnification,m*magnification] ; the resulting array enlarged by the magnification factor. ; array element array[i,j] from the input image is replicated ; in array elements ; result[i*magnification..i*magnification+magnification-1, ; j*magnification..j*magnification+magnification-1] ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, SuperArray ; RESTRICTIONS: ; PROCEDURE: ; Both IDL rebinning functions (REBIN and CONGRID) use interpolation ; procedures, and hence in general will produce pixel values not present ; in the original array. ; MagnifyArray replicates pixel values in blocks of magnification ; x magnification pixels. ; MODIFICATION HISTORY: ; FEB-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, undo, /key InitVar, mag , 2 IF min(mag) EQ 1 AND max(mag) EQ 1 THEN return, array_in ; Undo option is only available for 1 and 2 dimensions CASE undo OF 0: BEGIN array_out = [array_in] sz = size(array_out) InitVar, dims, sz[0] dims = dims[0] < sz[0] dummy_dim = dims EQ sz[0] IF dummy_dim THEN array_out = reform(array_out, [sz[1:sz[0]],1]) sz = size(array_out) IF IsType(mag,/scalar) THEN mags = replicate(mag,dims) ELSE mags = mag FOR i=1,dims DO BEGIN j = i-1 sz[i] = mags[j]*sz[i] array_out = reform( SuperArray(array_out, mags[j], after=j), sz[1:sz[0]]) ENDFOR IF dummy_dim THEN array_out = reform(array_out, sz[1:sz[0]-1]) END 1: BEGIN sz = size(array_in) CASE sz[0] OF 1: array_out = array_in[lindgen(sz[1]/mag)*mag] 2: BEGIN nx = sz[1]/mag ny = sz[2]/mag p = lonarr(2,nx*ny) p[0,*] = lindgen(nx)# replicate(1,ny) p[1,*] = replicate(1,nx)# lindgen(ny) p = p*mag array_out = array_in[p[0,*],p[1,*]] array_out = reform(array_out, nx, ny, /overwrite) END ELSE: BEGIN array_out = array_in message, /info, 'Magnification can only be undone for 1D and 2D arrays' END ENDCASE END ENDCASE RETURN, array_out & END