WEBVTT
Kind: captions
Language: en-AR

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
32,580 of them to be exact.  All of this is done using code.

00:00:07.617 --> 00:00:10.628
But okay, let's talk about how these things are actually made.  It

00:00:10.628 --> 00:00:12.760
all starts with two key components: a

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

00:00:15.429 --> 00:00:20.105
database that contains (so far) every Pokémon card ever released.

00:00:20.105 --> 00:00:24.828
Now, it's a bit difficult to define "every card" because it depends on what we count.

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

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

00:00:35.680 --> 00:00:39.050
created this database using a script that

00:00:39.050 --> 00:00:44.345
systematically downloads every available card 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 descriptive data —

00:00:47.300 --> 00:00:52.680
things like which group 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 insights.  For example, these are the most common words

00:00:57.640 --> 00:01:02.920
in the names of Pokémon attacks.  Some 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 there are also racist gestures, energy-based terms, and even

00:01:09.040 --> 00:01:14.920
references to states (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 they belong on 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
Now, going back to the same process, the algorithm begins by

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

00:01:30.795 --> 00:01:35.132
Each block will be replaced with one Pokémon card.

00:01:35.132 --> 00:01:39.057
We can choose the grid size and get the number of blocks we want.

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

00:01:42.794 --> 00:01:47.713
At a certain point, it becomes so small that the details begin to blur when zoomed in.

00:01:47.713 --> 00:01:51.320
To address this problem, we scale the entire composite image 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 still look 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 the dominant color, which is the color that best represents that part of

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

00:02:09.400 --> 00:02:13.600
Computers process colors as numerical 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 densities.  Therefore,

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

00:02:22.640 --> 00:02:26.680
Initially, I tried to take the average color - basically 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
pale gray tones.  Therefore, I switched to using the medium color instead.  In mathematics, the median is simply the

00:02:37.400 --> 00:02:42.280
middle value when you align all the numbers, and since it is less affected by extreme values, it tends to

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

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

00:02:52.120 --> 00:02:56.000
We can calculate the average color in advance for each card in the database since these values ​​do not

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

00:03:01.480 --> 00:03:06.680
point are the 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 a three-dimensional space and measured the (Euclidean) distance between them.  The

00:03:12.040 --> 00:03:17.080
closer the dots are, the more similar the colors will be.  Although this method works at a basic level, it does not

00:03:17.080 --> 00:03:21.840
fully capture the subtle differences in how we perceive colors.  To improve this, I explored

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

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

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

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

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

00:03:46.000 --> 00:03:50.949
the scale by replacing the Euclidean distance with something more suitable for color perception.  The

00:03:50.949 --> 00:03:56.760
CIE Delta E 2000 scale is a more sophisticated scale that determines the perceptual difference

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

00:04:01.720 --> 00:04:06.520
similar the two colors are to the human eye.  Because collages can sometimes cause the

00:04:06.520 --> 00:04:11.480
original image to lose some of its impact, I've added a modification to give more weight to

00:04:11.480 --> 00:04:16.400
highly saturated colors, keeping things 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 a fun fact: certain types of cards are

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

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

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

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

00:04:43.974 --> 00:04:50.320
evolutionary stages follow a natural pattern, with the base stage 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

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

00:05:00.560 --> 00:05:03.720
three original characters, Squirtle is the most represented, and

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

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

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

00:05:19.280 --> 00:05:23.809
best according to this metric when compared to the dominant color in the block.

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

00:05:29.240 --> 00:05:34.200
cards too often, the algorithm does not just settle on the top match, but instead finds

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

00:05:39.320 --> 00:05:44.920
to narrow down the options, then the

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

00:05:48.854 --> 00:05:54.320
Finally, you randomly select one card from among the top candidates, keeping things organic and diverse.

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

00:05:59.840 --> 00:06:06.040
those cards are exhausted.  One possible solution is to relax the admission 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 is choosing

00:06:11.880 --> 00:06:16.011
suboptimal cards when there are plenty of good cards 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 color spectrum; some colors are underrepresented,

00:06:22.800 --> 00:06:25.268
while others are 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
which relaxes the criteria slightly to allow for a 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 rotate and shift it slightly randomly.  This results in a grid split and gives

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

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

00:06:48.640 --> 00:06:53.840
perfectly structured network also has its charm... but now we have choices.

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

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

00:07:04.238 --> 00:07:09.015
adjust 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 settings, processing time can range from a few minutes to several days.

00:07:19.265 --> 00:07:23.102
Processing this composite image took two hours 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
This card was the most frequently used, appearing 331 times.

00:07:33.825 --> 00:07:36.724
Incidentally, when talking about duplicate 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
Popular Pokémon such as Pikachu, Charizard, Mewtwo and Eevee dominate the

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

00:07:49.036 --> 00:07:53.672
Fun fact, Unown R actually has fewer cards than 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 how the collage turned out.

00:07:58.448 --> 00:08:02.080
I hope you enjoy this technical break from your 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

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

