this post was submitted on 14 Jan 2024
91 points (98.9% liked)

196

16293 readers
3912 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 37 points 8 months ago* (last edited 8 months ago) (12 children)

I created this on my phone in MATLAB. You can probably do this in Octave with similar or the same code.

Figure 2024-01-14 17_18_24~2

First, I downloaded the image from Lemmy, then uploaded it into my MATLAB app. I renamed the image to image.jpg, then ran the following code:

image=imread("image.jpg") imagesc(log10(abs( fftshift(fft2(image)) )))

fft2 applies a 2D Fast Fourier transform to the image, which creates a complex (as in complex numbers) image. abs takes the magnitude of the complex image elementwise. log10 scales the result for display.

Then I downloaded the image from the MATLAB app, went into the Photos app and (badly) cropped out the white border.

Despite how dramatically different it looks, it actually contains the same [1] information as the original image. Said differently, you can actually go back to the original with the inverse functions, specifically by undoing the logarithm and applying the inverse FFT.

[1] Almost. (1). There will be border problems potentially caused by me sloppily cropping some pixels out of the image. (2). It looks like MATLAB resized the image when rendering the figure. However, if I actually saved the matrix (raw image) rather than the figure, then it would be the correct size. (3) (Thank you to @[email protected] for pointing this out.) You need the phase information to reconstruct the original signal, which I (intentionally) threw out (to get a real image) when I took the absolute value but then completely forgot about it.

[–] [email protected] 8 points 8 months ago (3 children)

Apply a nice gaussian kernel convolution to the fft and smooth that doodle out! Lets get blurry up in this doodle party!

[–] [email protected] 11 points 8 months ago (2 children)

Apply a nice gaussian kernel convolution to the fft

I applied the following code in MATLAB:

new_image = abs(ifft2(conv2(fft2(image),fspecial('gaussian',69)))); imwrite(new_image,"new_image.png")

And got this:

Figure 2024-01-15 05_40_24

[–] [email protected] 5 points 8 months ago

Just noticed that you chose the nicest kernel size. Even better.

load more comments (1 replies)
load more comments (1 replies)
load more comments (9 replies)