WEBVTT
Kind: captions
Language: en-FR

00:00:00.080 --> 00:00:02.899
This is a Pokémon card... made up of Pokémon cards.

00:00:02.899 --> 00:00:07.617
32,580 of them, to be precise.  And it's all done with code.

00:00:07.617 --> 00:00:10.628
But anyway, let's talk about how they were made.  It all

00:00:10.628 --> 00:00:12.760
starts with two main ingredients:

00:00:12.760 --> 00:00:15.429
a reference image – the target we want to recreate –

00:00:15.429 --> 00:00:20.105
and a database containing (from now on) all the Pokémon cards ever published.

00:00:20.105 --> 00:00:24.828
Now, "each card" is a little difficult to define, because it depends on what you are counting.

00:00:24.828 --> 00:00:29.843
Are the different language versions separate maps?  What about minor reprints?

00:00:29.843 --> 00:00:35.680
But for reference, the database currently includes 18,454 unique map images.

00:00:35.680 --> 00:00:39.050
I built this database using a script that systematically downloaded

00:00:39.050 --> 00:00:44.345
all available maps from an API I found online (I will link all resources in the description).

00:00:44.345 --> 00:00:47.300
In addition to the images, the dataset also includes metadata,

00:00:47.300 --> 00:00:52.680
such as the set to which each card belongs, release dates, and even the full text of each Pokémon's attacks.

00:00:52.680 --> 00:00:57.640
This metadata also reveals interesting information.  For example, these are the

00:00:57.640 --> 00:01:02.920
most common words in Pokémon attack names.  Several trends stand out: there are multiple references to

00:01:02.920 --> 00:01:09.040
physical attacks (such as tackling, punching and kicking), but also to elementary movements, energy-based terms and even

00:01:09.040 --> 00:01:14.920
references to conditions (such as confusion, sleep and hypnosis).  And here's the surprising thing: some of the

00:01:14.920 --> 00:01:19.302
most common words seem to belong more to a battlefield,

00:01:19.302 --> 00:01:23.016
which was definitely not something I expected to see in Pokémon!

00:01:23.016 --> 00:01:26.002
Now let's return to the process itself; the algorithm begins by

00:01:26.002 --> 00:01:30.795
superimposing a grid onto the reference image, dividing it into different sections.

00:01:30.795 --> 00:01:35.132
Each block will be exchanged for a Pokémon card.

00:01:35.132 --> 00:01:39.057
We can choose the grid size and have as many blocks as we want.

00:01:39.057 --> 00:01:42.794
Of course, the more cards we use, the smaller each one becomes.

00:01:42.794 --> 00:01:47.713
At a certain point, they become so small that details begin to blur when zooming in.

00:01:47.713 --> 00:01:51.320
To solve this problem, we resize the entire collage to a higher resolution using

00:01:51.320 --> 00:01:55.400
standard pixel interpolation techniques.  In this way, even at a very small size,

00:01:55.400 --> 00:02:00.040
the cards remain sharp and clear up close.  For each block in the grid, the first

00:02:00.040 --> 00:02:04.120
step is to determine its dominant color, the one that best represents that section of the

00:02:04.120 --> 00:02:09.400
image.  The idea is that later on we will find the Pokémon card that best matches that color.

00:02:09.400 --> 00:02:13.600
Computers process color as numerical values: in the RGB model, for example,

00:02:13.600 --> 00:02:17.720
each pixel is a combination of intensities of red, green, and blue.  Thus,

00:02:17.720 --> 00:02:22.640
to summarize all the colors of a block, we must condense these numbers into a single value.

00:02:22.640 --> 00:02:26.680
At first, I tried to take the average color, that is, by adding all the

00:02:26.680 --> 00:02:31.360
values ​​of red, green, and blue and dividing by the number of pixels, but this often produced

00:02:31.360 --> 00:02:37.400
dull and grayish tones.  So I opted for the middle color.  In mathematics, the median is simply the

00:02:37.400 --> 00:02:42.280
average value when you line up all the numbers, and because it is less affected by outliers, it tends to

00:02:42.280 --> 00:02:47.800
produce a brighter and more representative color.  Once the dominant color of a block is determined,

00:02:47.800 --> 00:02:52.120
the algorithm searches the database for the Pokémon card with the closest color.

00:02:52.120 --> 00:02:56.000
We can pre-calculate the median color of each card in the database since these values ​​do not

00:02:56.000 --> 00:03:01.480
change.  But how can you tell if the color of a card really resembles the dominant color of a block?  At what

00:03:01.480 --> 00:03:06.680
point are two colors considered "close enough"?  I started with a simple approach: I treated

00:03:06.680 --> 00:03:12.040
each color as a point in 3D space and measured the (Euclidean) distance between them.  The

00:03:12.040 --> 00:03:17.080
closer the points are, the more similar the colors are.  Although this method works on a basic level, it does

00:03:17.080 --> 00:03:21.840
not fully capture the nuances of how we perceive color.  To improve this, I explored

00:03:21.840 --> 00:03:27.000
alternative color spaces.  You have probably heard of RGB (red, green, blue) and HSB (hue,

00:03:27.000 --> 00:03:31.760
saturation, brightness), but in this case, the LAB color space has proven to be much more effective

00:03:31.760 --> 00:03:36.800
because it is designed to be perceptually uniform.  In Lab, "L" stands for lightness,

00:03:36.800 --> 00:03:41.400
and "A" and "B" represent the color components that exhibit differences in a way that more closely matches how

00:03:41.400 --> 00:03:46.000
the human eye actually perceives them.  Based on this, we can further improve the

00:03:46.000 --> 00:03:50.949
metric by replacing Euclidean distance with something more suited to color perception.

00:03:50.949 --> 00:03:56.760
The CIE Delta E 2000 metric is a more sophisticated measurement that quantifies the difference in perception

00:03:56.760 --> 00:04:01.720
between two colors.  Although the underlying mathematics are complex, they essentially tell us how

00:04:01.720 --> 00:04:06.520
similar two colors appear to the human eye.  Since collages can sometimes

00:04:06.520 --> 00:04:11.480
diminish the impact of the original image, I added an adjustment to emphasize

00:04:11.480 --> 00:04:16.400
highly saturated colors, keeping things bright and vibrant.  But of course, the final result also depends on

00:04:16.400 --> 00:04:21.480
the maps available in the dataset, so a quick break for a fun anecdote: some types of maps are

00:04:21.480 --> 00:04:27.040
much more common than others.  Charizard has more than twice as many cards as Blastoise or Venusaur,

00:04:27.040 --> 00:04:32.080
and the intermediate evolutions tend to have fewer versions overall, perhaps because they are not as

00:04:32.080 --> 00:04:39.000
iconic as their base and final forms.  Pokémon cards are far more numerous than Trainer and Energy cards,

00:04:39.000 --> 00:04:43.974
and among them, Water types take the lead, followed by Grass and Psychic.

00:04:43.974 --> 00:04:50.320
The evolution stages follow a natural pattern, with Basic being the most common, followed by Stage 1 and Stage 2.

00:04:50.320 --> 00:04:55.320
So, if we had to choose just one example of the most common card type, it would probably be

00:04:55.320 --> 00:05:00.560
Squirtle, a Water-type Basic Pokémon.  Charmander is therefore the most popular of the

00:05:00.560 --> 00:05:03.720
three original entries, Squirtle is the most representative,

00:05:03.720 --> 00:05:08.521
and Bulbasaur is... well, my favorite.  Okay, let's get back to the algorithm.

00:05:08.521 --> 00:05:14.760
The final color distance metric is a mixture of the CIE Delta E 2000 value and a

00:05:14.760 --> 00:05:19.280
weighted saturation difference, all within the LAB color space.  There will be one card in the database

00:05:19.280 --> 00:05:23.809
that achieves the highest score according to this metric relative to the dominant color of the block.

00:05:23.809 --> 00:05:29.240
However, there will also be others that come very close to it.  To ensure variety and avoid repeating the same

00:05:29.240 --> 00:05:34.200
cards too often, the algorithm does not simply find the best match: rather, it finds

00:05:34.200 --> 00:05:39.320
several candidates for each block.  This begins with a quick search using the Euclidean distance method

00:05:39.320 --> 00:05:44.920
to refine the options, then applies the

00:05:44.920 --> 00:05:48.854
more computationally expensive CIE Delta E 2000 metric (with saturation adjustment) to the pre-filtered candidates.

00:05:48.854 --> 00:05:54.320
Finally, he selects a card at random from the best candidates, keeping things organic and varied.

00:05:54.320 --> 00:05:59.840
In some cases, very few cards will meet the criteria, which may lead to a repeat once these are

00:05:59.840 --> 00:06:06.040
exhausted.  One possible solution would be to relax the acceptance threshold, allowing more

00:06:06.040 --> 00:06:11.880
candidates even if they are not a perfect match.  But this could also mean that the algorithm selects

00:06:11.880 --> 00:06:16.011
suboptimal maps when there are many good ones to choose from.

00:06:16.011 --> 00:06:19.102
This is evident when looking at how Pokémon cards are distributed

00:06:19.102 --> 00:06:22.800
along the spectrum of hues: some colors are underrepresented,

00:06:22.800 --> 00:06:25.268
while others are much more common.

00:06:25.268 --> 00:06:27.920
Instead, the algorithm uses an adaptive threshold,

00:06:27.920 --> 00:06:31.800
slightly relaxing the criteria to allow for a greater difference, and re-evaluates

00:06:31.800 --> 00:06:34.762
candidates until enough good matches are found.

00:06:34.762 --> 00:06:37.712
Before placing the selected card in the final collage,

00:06:37.712 --> 00:06:42.280
we rotate it and shift it slightly at random.  This breaks the grid and gives

00:06:42.280 --> 00:06:45.321
the image a more natural and handcrafted feel.

00:06:45.321 --> 00:06:48.640
In my opinion, even if it creates a more organic result,

00:06:48.640 --> 00:06:53.840
the perfectly structured grid also has its charm... but now we have options.

00:06:53.840 --> 00:06:58.734
The algorithm has many parameters that allow us to refine the result.

00:06:58.734 --> 00:07:04.238
For example, we can adjust the grid size, adjust the rigor of the color matching,

00:07:04.238 --> 00:07:09.015
and modify factors such as rotation and offset ranges, to name a few.

00:07:09.015 --> 00:07:13.998
With all these options, we can experiment and create collages with different levels of detail.

00:07:13.998 --> 00:07:19.265
Depending on the parameters, the treatment time can vary from a few minutes to several days.

00:07:19.265 --> 00:07:23.102
This collage took 2 hours to process on my personal laptop.

00:07:23.102 --> 00:07:28.819
It consists of more than 32,000 cards, of which approximately 11,000 are unique.

00:07:28.819 --> 00:07:33.825
The most frequently repeated card was this one, appearing 331 times.

00:07:33.825 --> 00:07:36.724
Moreover, speaking of repeated cards, it is interesting to note that

00:07:36.724 --> 00:07:40.744
some Pokémon are much more represented than others in the card database.

00:07:40.744 --> 00:07:45.360
Iconic Pokémon like Pikachu, Charizard, Mewtwo and Eevee dominate the top

00:07:45.360 --> 00:07:49.036
spots, while others only have one card.  Fun fact

00:07:49.036 --> 00:07:53.672
, Unown R actually has fewer cards than the other Unowns…

00:07:53.672 --> 00:07:56.059
Yeah, I don’t know.

00:07:56.059 --> 00:07:58.448
I am really happy with the result of the collage.

00:07:58.448 --> 00:08:02.080
And I hope you enjoyed this artistic departure from my usual game development content

00:08:02.080 --> 00:08:05.760
.  If you have any ideas about the project, feel free to leave them in the

00:08:05.760 --> 00:08:10.926
comments or join the discussion on Discord.  Thanks for watching and see you next time.

