WEBVTT
Kind: captions
Language: en-ID

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

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

00:00:07.617 --> 00:00:10.628
But okay, let's talk about how this is actually made.

00:00:10.628 --> 00:00:12.760
It 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 (as of now) every Pokémon card ever released.

00:00:20.105 --> 00:00:24.828
Now, “every card” is a bit difficult to define, because it depends on what we are counting.

00:00:24.828 --> 00:00:29.843
Are different language versions separate cards?  How about a little reprint?

00:00:29.843 --> 00:00:35.680
However, for reference, the current database includes 18,454 unique card images.

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

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
things like each card's set, release date, 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 insights.  For example, it is the

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

00:01:02.920 --> 00:01:09.040
physical attacks (such as tackles, punches, and kicks), but also elemental moves, 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 part—some of the

00:01:14.920 --> 00:01:19.302
most common words sound like words from the battlefield,

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

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

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

00:01:30.795 --> 00:01:35.132
Each block will be exchanged for 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 the cards we get.

00:01:42.794 --> 00:01:47.713
At some point, the size becomes so small that the details start to blur when zoomed in.

00:01:47.713 --> 00:01:51.320
To address this, we upscaled the entire collage to a higher resolution using

00:01:51.320 --> 00:01:55.400
standard pixel interpolation techniques.  This way, even though the card is very small, it

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

00:02:00.040 --> 00:02:04.120
first step is to determine its dominant color—the color that best represents

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

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

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

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

00:02:22.640 --> 00:02:26.680
At first, I tried taking the average color—essentially adding up 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

00:02:31.360 --> 00:02:37.400
dull, grayish tones.  So, I switched to using the median color.  In mathematics, the median is simply the

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

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

00:02:47.800 --> 00:02:52.120
the algorithm searches the database for Pokémon cards with the most matching colors.

00:02:52.120 --> 00:02:56.000
We can first calculate the median color 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 color of the card is really similar to the dominant color of a block?  At

00:03:01.480 --> 00:03:06.680
what 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 closer

00:03:12.040 --> 00:03:17.080
the dots are, the more similar their colors are.  While this method works at a basic level, it doesn't fully

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

00:03:21.840 --> 00:03:27.000
alternative color spaces.  You may have 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 proves to be much more effective

00:03:31.760 --> 00:03:36.800
because it is designed to look uniform.  In Lab, “L” stands for brightness,

00:03:36.800 --> 00:03:41.400
while “A” and “B” represent color components that show differences in a way that is more in line

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

00:03:46.000 --> 00:03:50.949
the metric by replacing the Euclidean distance with something that better aligns with color perception.  The

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

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

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

00:04:06.520 --> 00:04:11.480
original image lose some of its impact, I added adjustments to give more weight to the

00:04:11.480 --> 00:04:16.400
highly saturated colors, 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 data set, so here's an interesting fact: certain card types are

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

00:04:27.040 --> 00:04:32.080
and mid-level evolutions tend to have fewer versions overall—perhaps because they're not as iconic as their

00:04:32.080 --> 00:04:39.000
base and final forms.  The number of Pokémon cards far outnumbers the number of Trainer and Energy cards,

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

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

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

00:04:55.320 --> 00:05:00.560
be Squirtle—a Basic, Water-type Pokemon.  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 CIE Delta E 2000 values ​​and

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

00:05:19.280 --> 00:05:23.809
that scores the best according to this metric when compared to the dominant color of the blocks.

00:05:23.809 --> 00:05:29.240
However, there will also be other people who approach him.  To ensure variety and avoid repeating the

00:05:29.240 --> 00:05:34.200
same card too often, the algorithm not only selects the most suitable card—it also 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 choices, then applies the

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

00:05:48.854 --> 00:05:54.320
Finally, he randomly selects one card from the top candidates, keeping things organic and varied.

00:05:54.320 --> 00:05:59.840
In some cases, very few cards meet the criteria, which can lead to a replay after the cards are

00:05:59.840 --> 00:06:06.040
used up.  One possible solution is to relax the acceptance threshold, allowing more

00:06:06.040 --> 00:06:11.880
candidates in even if they are not a perfect match.  However, this could also mean that the algorithm is choosing a

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

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

00:06:19.102 --> 00:06:22.800
along the color 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 allow for greater differences, and re-evaluating

00:06:31.800 --> 00:06:34.762
candidates until a sufficient match is found.

00:06:34.762 --> 00:06:37.712
Before placing the selected cards into the final collage,

00:06:37.712 --> 00:06:42.280
we rotate and offset them slightly randomly.  This breaks up the grid and gives the

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

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

00:06:48.640 --> 00:06:53.840
perfectly structured grid also has its appeal... but now we have a choice.

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

00:06:58.734 --> 00:07:04.238
For example, we can adjust the grid size, adjust how tight the color matching is required,

00:07:04.238 --> 00:07:09.015
and modify factors such as rotation range and offset, among many others.

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

00:07:13.998 --> 00:07:19.265
Depending on the 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.

00:07:23.102 --> 00:07:28.819
It consists of over 32,000 cards, with approximately 11,000 unique cards.  The

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

00:07:33.825 --> 00:07:36.724
By the way, speaking of repeat cards, it's interesting to note that

00:07:36.724 --> 00:07:40.744
some Pokémon are 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

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

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

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

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

00:07:58.448 --> 00:08:02.080
And I hope you find this artistic twist on my usual game development content

00:08:02.080 --> 00:08:05.760
enjoyable.  If you have any thoughts on this 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.

