/** 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:AudreyHepburnMoire.jpg"] //img = new image["file:../docs/images/futureboylogo114x114.png"] //img = new image["file:../fawncircles.jpg"] img = img.resize[1024, undef] //img = new image[4096,4096] //img.makeARGB[] [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[] 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:fft.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.show[] i3out.write["denoised.png"]