function translatefits, image, imagedims, vectran ;determines if it is necessary to add black space for translation ;this is done only if the translation is positive (up, right or both directions) if imagedims[0]+vectran[0] lt imagedims[0] then tranmodx=0 else tranmodx=vectran[0] if imagedims[1]+vectran[1] lt imagedims[1] then tranmody=0 else tranmody=vectran[1] dummy=image image=lonarr(imagedims[0]+tranmodx, imagedims[1]+tranmody) for j=0, (imagedims[0]-1) do begin for k=0, (imagedims[1]-1) do begin image[j,k]=dummy[j,k] endfor endfor imagedims=size(image, /dimensions) dummy=image if vectran[0] lt 0 then begin ;here the subscript modifications are calculated j1=0 ;basically these are needed so that the image j2=abs(vectran[0]) ;can be translated in all directions j3=0 ;the algorhytm is the most complex one in the code j4=imagedims[0] ;but it can be understood through the example given at endif else begin ;the end of the function j1=vectran[0] j2=0 j3=imagedims[0] j4=0 endelse if vectran[1] lt 0 then begin k1=0 k2=abs(vectran[1]) k3=0 k4=imagedims[1] endif else begin k1=vectran[1] k2=0 k3=imagedims[1] k4=0 endelse dummy=image for j=0, (imagedims[0]-1-(j1+j2)) do begin for k=0, (imagedims[1]-1-(k1+k2)) do begin image[j+j1,k+k1]=dummy[j+j2,k+k2] endfor endfor for j=0, (imagedims[0]-1-(j1+j2)) do begin for k=(imagedims[1]-(k1+k2)), (imagedims[1]-1) do begin image[j+j1,k+k1-k3]=dummy[j+j2,k+k2-k4] endfor endfor for j=(imagedims[0]-(j1+j2)), (imagedims[0]-1) do begin for k=0, (imagedims[1]-1-(k1+k2)) do begin image[j+j1-j3,k+k1]=dummy[j+j2-j4,k+k2] endfor endfor for j=(imagedims[0]-(j1+j2)), (imagedims[0]-1) do begin for k=(imagedims[1]-(k1+k2)), (imagedims[1]-1) do begin image[j+j1-j3,k+k1-k3]=dummy[j+j2-j4,k+k2-k4] endfor endfor return, image end ;so let's suppose we have a 5x5 image and -4,+10 translation vector. the new image will ;have dimensions 5x15, adding black space at the end of the image. now let's look at ;the coeficient clauses. vectran[0] is negative, so: ; j1=0 ; j2=abs(vectran[0]) ; j3=0 ; j4=imagedims[0] ;now let's just look at the part of translation ; ; for j=0, (imagedims[0]-1-(j1+j2)) do begin ; for k=0, (imagedims[1]-1-(k1+k2)) do begin ; image[j+j1,k+k1]=dummy[j+j2,k+k2] ; endfor ; endfor ; ;so the counter j goes from 0 to imagedims[0]-1-(j1+j2) ;imagedims[0]-1 is the maximum index ;(j1+j2) is always a positive value and eather j1 or j2 have value of 0 ;if the x translation is positive then j2 will be zero ;if the x translation is negative (as in our case) then j1 will be zero ;accordingly the counters on will start from j1 of the image array if the translation ;is positive and from j2 of the dummy array if the translation is negative, effectively ;simulating translation to positive or negative direction ; ; image[j+j1,k+k1]=dummy[j+j2,k+k2] ; ;same stands for k coeficients and y axis ; ;the first part of the code will only transfer one part of the picture ;so the j3 and j4 koeficients are used to substract the image dimensions from the ;current counter ; ; image[j+j1-j3,k+k1-k3]=dummy[j+j2-j4,k+k2-k4] ; ;note that in those parts of the code counters go from (imagedims[0]-(j1+j2)) to ;(imagedims[0]-1) ; ;to sum up - translation is a pixel (or rather [i,j] array element) to pixel ;transfer of data with accordingly changed coordinates for each pixel