Stephen Gruppetta Profile picture
Apr 11, 2022 9 tweets 3 min read Read on X
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 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 Cross-section of a sinusoidal grating
Sinusoidal gratings can have different orientations… Sinusoidal gratings with different orientations
…different amplitudes… Sinusoidal gratings with different amplitudes
…and different frequencies—these are spatial frequencies, not temporal ones Sinusoidal gratings with different frequencies
There's one more parameter that defines a sinusoidal grating: the phase. Gratings with a different phase are shifted with respect to each other… Sinusoidal grating with different phase
You can create a 2D sinusoidal grating in #Python using #NumPy and display it using #Matplotlib

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

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Stephen Gruppetta

Stephen Gruppetta Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @s_gruppetta

Jun 10
What's the `bytes` data structure? Why do I need it? And what's UTF-8?

Sounds boring… but recently, I came across this topic in my meanderings and found it fascinating

This subject is a bit more computer-science-y
But don't worry, I'll take good care of you

/1
First, let's look at a built-in type you may not have heard of: `bytes`

We'll get to the general meaning of "byte" in computing in a second

But first, let's focus on the data type called `bytes`.

And the best way to explain bytes is to compare it with a string.

/2
Let's create a string and a bytes object

The bytes literal looks very similar to the string one. You add b in front of the quotes

/3 Image
Read 40 tweets
Apr 5, 2023
Object-Oriented Python at the Hogwarts School of Codecraft and Algorithmancy
---
Year 5:
Inheritance
---

The students are growing up! This Year they'll learn about a key property of OOP - how to create a class that inherits from another one

Here's the code so far

/1 Image
We've got four classes:
• Wizard
• House
• Wand
• Spell

Each one has its own attributes — these are data attributes and methods

The classes represent "things" as seen from a human's perspective. Each class contains all the data attributes and methods needed by an object

/2
Now, at Hogwarts School of Codecraft & Algorithmancy there are students & professors

They have different things, such as "subject taught" or "mark exam" for professors and "subjects studied" or "take exam" for students

However, all professors & students are wizards

/3
Read 33 tweets
Apr 3, 2023
Object-Oriented Python at the Hogwarts School of Codecraft and Algorithmancy
---
Year 4:
More interaction between classes
---

Year 3 was a busy year. Here's were we left in Year 3

/1 See year 3 thread for code in ALT text
In earlier Years, we discussed how we should think of the problem from the point of view of the "objects" that make sense to a human describing the problem

In our example so far, we have:
• Wizard
• House
• Wand

An object that belongs to these classes has _attributes_

/2
You've already come across the two types of attributes an object can have

• Data attributes are variables that are connected to the instance of the class. They are also called instance variables

• Methods are functions connected to the instance of the class

/3
Read 20 tweets
Apr 1, 2023
Slightly off-topic from my usual on this account—but a lot of my work is also linked to children's education (coding primarily, but let's think beyond subjects)

I've taken a stab at what "homework" in the near-future could look like, using a GPT-first, cheat-proof approach…

/1 1. Write an outline of your...
It solves reasonably well the problem of "cheating" by incorporating GPT into the process and requiring the whole conversation to be submitted, including first drafts, suggestions by GPT, second drafts, and so on

Teachers can craft the right prompts that all students use

/2
But main point is not that it's cheat-proof but that it leverages the opportunities LLMs provide to improve learning

I collated some ideas & examples of how learning (children, but also adult-learning) could change soon

Consider as work-in-progress

codetoday.co.uk/post/learning-…

/3
Read 4 tweets
Mar 5, 2023
What Python data type would [a multi-storey car park] be?
–––
You drive into a multi-storey car park, find a spot to park, and then you ask yourself: "what data structure would best represent this car park", of course

Let's explore

1/ Model of a multi-storey car...
Let's name the object `car_park` and it contains several levels. I'll also look at `level` which represents one the levels. This will be a different data type

The car park has a fixed number of levels which don't change. Therefore, `car_park` is immutable

2/
You can count the levels – `len(car_park)` exists
You can determine whether `level` is in `car_park`, so `car_park` is a container
You can go through the levels one after the other, so `car_park` is iterable

These three properties make `car_park` a collection, too

3/
Read 15 tweets
Mar 4, 2023
These thought experiments help us focus on real decisions we need to make when choosing what data types to use in programs

It's not just about the data itself but how you're likely to use it

For example, in this restaurant tables scenario, I opted for dictionaries, but…

/1
It depends whether we want to prioritise the use case when the tables are being used during normal service, with diners sitting on them and waiters taking their orders and bringing them food [dictionary is a good choice]…

/2
…or if you want to prioritise the setting up process before the restaurant opens its doors when staff go from one table to the next to clean it and set it up. For this, you could be tempted to use a sequence instead, such as a tuple or list

/3
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(