WEBVTT
Kind: captions
Language: en-TR

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
Exactly 32,580 of them.  And all of this is done with code.

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

00:00:10.628 --> 00:00:12.760
all starts with two main components:

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

00:00:20.105 --> 00:00:24.828
Now, defining "each card" is a bit difficult because it depends on what we're counting.

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

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

00:00:35.680 --> 00:00:39.050
I created this database using a script that systematically downloads every available card from an API I found online

00:00:39.050 --> 00:00:44.345
(I'll link to all the sources in the description).

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

00:00:47.300 --> 00:00:52.680
also includes metadata 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 information.  For example, these are some of the

00:00:57.640 --> 00:01:02.920
most frequently used words in Pokémon attack names.  Several trends stand out:

00:01:02.920 --> 00:01:09.040
There are multiple references to physical attacks (such as grappling, punching, and kicking), but also to basic movements, energy-based terms, and even

00:01:09.040 --> 00:01:14.920
references to conditions (such as confusion, sleep, and hypnosis).  And the surprising part is this;

00:01:14.920 --> 00:01:19.302
Some of the most common words sound more like they belong on a battlefield,

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

00:01:23.016 --> 00:01:26.002
Now, returning to the process itself, the algorithm

00:01:26.002 --> 00:01:30.795
begins by placing a grid over the reference image and dividing it into different sections.

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

00:01:35.132 --> 00:01:39.057
can choose the size of the grid 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.  At

00:01:42.794 --> 00:01:47.713
a certain point, they shrink so much that when zoomed in, the details begin to blur.

00:01:47.713 --> 00:01:51.320
To solve this problem,

00:01:51.320 --> 00:01:55.400
we're scaling the entire collage to a higher resolution using standard pixel interpolation techniques.  In this way, even at very small sizes,

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

00:02:00.040 --> 00:02:04.120
, the first step is to determine the dominant color that best represents that part of the image

00:02:04.120 --> 00:02:09.400
.  The idea is that later we'll 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.  Therefore,

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

00:02:22.640 --> 00:02:26.680
I initially tried averaging the color (basically adding up all the red,

00:02:26.680 --> 00:02:31.360
green, and blue values ​​and dividing by the pixel count), but this generally produced dull,

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

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

00:02:42.280 --> 00:02:47.800
tends to produce a more vibrant and representative color.  Once a block's dominant color 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.  Since

00:02:52.120 --> 00:02:56.000
these values ​​don't change, we can pre-calculate the median color of each card in the database

00:02:56.000 --> 00:03:01.480
.  So how can we tell if a card's color actually matches 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:

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

00:03:12.040 --> 00:03:17.080
more similar the colors will be.  While this method works at a basic level, it

00:03:17.080 --> 00:03:21.840
doesn't fully capture the nuances of how we perceive color.  To improve this,

00:03:21.840 --> 00:03:27.000
I explored alternative color spaces.  You've probably heard of RGB (red, green, blue) and HSB (hue, saturation, brightness)

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

00:03:31.760 --> 00:03:36.800
because it's designed to be perceptually uniform.  In Lab, "L" represents aperture,

00:03:36.800 --> 00:03:41.400
and "A" and "B"

00:03:41.400 --> 00:03:46.000
represent color components that differ in a way that is closer to how the human eye actually perceives them

00:03:46.000 --> 00:03:50.949
.  Based on this, we can further improve the measurement by replacing the Euclidean distance with something more suitable for color perception

00:03:50.949 --> 00:03:56.760
.  The CIE Delta E 2000 metric is a more complex measure that gauges the perceptual difference

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

00:04:01.720 --> 00:04:06.520
it actually tells us how similar two colors appear to the human eye.  Since collages can sometimes cause the original image to lose some of its impact

00:04:06.520 --> 00:04:11.480
, I added a fine-tuning technique by giving more weight to highly saturated colors to ensure everything stays bright and vibrant

00:04:11.480 --> 00:04:16.400
.  But of course, the final result also

00:04:16.400 --> 00:04:21.480
depends on the cards in the dataset;  So, here's a quick break for a fun fact: certain types of cards 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 there are generally fewer versions of mid-stage evolutions;  Perhaps

00:04:32.080 --> 00:04:39.000
because they aren't as iconic as their basic and final forms.  There are far more Pokémon cards than Trainer and Energy cards, with

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

00:04:43.974 --> 00:04:50.320
Evolutionary stages follow a natural pattern;  Basic is 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 from the most common card type, it

00:04:55.320 --> 00:05:00.560
would probably be Squirtle;  A Basic, Water type Pokémon.  So Charmander is the most popular of the three original starting players

00:05:00.560 --> 00:05:03.720
, 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.  The

00:05:08.521 --> 00:05:14.760
final color distance measurement is

00:05:14.760 --> 00:05:19.280
a combination of the CIE Delta E 2000 value and the weighted saturation difference, all within the LAB color space.  In the database, there will be

00:05:19.280 --> 00:05:23.809
a card that scores best according to this metric when compared to the block's dominant color.

00:05:23.809 --> 00:05:29.240
But there will be others who come very close.  To ensure variety and

00:05:29.240 --> 00:05:34.200
prevent the same cards from being repeated too often, the algorithm doesn't just settle for the best match;  Instead, it

00:05:34.200 --> 00:05:39.320
finds multiple candidates for each block.

00:05:39.320 --> 00:05:44.920
It starts with a quick search using the Euclidean distance method to narrow down the options, then applies the computationally more expensive CIE Delta E 2000

00:05:44.920 --> 00:05:48.854
metric (with saturation adjustment) to the pre-filtered candidates.

00:05:48.854 --> 00:05:54.320
Finally, by randomly selecting a card from among the best candidates, it ensures that everything remains organic and varied.  In

00:05:54.320 --> 00:05:59.840
some cases, there are very few cards that meet the criteria, which

00:05:59.840 --> 00:06:06.040
can lead to the process being repeated once the cards run out.  One possible solution

00:06:06.040 --> 00:06:11.880
might be to relax the acceptance threshold by allowing more candidates, even if they aren't perfect matches.  However, this also means that the algorithm might choose suboptimal cards even when there are many good cards to choose from

00:06:11.880 --> 00:06:16.011


00:06:16.011 --> 00:06:19.102
.

00:06:19.102 --> 00:06:22.800
This is clearly evident when you look at how Pokémon cards are distributed across the color spectrum;

00:06:22.800 --> 00:06:25.268
Some colors are not adequately represented 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 larger difference, and

00:06:31.800 --> 00:06:34.762
re-evaluating candidates until sufficiently good matches are found.

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

00:06:37.712 --> 00:06:42.280
rotate and slide it randomly.  This divides the grid and

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

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

00:06:48.640 --> 00:06:53.840
perfectly structured grill also has its own appeal... but now we have options.

00:06:53.840 --> 00:06:58.734
The algorithm has various settings that allow us to fine-tune the result.  For example, to name a few

00:06:58.734 --> 00:07:04.238
, we can adjust the grid size, set how tight the color matching should be,

00:07:04.238 --> 00:07:09.015
and change factors such as rotation and offset ranges.  With

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

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

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

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

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

00:07:33.825 --> 00:07:36.724
Speaking of repeating cards, it's interesting to note that

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

00:07:40.744 --> 00:07:45.360
.  Iconic Pokémon like Pikachu, Charizard, Mewtwo, and Eevee are at the top of the list, while

00:07:45.360 --> 00:07:49.036
others only have 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'm really pleased with how the collage turned out.

00:07:58.448 --> 00:08:02.080
And 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 ideas about the project, feel free to share them.

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

