procedure mkmosaic(image1,image2,output) string image1 ="" {prompt="name of input image 1 (reference image)"} string image2 ="" {prompt="name of input image 2"} string output ="" {prompt="name of output image"} string orient ="top" {prompt="mosaic image2 to top|bottom|left|right of image1", enum="top|bottom|left|right"} int margin =4 {prompt="width of margin in pixels"} real bgvalue =-100. {prompt="background value"} real scale =1. {prompt="scale pixel values image2 by this factor"} real zero =0. {prompt="offset to add to pixel values image2"} # @(#) task mkmosaic Author: R.A. Jansen -- May 10 1995 # @(#) # @(#) task to create a mosaic of two images of arbitrary dimension. A # @(#) gap of 'margin' pixels with value 'bgvalue' is left between the # @(#) two images. The pixel values of 'image2' will be offset by 'zero' # @(#) and multiplied by 'scale'. 'Image2' is placed to the top, bottom, # @(#) left, or right of 'image1'. # @(#) # @(#) Jun 4 2002 -- replaced call to obsolete task 'imcreate' by block # @(#) replication of "dev$pix.imh". The header of the 'output' # @(#) mosaic is copied from 'image1'. 'chkimg' is now used for # @(#) image checking. When 'scale=0.', auto-scaling is applied. begin string img1, img2, out, ornt, sec1, sec2, sec3, szstr int mrg, np, nax1, nax2, nax3, nax4, nax5, nax6 real bg, scl, zr, sky1, sky2 img1 = image1 img2 = image2 out = output ornt = orient mrg = margin bg = bgvalue scl = scale zr = zero if ( ornt == "top" ) { ornt = "t" } if ( ornt == "bottom" ) { ornt = "b" } if ( ornt == "left" ) { ornt = "l" } if ( ornt == "right" ) { ornt = "r" } # Check whether the 'artdata' package is loaded if ( !defpac("artdata") ) { artdata } # Check existence of reference input image ... unlearn chkimg chkimg (img1, "access", verbose=yes) if (!chkimg.ok) { return } img1 = chkimg.imroot//chkimg.imtype imgets (img1, "i_naxis1") ; nax1 = int(imgets.value) imgets (img1, "i_naxis2") ; nax2 = int(imgets.value) sec1 = "[1:"//nax1//",1:"//nax2//"]" # Check existence of second input image ... unlearn chkimg chkimg (img2, "access", verbose=yes) if (!chkimg.ok) { return } img2 = chkimg.imroot//chkimg.imtype imgets (img2, "i_naxis1") ; nax3 = int(imgets.value) imgets (img2, "i_naxis2") ; nax4 = int(imgets.value) sec2 = "[1:"//nax3//",1:"//nax4//"]" # Check that the output image doesn't exist already ... unlearn chkimg chkimg (out, "noaccess", verbose=yes) if (!chkimg.ok) { return } out = chkimg.imroot//chkimg.imtype # Set output axis dimension ... if ( ornt == "t" ) { nax5 = nax2 + mrg + 1 nax6 = nax2 + nax4 + mrg if ( nax1 > nax3 ) { np = nax1 } else { np = nax3 } szstr = "["//np//","//nax6//"]" } else if ( ornt == "b" ) { nax5 = nax4 + mrg + 1 nax6 = nax4 + nax2 + mrg if (nax3 > nax1 ) { np = nax3 } else { np = nax1 } szstr = "["//np//","//nax6//"]" } else if ( ornt == "l" ) { nax5 = nax3 + mrg + 1 nax6 = nax3 + nax1 + mrg if ( nax2 > nax4 ) { np = nax2 } else { np = nax4 } szstr = "["//nax6//","//np//"]" } else { nax5 = nax1 + mrg + 1 nax6 = nax1 + nax3 + mrg if ( nax4 > nax2 ) { np = nax4 } else { np = nax2 } szstr = "["//nax6//","//np//"]" } # Create image template for new mosaic ... print (" ") print ("Creating frame \""//out//szstr//"\"; pixel value = ",bg) imcopy ("dev$pix.imh[1:2,1:2]", out, verbose=no) imheader (img1, longheader=yes, > "tmpmkmsc.head") mkheader (out, "tmpmkmsc.head", append=no, verbose=no) delete ("tmpmkmsc.head", yes, verify=no) imreplace (out, value=bg, imagina=0., lower=INDEF, upper=INDEF) if ( ornt == "t" || ornt == "b" ) { #imcreate (out, 2, np, nax6, INDEF, INDEF, INDEF, INDEF, INDEF, # header="copy", pixtype="real", reference=img1) blkrep (out, out, int(0.5*np), int(0.5*nax6), 1, 1, 1, 1, 1) } else { #imcreate (out, 2, nax6, np, INDEF, INDEF, INDEF, INDEF, INDEF, # header="copy", pixtype="real", reference=img1) blkrep (out, out, int(0.5*nax6), int(0.5*np), 1, 1, 1, 1, 1) } # Mosaic 'img1' and 'img2' into the output image ... print ("Mosaicing input frames ...") # Apply optional intensity scaling... if ( scl != 1. ) { if ( scl == 0. ) { getsky (img1, niter=3, verbose=no) sky1 = getsky.smidpt getsky (img2, niter=3, verbose=no) sky2 = getsky.smidpt scl = sky1/sky2 print ("Applying automatic scaling ",scl," to frame ",img2," ...") imarith (img2, "*", scl, "tmpmkmscout", title="", divzero=0., hparams="", pixtype="real", calctype="real", verbose=no, noact=no) } else { print ("Applying scaling factor ",scl," to frame ",img2," ...") imarith (img2, "*", scl, "tmpmkmscout", title="", divzero=0., hparams="", pixtype="real", calctype="real", verbose=no, noact=no) } } # Apply optional zero point offset... if ( zr != 0. ) { print ("Applying zero point offset ",zr," to frame ",img2," ...") if ( access("tmpmkmscout.fits") ) { imarith ("tmpmkmscout", "+", zr, "tmpmkmscout2", title="", divzero=0., hparams="", pixtype="real", calctype="real", verbose=no, noact=no) imdelete ("tmpmkmscout", yes, verify=no, default_acti=yes) imrename ("tmpmkmscout2", "tmpmkmscout", verbose=no) } else { imarith (img2, "+", zr, "tmpmkmscout", title="", divzero=0., hparams="", pixtype="real", calctype="real", verbose=no, noact=no) } } if ( ornt == "t" ) { print (img1//sec1," ---> ",out//sec1) imcopy (img1//sec1, out//sec1, verbose=no) sec3 = "[1:"//nax3//","//nax5//":"//nax6//"]" print (img2//sec2," ---> ",out//sec3) if ( access("tmpmkmscout.fits") ) { imcopy ("tmpmkmscout.fits", out//sec3, verbose=no) imdelete ("tmpmkmscout.fits", yes, verify=no, default_acti=yes) } else { imcopy (img2//sec2, out//sec3, verbose=no) } } else if ( ornt == "b" ) { print (img2//sec2," ---> ",out//sec2) if ( access("tmpmkmscout.fits") ) { imcopy ("tmpmkmscout.fits", out//sec2, verbose=no) imdelete ("tmpmkmscout.fits", yes, verify=no, default_acti=yes) } else { imcopy (img2//sec2, out//sec2, verbose=no) } sec3 = "[1:"//nax1//","//nax5//":"//nax6//"]" print (img1//sec1," ---> ",out//sec3) imcopy (img1//sec1, out//sec3, verbose=no) } else if ( ornt == "r" ) { print (img1//sec1," ---> ",out//sec1) imcopy (img1//sec1, out//sec1, verbose=no) sec3 = "["//nax5//":"//nax6//",1:"//nax4//"]" print (img2//sec2," ---> ",out//sec3) if ( access("tmpmkmscout.fits") ) { imcopy ("tmpmkmscout.fits", out//sec3, verbose=no) imdelete ("tmpmkmscout.fits", yes, verify=no, default_acti=yes) } else { imcopy (img2//sec2, out//sec3, verbose=no) } } else { print (img2//sec2," ---> ",out//sec2) if ( access("tmpmkmscout.fits") ) { imcopy ("tmpmkmscout.fits", out//sec2, verbose=no) imdelete ("tmpmkmscout.fits", yes, verify=no, default_acti=yes) } else { imcopy (img2//sec2, out//sec2, verbose=no) } sec3 = "["//nax5//":"//nax6//",1:"//nax2//"]" print (img1//sec1," ---> ",out//sec3) imcopy (img1//sec1, out//sec3, verbose=no) } # print ("Done.") end