def all_kernels(kdim, writefile=True, makeimage=False, vb=False): ## Get files -- path hard-coded allpngs = numpy.sort(file_seek("../Data/GPSF/", "snap*d0_CFHTLS_03_g*.png")) ## Collect pairs of files for i in range(0, len(allpngs), 2): ## Extract image info image1 = png_pix(allpngs[i]) image2 = png_pix(allpngs[i + 1]) ## Cut out extraneous white pixels image1 = pngcropwhite(image1) image2 = pngcropwhite(image2) ## Deconvolve A = get_kernel(image1, image2, kdim) B = get_kernel(image2, image1, kdim) ##------------------------------------------------------------ ## Write kernels to file and make images ## Gaussian to PSF outfile = os.path.splitext(allpngs[i])[0][:-4] + "_GausstoPSF_" + str( A.shape[0]) + ".krn" f = open(outfile, "w") f.write( "## Convolution kernel taking 2D Gaussian to PSFEx image\n\n\n") writearray(f, A, True) if vb: print "DeconvolveToTargetPSF.py: kernel written to", outfile ## PSF to Gaussian outfile = os.path.splitext(allpngs[i])[0][:-4] + "_PSFtoGauss_" + str( B.shape[0]) + ".krn" f = open(outfile, "w") f.write( "## Convolution kernel taking PSFEx image to 2D Gaussian\n\n\n") writearray(f, B, True) if vb: print "DeconvolveToTargetPSF.py: kernel written to", outfile print "\n" ##------------------------------------------------------------ return
def all_kernels(kdim, writefile=True,makeimage=False, vb=False): ## Get files allpngs = numpy.sort(file_seek("../Data/GPSF/","snap*d0_CFHTLS_03_g*.png")) ## Collect pairs of files for i in range (0,len(allpngs),2): ## Extract image info image1 = png_pix(allpngs[i]) image2 = png_pix(allpngs[i+1]) ## Cut out extraneous white pixels image1 = pngcropwhite(image1) image2 = pngcropwhite(image2) ## Deconvolve A=get_kernel(image1,image2, kdim) B=get_kernel(image2,image1, kdim) ##------------------------------------------------------------ ## Write kernels to file and make images ## Gaussian to PSF outfile=os.path.splitext(allpngs[i])[0][:-4]+"_GausstoPSF_"+str(A.shape[0])+".krn" f=open(outfile,"w") f.write("## Convolution kernel taking 2D Gaussian to PSFEx image\n\n\n") writearray(f,A,True) if vb: print "DeconvolveToTargetPSF.py: kernel written to",outfile ## PSF to Gaussian outfile=os.path.splitext(allpngs[i])[0][:-4]+"_PSFtoGauss_"+str(B.shape[0])+".krn" f=open(outfile,"w") f.write("## Convolution kernel taking PSFEx image to 2D Gaussian\n\n\n") writearray(f,B,True) if vb: print "DeconvolveToTargetPSF.py: kernel written to",outfile print "\n" ##------------------------------------------------------------ return
def reconvolve(image1, image2, kernel): ## Read in images & kernel and process into shape arr1 = pngcropwhite(png_pix(image1)) kernel = numpy.loadtxt(kernel) newdim = numpy.array(arr1.shape)-numpy.array(kernel.shape)+1 arr2 = shave(newdim, pngcropwhite(png_pix(image2))) ## Reconvolved image -- should be integer array recon = numpy.around(convolve(arr1, kernel, mode="valid")) ## Residue should be 0 residue = recon-arr2 ## Visualise residue from pylab import imshow, show, colorbar imshow(residue) #colorbar() show() return