pro outline,xscale,yscale,lp,bp,xleft,ybott,x,y,absc,ordlow,ordhigh is=size(x) ;print,'Getting outline of image in mosaic coordinates' ; Trace out the outline of the image in mosaic pixel coordinates by ; converting the image absolute geometric display coordinates into ; mosaic pixels; make sure to wrap the outline around xoutline=intarr(1500) youtline=intarr(1500) ocnt=0 for j=0,is(2)-1 do begin xoutline(ocnt+j)=lp+(x(0,j)-xleft)*xscale youtline(ocnt+j)=bp+(y(0,j)-ybott)*yscale endfor ocnt=is(2)-1 for i=1,is(1)-1 do begin xoutline(i+ocnt)=lp+(x(i,is(2)-1)-xleft)*xscale youtline(i+ocnt)=bp+(y(i,is(2)-1)-ybott)*yscale endfor ocnt=ocnt+is(1)-1 for j=is(2)-2,0,-1 do begin jcnt=is(2)-1-j xoutline(ocnt+jcnt)=lp+(x(is(1)-1,j)-xleft)*xscale youtline(ocnt+jcnt)=bp+(y(is(1)-1,j)-ybott)*yscale endfor ocnt=ocnt+is(2)-1 for i=is(1)-2,0,-1 do begin icnt=is(1)-1-i xoutline(ocnt+icnt)=lp+(x(i,0)-xleft)*xscale youtline(ocnt+icnt)=bp+(y(i,0)-ybott)*yscale endfor ocnt=ocnt+is(1)-1 ; Shorten the array size for the outline xoutline=xoutline(0:ocnt) youtline=youtline(0:ocnt) ; Prepare arrays to store the expanded outline xol=intarr(10*(ocnt+1)) yol=intarr(10*(ocnt+1)) ; Fill in the gaps in the xcoordinate of the outline ; olcnt indexes the new, expanded outline arrays xol and yol olcnt=0 for i=0,ocnt-1 do begin xfirst=xoutline(i) xnext=xoutline(i+1) yfirst=youtline(i) ynext=youtline(i+1) xol(olcnt)=xfirst yol(olcnt)=yfirst olcnt=olcnt+1 while not (abs(xnext-xfirst) eq 1) and not (abs(xnext-xfirst) eq 0) do begin if xnext gt xfirst then begin xol(olcnt)=xfirst+1 endif else begin xol(olcnt)=xfirst-1 endelse yol(olcnt)=yfirst*(xnext-xol(olcnt))/(xnext-xfirst) $ +ynext*(xol(olcnt)-xfirst)/(xnext-xfirst) xfirst=xol(olcnt) yfirst=yol(olcnt) olcnt=olcnt+1 endwhile endfor ; Make sure the new expanded array wraps around xol(olcnt)=xoutline(ocnt) yol(olcnt)=youtline(ocnt) ; And shorten it xol=xol(0:olcnt) yol=yol(0:olcnt) ; Now create three new arrays, one which stores all of the x ; mosaic pixel coordinates which represent the abscissa of the ; image and two arrays which store the upper and lower y limits ; of the image limits and represent the ordinate; note that the ; image can't curl so much that it needs four y limits, not two, ; to define its vertical extent; this program won't handle such images ; Create the 3 new arrays absc=intarr(olcnt+1) ordlow=intarr(olcnt+1) ordhigh=intarr(olcnt+1) xmax=max(xol) xmin=min(xol) acnt=0 for i=xmin,xmax do begin absc(i-xmin)=i allx=where(xol eq i) ordlow(i-xmin)=min(yol(allx)) ordhigh(i-xmin)=max(yol(allx)) ; if i eq 255 then stop acnt=acnt+1 endfor absc=absc(0:acnt-1) ordlow=ordlow(0:acnt-1) ordhigh=ordhigh(0:acnt-1) return end