WEBVTT
Kind: captions
Language: en-PL

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

00:00:02.899 --> 00:00:07.617
Or more precisely, 32,580 of them.  And all this is done using code.

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

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

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

00:00:15.429 --> 00:00:20.105
and a database containing (for now) every single Pokémon card ever released.

00:00:20.105 --> 00:00:24.828
Defining “every single card” is a bit difficult because it depends on what you are counting.

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

00:00:29.843 --> 00:00:35.680
For comparison, the database currently contains 18,454 unique card 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
every available card from an API I found online (I'll link all the resources in the description).

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

00:00:47.300 --> 00:00:52.680
such as the set each card belongs to, 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 some interesting observations.  For example, these are the most common

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

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

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

00:01:14.920 --> 00:01:19.302
of the most common words sound more like they refer to the battlefield,

00:01:19.302 --> 00:01:23.016
which is definitely something I didn't expect to see in Pokémon!

00:01:23.016 --> 00:01:26.002
Coming back to the process itself, the algorithm starts by

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

00:01:30.795 --> 00:01:35.132
Each block will be converted into one 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 will be.

00:01:42.794 --> 00:01:47.713
At some point they become so small that the details start to blur when you zoom in.

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

00:01:51.320 --> 00:01:55.400
standard pixel interpolation techniques.  This way, even at very small sizes,

00:01:55.400 --> 00:02:00.040
the cards still look sharp and clear up close.  The first step for each grid block

00:02:00.040 --> 00:02:04.120
is to determine its dominant color—the one that best represents that part of the image

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

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

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

00:02:17.720 --> 00:02:22.640
sum all the colors in a block, we need to condense these numbers into a single value.

00:02:22.640 --> 00:02:26.680
At first, I tried taking the average color—simply adding all the

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

00:02:31.360 --> 00:02:37.400
grayish tints.  Instead, I started using the middle color.  In mathematics, the median is simply the

00:02:37.400 --> 00:02:42.280
middle value when you put all the numbers together, and because it is less affected by outliers, it usually

00:02:42.280 --> 00:02:47.800
produces a more vibrant and 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 most matching color.

00:02:52.120 --> 00:02:56.000
We can pre-calculate the average suit for each card in the database because these values ​​do not

00:02:56.000 --> 00:03:01.480
change.  But how do we know if the card suit really resembles the dominant suit of the block?  At what

00:03:01.480 --> 00:03:06.680
point do two colors count as "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 closer

00:03:12.040 --> 00:03:17.080
the points are, the more similar the colors are.  While this method works at a basic level, it does not

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

00:03:21.840 --> 00:03:27.000
color spaces.  You've 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 proved much more effective

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

00:03:36.800 --> 00:03:41.400
and "A" and "B" represent color components that exhibit differences in a way that is more consistent with

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

00:03:46.000 --> 00:03:50.949
the metric by replacing the Euclidean distance with a value more suited to color perception.  The

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

00:03:56.760 --> 00:04:01.720
between two colors.  While the math is complex, it essentially tells us how

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

00:04:06.520 --> 00:04:11.480
original image lose some of its impact, I added a tweak to give more weight to highly saturated

00:04:11.480 --> 00:04:16.400
colors while keeping everything bright and vibrant.  But of course, the final result also depends

00:04:16.400 --> 00:04:21.480
on the cards available in the dataset, so a quick break for some trivia: some card types 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 mid-stage evolutions generally have fewer versions – perhaps because they aren't as

00:04:32.080 --> 00:04:39.000
iconic as their base and final forms.  Pokémon cards significantly outnumber Trainer and Energy cards, with

00:04:39.000 --> 00:04:43.974
Water-types leading the way, followed by Grass and Fairy-types.

00:04:43.974 --> 00:04:50.320
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 one example of the most common card type, it would probably be

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

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

00:05:03.720 --> 00:05:08.521
and Bulbasaur is… well, my favorite.  Okay, back to the algorithm.  The

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

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

00:05:19.280 --> 00:05:23.809
that has the best score in this respect compared to the dominant color of the block.

00:05:23.809 --> 00:05:29.240
However, there will be others who will be very close.  To ensure variety and avoid

00:05:29.240 --> 00:05:34.200
repeating the same cards too often, the algorithm doesn't just focus on the best match – instead, it finds

00:05:34.200 --> 00:05:39.320
multiple candidates for each block.  It starts with a quick search using the Euclidean distance method

00:05:39.320 --> 00:05:44.920
to narrow down the options, and then applies the more computationally expensive

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

00:05:48.854 --> 00:05:54.320
Finally, it randomly selects one card from among the best candidates, maintaining an organic and diverse feel.

00:05:54.320 --> 00:05:59.840
In some cases, very few cards will meet the criteria, which can lead to repeats once they are

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

00:06:06.040 --> 00:06:11.880
even if they are not a perfect fit.  But it could also mean that the algorithm is choosing

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

00:06:16.011 --> 00:06:19.102
This is obvious when we look at the distribution of Pokémon cards

00:06:19.102 --> 00:06:22.800
across the shade spectrum – 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 account for the larger 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 randomly rotate it and move it slightly.  This breaks up the mesh and gives

00:06:42.280 --> 00:06:45.321
the image a more natural, handmade look.

00:06:45.321 --> 00:06:48.640
In my opinion, while this creates a more organic effect, a

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

00:06:53.840 --> 00:06:58.734
The algorithm has a variety of settings that allow us to fine-tune the result.

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

00:07:04.238 --> 00:07:09.015
and modify factors such as rotation and translation range, 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 your settings, processing time can range 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.  It

00:07:23.102 --> 00:07:28.819
consists of over 32,000 cards, including approximately 11,000 unique ones.

00:07:28.819 --> 00:07:33.825
The most frequently repeated card was one that appeared 331 times.

00:07:33.825 --> 00:07:36.724
By the way, speaking of repeating cards, it's worth noting that

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

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.

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

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

00:07:56.059 --> 00:07:58.448
very glad the collage turned out.

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

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

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

