96
submitted 11 months ago* (last edited 11 months ago) by Otherwise_Direction7 to c/196@lemmy.blahaj.zone
you are viewing a single comment's thread
view the rest of the comments
[-] PM_ME_VINTAGE_30S@lemmy.sdf.org 39 points 11 months ago* (last edited 11 months ago)

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 @itslilith@lemmy.blahaj.zone 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.

[-] asbestos@lemmy.world 20 points 11 months ago* (last edited 11 months ago)

Can guarantee OP didn’t expect this when he was making the post, damn

[-] itslilith@lemmy.blahaj.zone 12 points 11 months ago

don't you lose information by taking the abs(), since to restore the full information you need both complex and imaginary parts of the fft? You could probably get away with encoding Re and Im in different color channels tho

[-] drailin@kbin.social 5 points 11 months ago* (last edited 11 months ago)

Another nice way one could preserve the complex data when visualizing it would be to make a 3d color mesh and display the imaginary components as the height in z and the real component as the color scale (or vice-versa).

Edit* now I am trying to think if there would be a clever way to show the abs, Re and Im values in one 3d plot, but drawing a blank. Maybe tie Im to the alpha value to make the transparency change as the imaginary component goes up and down? It would just require mapping the set of all numbers from -inf:inf to 0:1, which is doable in a 1-1 transformation iirc since they both have cardinality C. I think it would be

alpha = 1 - 1/(1-e^{Im(z)})

Which looks a lot like the equation for Bose-Einstein statistics in Stat. Mech. I was never very good at complex analysis or group theory though, so I don't really know what to make of that.

[-] itslilith@lemmy.blahaj.zone 4 points 11 months ago

Bose-Einstein isn't a great fit, since you'd need to integrate, and it only goes from 0:inf. For mapping the reals to 0:1 you could use arctan and shift it a bit.

Now I'm thinking, instead of color and alpha, you could use two out of hue, saturation and value for Re and Im (or all three, and plot Abs as well)

[-] drailin@kbin.social 4 points 11 months ago

Ah, you're right, I haven't taken Stat. Mech. in almost 5 years so my brain just latched on to the general form. Analysis in frequency space is always fun

[-] PM_ME_VINTAGE_30S@lemmy.sdf.org 4 points 11 months ago

Correct. I updated my comment.

[-] drailin@kbin.social 8 points 11 months ago

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

[-] PM_ME_VINTAGE_30S@lemmy.sdf.org 12 points 11 months ago

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

[-] drailin@kbin.social 7 points 11 months ago
[-] drailin@kbin.social 5 points 11 months ago

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

[-] Otherwise_Direction7 5 points 11 months ago

Ok, this is really mad cool, I like it

[-] HerbalGamer@sh.itjust.works 4 points 11 months ago

Saving this comment in case I ever need a new phone background.

this post was submitted on 14 Jan 2024
96 points (100.0% liked)

196

16721 readers
2488 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 2 years ago
MODERATORS