Stephen Gruppetta Profile picture
Constantly looking for simple ways to explain complex things • You'll find Python and narrative technical writing stuff here… @realpython core team member

Apr 11, 2022, 9 tweets

What's an image made of?

There are many correct answers.

But the most fascinating one is: << sines & cosines >>

Read on if you're intrigued👇🧵🪡

#python #images #fourier

*Any* image can be reconstructed from a series of sinusoidal gratings.

A sinusoidal grating looks like this…

#sinusoidal #grating

It’s called a sinusoidal grating because the grayscale values vary according to the sine function.

If you plot the values along a horizontal line of the grating, you’ll get a plot of a sine function

Sinusoidal gratings can have different orientations…

…different amplitudes…

…and different frequencies—these are spatial frequencies, not temporal ones

There's one more parameter that defines a sinusoidal grating: the phase. Gratings with a different phase are shifted with respect to each other…

You can create a 2D sinusoidal grating in #Python using #NumPy and display it using #Matplotlib

@numpy_team @matplotlib

Or even better, you can use a function of both x and y to make any grating

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling