WEBVTT
Kind: captions
Language: en

00:00:00.080 --> 00:00:02.899
This is a Pokémon card...it's made of Pokémon cards.  To be

00:00:02.899 --> 00:00:07.617
precise, the number is 32,580.  And it's all done in code.

00:00:07.617 --> 00:00:10.628
Now, let's talk about how these were actually made.

00:00:10.628 --> 00:00:12.760
It all starts with two main elements.  One is a

00:00:12.760 --> 00:00:15.429
reference image (the target you want to recreate)

00:00:15.429 --> 00:00:20.105
, and the other is a database containing all Pokémon cards released to date (as of now).

00:00:20.105 --> 00:00:24.828
Now, defining "all cards" is a bit tricky because it depends on what you're counting.

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

00:00:29.843 --> 00:00:35.680
However, for your reference, the database currently contains 18,454 unique card images.  This database was built using a script that systematically downloads all

00:00:35.680 --> 00:00:39.050
available cards from APIs found online

00:00:39.050 --> 00:00:44.345
(links to all resources are provided within the description).  In

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

00:00:47.300 --> 00:00:52.680
includes metadata such as the set each card belongs to, its release date, and the full text of each Pokémon's attack.

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

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

00:01:02.920 --> 00:01:09.040
are multiple references to physical attacks (tackles, punches, kicks, etc.), but there are also references to elemental movements, energy-based terminology, and even

00:01:09.040 --> 00:01:14.920
states (confusion, sleep, hypnosis, etc.).  And here's the surprising part.

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

00:01:19.302 --> 00:01:23.016
expected to see this 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 overlaying a grid onto the reference image and dividing the reference image into various sections.

00:01:30.795 --> 00:01:35.132
Each block is exchanged for one Pokémon card.  You

00:01:35.132 --> 00:01:39.057
can choose the grid size and include as many blocks as you need.

00:01:39.057 --> 00:01:42.794
Of course, the more cards you use, the smaller each individual card becomes.  At

00:01:42.794 --> 00:01:47.713
some point, they become very small, and when you zoom in, the details start to blur.  To address this, we'll

00:01:47.713 --> 00:01:51.320
use standard pixel interpolation techniques to scale up the entire collage to a higher resolution

00:01:51.320 --> 00:01:55.400
.  This way, even at a very small size, the

00:01:55.400 --> 00:02:00.040
cards appear sharp and clear when viewed up close.  For every block in the grid, the first

00:02:00.040 --> 00:02:04.120
step is to determine its primary color—the color that best represents that section of the image

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

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

00:02:17.720 --> 00:02:22.640
to summarize all the colors within a block, these numbers need to be condensed into a single value.

00:02:22.640 --> 00:02:26.680
Initially, I tried to obtain an average color (basically, by adding up the red,

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

00:02:31.360 --> 00:02:37.400
often resulted in a dull, grayish hue.  Therefore, we switched to using the median color instead.  In mathematics, the median is

00:02:37.400 --> 00:02:42.280
simply the middle value when all numbers are arranged in a row, and because it is less affected by outliers, it

00:02:42.280 --> 00:02:47.800
tends to produce a more vivid and representative color.  Once the main color of a block is determined, the

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

00:02:52.120 --> 00:02:56.000
Since these values ​​do not change, we can pre-calculate the median color for all cards in the database

00:02:56.000 --> 00:03:01.480
.  But how can you know if the card's color is truly similar to the dominant color of the block? At

00:03:01.480 --> 00:03:06.680
what point are two colors considered "close enough"? I started with a simple approach.  We treated each color as a point in 3D space

00:03:06.680 --> 00:03:12.040
and measured the (Euclidean) distance between them.  The closer the points are

00:03:12.040 --> 00:03:17.080
, the more similar their colors become.  This method works at a basic level, but it doesn't

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

00:03:21.840 --> 00:03:27.000
considered alternative color spaces.  You've probably heard of RGB (Red, Green, Blue) and HSB (Hue, Saturation, Lightness), but in

00:03:27.000 --> 00:03:31.760
this case, the

00:03:31.760 --> 00:03:36.800
RGB color space, which is designed to be perceptually uniform, has proven to be far more effective.  In Lab, "L" represents brightness, and

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

00:03:41.400 --> 00:03:46.000
represent color components that show differences in a way that is closer to how the human eye actually perceives them.  Based on this, the

00:03:46.000 --> 00:03:50.949
metrics can be further improved by replacing Euclidean distance with one that is more suitable for color perception

00:03:50.949 --> 00:03:56.760
.  The CIE Delta E 2000 metric is a more sophisticated metric for quantifying differences in perception.

00:03:56.760 --> 00:04:01.720
Between two colors.  The calculations behind it are complex, but basically it

00:04:01.720 --> 00:04:06.520
tells us how two colors resemble what the human eye sees.  Because collages can sometimes lose some of the impact of the original images

00:04:06.520 --> 00:04:11.480
, I added adjustments to give more weight to the highly saturated colors to

00:04:11.480 --> 00:04:16.400
maintain a bright and lively atmosphere.  However, of course, the final result will

00:04:16.400 --> 00:04:21.480
also depend on the cards available in the dataset.  Therefore, I will briefly explain an interesting fact.  Certain types of cards are

00:04:21.480 --> 00:04:27.040
far more common than other types.  Charizard has more than twice as many cards as Blastoise and Venusaur

00:04:27.040 --> 00:04:32.080
, and there is a general tendency for the number of versions to decrease in the mid-career evolutions.  This is probably

00:04:32.080 --> 00:04:39.000
because it is not as symbolic as the basic or final form.  The number of Pokémon cards far exceeds the number of Trainer cards and Energy cards, with

00:04:39.000 --> 00:04:43.974
Water-type cards being the most numerous, followed by Grass-type and Psychic-type cards.  The

00:04:43.974 --> 00:04:50.320
evolutionary stages follow a natural pattern, with the basic stage being the most common, followed by Stage 1, and then Stage 2.

00:04:50.320 --> 00:04:55.320
Therefore, if we were to give one example of the most common type of card, it would probably be

00:04:55.320 --> 00:05:00.560
Squirtle, a basic Water-type Pokémon.  Therefore, Charmander is the most popular of the three original starters

00:05:00.560 --> 00:05:03.720
, Squirtle is the most representative, and

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

00:05:08.521 --> 00:05:14.760
final color distance metric is a blend of CIE Delta E 2000 values ​​and weighted saturation

00:05:14.760 --> 00:05:19.280
differences, all within the LAB color space.  The database

00:05:19.280 --> 00:05:23.809
contains one card that scores the highest according to this metric when compared to the dominant color of the block.

00:05:23.809 --> 00:05:29.240
However, there are probably other things that are very similar.  To ensure diversity and

00:05:29.240 --> 00:05:34.200
avoid frequent repetition of the same cards, the algorithm

00:05:34.200 --> 00:05:39.320
finds multiple candidates for each block, rather than simply determining the top match.  First, we narrow down the options with a quick search using Euclidean distance

00:05:39.320 --> 00:05:44.920
, and then we apply the more computationally intensive 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, one card is randomly selected from the top candidates to keep things organic and diverse.  In

00:05:54.320 --> 00:05:59.840
some cases, there may be very few cards that meet the criteria, and the problem may

00:05:59.840 --> 00:06:06.040
recur once the cards run out.  One possible solution is to relax the acceptance criteria and

00:06:06.040 --> 00:06:11.880
allow more candidates, even if they are not a perfect match.  However, this could

00:06:11.880 --> 00:06:16.011
also mean that the algorithm might select a less-than-optimal card when there are many good cards to choose from

00:06:16.011 --> 00:06:19.102
.  This is evident when you look at how Pokémon cards are distributed along the hue spectrum

00:06:19.102 --> 00:06:22.800
.  Some colors are underrated

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 to

00:06:27.920 --> 00:06:31.800
slightly relax the criteria and allow for larger differences,

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

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

00:06:37.712 --> 00:06:42.280
cards will be randomly rotated and offset.  This divides the grid,

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

00:06:45.321 --> 00:06:48.640
my opinion, this yields a more organic result, although a

00:06:48.640 --> 00:06:53.840
perfectly structured grid is also appealing...but now we have a choice.  The

00:06:53.840 --> 00:06:58.734
algorithm has various settings that allow you to fine-tune the results.

00:06:58.734 --> 00:07:04.238
For example

00:07:04.238 --> 00:07:09.015
, you can adjust the grid size, fine-tune how strict the color matching needs to be, and modify elements such as rotation and offset ranges

00:07:09.015 --> 00:07:13.998
.  With all these options, you can experiment and create collages at various levels of detail.

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

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

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

00:07:28.819 --> 00:07:33.825
This is the most frequently repeated card, having appeared 331 times.

00:07:33.825 --> 00:07:36.724
By the way, speaking of recurring cards, it's

00:07:36.724 --> 00:07:40.744
interesting to note that some Pokémon are represented far more often than others in the card database.

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

00:07:45.360 --> 00:07:49.036
, but there are also Pokémon that only have one card.

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

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

00:07:56.059 --> 00:07:58.448
really happy with how the collage turned out.

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

00:08:02.080 --> 00:08:05.760
.  If you have any opinions about the project, please feel free to leave a comment.

00:08:05.760 --> 00:08:10.926
Please leave a comment or join the discussion on Discord.  Thank you for watching.  See you next time.

