/** This demonstrates using Fourier transforms to process an image, obtain its Fourier transform, display the Fourier transform in a logarithmic scale, and then invert the transform to produce the original image. This file is similar to the FourierImage.frink file but contains more stuff for debugging Fourier Transforms, the log magnitude/phase plots, etc. */ //img = new image["file:kittyface.jpg"] //img = new image["file:../docs/images/futureboylogo512x512.png"] //img = new image["file:/home/eliasen/Downloads/webb.jpg"] img = new image["file:/home/eliasen/Pictures/headbanging.png"] //img = new image["file:AudreyHepburnMoire.jpg"] //img = new image["file:../docs/images/futureboylogo114x114.png"] //img = new image["file:../fawncircles.jpg"] //img = new image["file:JWSTdiffraction.png"] //img = img.resize[1024, undef] //img = new image[4096,4096] //img.makeARGB[] // Make a single star (maybe blurred) /* img = new image[101, 101] for x = 0 to 100 for y = 0 to 100 img.setPixel[x,y,0,0,0] img.setPixel[50,50,1,1,1] img = img.circularBlur[3]//.normalize[] img.show[] */ [origWidth, origHeight] = img.getSize[] println["image size is [$origWidth, $origHeight]"] array = img.toComplexArray[] println["\narray is " + first[array@0, 5]] /* start = now[] df = DFT[array] end = now[] println["Time in DFT: " + (end-start -> "ms")] */ start = now[] ff = FFT[array] end = now[] println["Time in FFT: " + (end-start -> "ms")] // If the flag below is true, this assumes the DC component is in the // center of the image. This needs to match the value in the // .toComplexArrayFromLog call below. img2f = ff.toLogImage[true] println["Resultant image size from FFT is " + img2f.getSize[]] img2f.show[] // You can edit fft.png and then comment out the following line and run // it again to re-load the edited image. img2f.write["fft.png"] /* img2d = df.toLogImage[] println["Resultant image size from DFT is " + img2d.getSize[]] img2d.show[] */ start = now[] inverseF = inverseFFT[ff] end = now[] println["Time in inverseFFT: " + (end-start -> "ms")] inverseImgF = inverseF.toImage[origWidth, origHeight] //inverseImgF = inverseF.toImage[] println["Resultant image size from inverse FFT is " + inverseImgF.getSize[]] //inverseImgF.show[] inverseImgF.write["reconstructed.png"] /* inverseD = inverseDFT[df] inverseImgD = inverseD.toImage[] println["Resultant image size from inverse DFT is " + inverseImgD.getSize[]] inverseImgD.show[] */ println["\nff is " + first[ff@0, 5]] a2 = img2f.toComplexArrayFromLog[] println["\na2 is " + first[a2@0, 5]] ia = inverseFFT[a2] println["\nia is " + first[ia@0, 5]] back = ia.toImage[origWidth, origHeight] //back.show[] diff = array.subtract[ia] println["minReal = " + diff.getMinReal[]] println["maxReal = " + diff.getMaxReal[]] println["minImag = " + diff.getMinImag[]] println["maxImag = " + diff.getMaxImag[]] i3 = new image["file:fftin.png"] // If the flag below is true, this assumes the DC component is in the // center of the image. This needs to match the value in the .toLogImage call // above. a3 = i3.toComplexArrayFromLog[true] inv3 = inverseFFT[a3] i3out = inv3.toImage[origWidth, origHeight] i3out = i3out.normalize[] // The following line reproduces the uncropped full FFT instead of the cropped // above // i3out = inv3.toImage[img2f.getWidth[], img2f.getHeight[]] i3out.show[] i3out.write["denoised.png"]