Coding Challenge #50.2: Animated Circle Packing - Part 2 (Kitten Addendum)

The Coding Train
10 Jan 201705:07

Summary

TLDRIn this video, the creator revisits their circle packing algorithm, this time applying it to an image of a kitten. They demonstrate how to modify the algorithm to generate circles filled with colors sampled from the image itself, rather than using brightness values. The result is a unique visual representation of the kitten made entirely of circles. The tutorial also hints at the potential for using this technique with live video and suggests exploring creative image analysis methods to optimize circle placement for detailed areas of an image.

Takeaways

  • 🔄 The video is a continuation of a circle packing coding challenge, focusing on visualizing a generic image.
  • 🐾 The idea is to use a kitten image as a basis for circle packing, with the image being 800 by 800 pixels.
  • 🛠 The initial attempt to load the kitten image failed due to format issues, highlighting the need for image compatibility.
  • 🎨 The approach changes to placing circles randomly and using the color values directly from the kitten image instead of seeding based on brightness.
  • 📝 The script removes the concept of 'spots' and instead uses random values for circle placement, eliminating the need for a list of initial spots.
  • 🌈 A new 'color' variable is added to the circle object, and the circle creation process is updated to include this color.
  • 🔢 The script uses integer conversion for floating-point values of X and Y to correctly index into the image's pixel array.
  • 🖌️ The circles are filled with the color extracted from the image, and the stroke is removed for a cleaner look.
  • 🐱 The final result is a visualization of the kitten image made entirely of circles, demonstrating the effectiveness of the circle packing algorithm.
  • 🤔 The video suggests exploring creative ways to analyze the image for initial circle placement, such as using edge detection or other image properties.
  • 🔮 The idea of using live video for circle packing is introduced, prompting thoughts on how the algorithm would adapt to dynamic images.
  • 💡 The video concludes with an invitation for viewers to experiment with the coding challenge and hints at releasing JavaScript versions for browser compatibility.

Q & A

  • What is the main topic of the video script?

    -The main topic of the video script is the circle packing algorithm and its application in visualizing a generic image, specifically using a kitten image as an example.

  • What was the initial approach to circle packing in the previous part of the challenge?

    -The initial approach involved circle packing around letter formations, as demonstrated with the year '2017'.

  • Why did the speaker decide to change the circle seeding process?

    -The speaker decided to change the circle seeding process to place circles everywhere and pull the color value from the kitten image itself, instead of seeding circles based on brightness values.

  • What was the issue with using floating-point values for X and Y when accessing pixel colors?

    -The issue was that the index calculation required integer values, and using floating-point values for X and Y would not work with the image processing formula.

  • How did the speaker resolve the issue with floating-point values for X and Y?

    -The speaker resolved the issue by converting X and Y into integers using the int function before using them in the index calculation.

  • What was the purpose of adding a color variable to the circle object?

    -The purpose of adding a color variable was to store and fill the circles with the color values from the kitten image, rather than just using white circles.

  • What was the initial error encountered when the speaker tried to create a circle with a color argument?

    -The initial error was that the circle was expecting a color to be passed in, which was not provided at that point in the code.

  • How does the speaker suggest improving the circle placement algorithm?

    -The speaker suggests analyzing the image to place more initial circles where there is detail and fewer where there is little detail, allowing for larger and smaller circles to be grown as needed.

  • What creative methods does the speaker propose for seeding circle locations based on image properties?

    -The speaker proposes methods such as edge detection or other creative ways to determine where to seed circles based on the quality and properties of the image.

  • What is the speaker's plan for future releases related to this coding challenge?

    -The speaker plans to release JavaScript versions of the coding challenge for those who want to try it in the browser.

  • How does the speaker suggest using the circle packing algorithm with live video?

    -The speaker suggests that applying the circle packing algorithm to live video could be interesting and could lead to creative visual effects.

  • What is the target number of circles the speaker is trying to create in the demonstration?

    -The target number of circles the speaker is trying to create is ten.

Outlines

00:00

🎨 Circle Packing Algorithm with Image Visualization

The script introduces a follow-up to a previous coding challenge involving circle packing algorithms. The author proposes a new idea of visualizing a generic image using circle packing, starting with an example of packing circles around letter formations from a previous project. The focus shifts to using a kitten image, which is 800x800 pixels, as the basis for the circle packing. The initial attempt to load the image fails due to format issues, leading to a discussion on seeding circle locations based on brightness values and changing the approach to place circles randomly and pull color values directly from the kitten image. The script suggests removing the concept of 'spots' and restarting with random circle locations and sizes, and then adding a color variable to the circle object to store the color from the image. The author also discusses potential issues with floating-point values for X and Y coordinates and the need to convert them to integers to correctly sample the image's color. The summary concludes with a demonstration of the kitten image being represented by circles filled with colors from the original image, and the author invites viewers to consider creative ways to analyze images for more refined circle placement, hinting at edge detection or other image properties.

Mindmap

Keywords

💡Circle Packing

Circle packing is a geometric algorithm that involves arranging circles within a given space such that they touch each other but do not overlap. In the video, circle packing is used as a method to visualize an image by creating a pattern of circles that mimic the original image's shape and color distribution. The script discusses an algorithm for circle packing around letter formations and later around a kitten image.

💡Algorithm Visualization

Algorithm visualization refers to the process of making an algorithm's behavior or output visible and understandable through graphical representation. In the context of this video, the circle packing algorithm is visualized by applying it to an image, showing how the algorithm can be used to create a unique representation of the image's content.

💡Brightness Values

Brightness values in an image refer to the lightness or darkness of the pixels. In the video, the script mentions changing the circle seeding process to use brightness values as a basis for the circle locations, which means that the algorithm will consider the lightness or darkness of the image areas when deciding where to place the circles.

💡Color Value

Color value is the specific color information of a pixel in an image. The script describes a process where the color of each circle is determined by the color value of the corresponding pixel in the image. This is done by extracting the color from the kitten image and using it to fill the circles, creating a visual representation of the image using only circles.

💡Image Processing

Image processing is the application of mathematical algorithms to create a visual or functional representation of an image. The video script discusses using image processing techniques to extract color values from an image and to determine the placement of circles based on pixel brightness, which is a form of image analysis and manipulation.

💡Floating Point Values

Floating point values are a type of numerical data representation that can indicate fractional quantities. In the script, the author mentions that the X and Y coordinates for placing circles are floating point values, which need to be converted to integers to correctly index into the image's pixel array.

💡Pixel Indexing

Pixel indexing is the method of accessing individual pixels in an image based on their position. The script uses a formula to calculate the index for accessing the color of a specific pixel at a given X and Y coordinate. The formula is adapted to work with floating point values by converting them to integers.

💡Creative Seeding

Creative seeding refers to the initial placement of elements in a generative process, such as the placement of circles in the circle packing algorithm. The script suggests analyzing the image to place more initial circles in areas with detail and fewer in areas with less detail, allowing for a more refined representation of the image.

💡Edge Detection

Edge detection is a technique in image processing used to identify and highlight boundaries between different regions in an image. The script mentions edge detection as a potential method for determining where to seed circles based on the image's properties, which could lead to a more accurate and detailed circle packing representation.

💡Live Video

Live video refers to video content that is broadcast in real-time, without any delay. The script suggests the possibility of applying the circle packing algorithm to live video, which would involve dynamically creating a circle representation of the video content as it is being captured.

💡JavaScript

JavaScript is a programming language commonly used for web development, including creating interactive elements on web pages. The script mentions releasing JavaScript versions of the circle packing algorithm, indicating the intention to make the algorithm accessible for implementation in web browsers.

Highlights

Introduction to the continuation of the circle packing coding challenge with a focus on visualizing generic images.

The idea of loading an image, specifically a kitten image, and exploring its 800x800 size.

Encountering issues with the kitten image due to format incompatibility, 'kitten touch JPEG'.

Concept of changing the circle seeding process to place circles everywhere and pull color values from the image itself.

Elimination of the 'spots' concept from the previous circle packing algorithm.

Introduction of a new circle object with a color variable to store the color from the image.

Error handling when the circle object expects a color to be passed in during creation.

Method of obtaining color values from the image using a formula and converting X and Y coordinates to integers.

Visualization of circles with colors from the kitten image instead of white circles.

Demonstration of the kitten image recreated using colored circles.

Discussion on the potential of applying this technique to any image or live video.

Mention of the target number of circles and the observation of circle growth dynamics.

Suggestion to analyze the image for creative circle placement based on detail and color properties.

Proposal to investigate edge detection or other methods for intelligent circle seeding.

Hypothesis on the effects of applying the circle packing technique to live video.

Invitation for viewers to explore and create with the presented coding challenge.

Promise to release JavaScript versions for browser compatibility.

Closing remarks with music.

Transcripts

play00:00

hello welcome by back this is like sort

play00:02

of like a part two of my circle packing

play00:03

animated coding challenge thing because

play00:05

you know kittens I guess so uh what if

play00:10

we took that I think will be interesting

play00:11

to just look at the circle packing

play00:13

algorithm visualizing a generic image so

play00:16

if you recall where I left it last is

play00:19

it's kind of circle packing around the

play00:21

letter formations here we're seeing 2017

play00:25

but what if instead I were to load and

play00:28

let's go to this kitten image and let's

play00:32

look at what is the size of this kitten

play00:34

image it's 800 by 800 so let's make the

play00:37

window 800 by 800 what if I were to load

play00:41

this kitten image well if I run this we

play00:45

get a lot of things broken because it's

play00:48

kitten touch JPEG so if we run this we

play00:51

can see okay well I don't see the kitten

play00:54

so one of the things I want to change

play00:55

here is instead of drawing the circle

play00:59

seeding the circles locations based on

play01:03

brightness values I just want to like

play01:05

put circles everywhere and pull the

play01:07

color value from the kitten itself so a

play01:09

couple things I should change is one is

play01:11

we don't have this idea of spots anymore

play01:16

so I can get rid of this idea of a list

play01:19

of initial possible spots although I'll

play01:21

discuss why that might be interesting to

play01:23

bring back in and I just want the circle

play01:29

locations to go back to being a a random

play01:36

with value and a random height value and

play01:42

we don't need spots anymore the big

play01:46

difference here so there's this circle

play01:47

packing thing going on again the big

play01:49

difference here is I want the circle to

play01:53

store a color so I'm going to add a

play01:55

color variable to the circle object and

play01:58

when I create the circle I'm going to

play02:01

add another argument that I pass in for

play02:05

color I get an error here because the

play02:09

circle is expecting now a color to be

play02:10

passed in so what I need to do is I need

play02:13

to go

play02:13

and get from that image I need to create

play02:18

a color value and then pass that in so

play02:24

the question becomes what pixel do I

play02:27

look up well I want to look up the color

play02:29

for that X&Y point and the way that I do

play02:32

that is with this formula that I've used

play02:33

in countless image processing videos

play02:35

before where I say the index is X plus y

play02:38

times the images with now there's an

play02:42

issue here x and y are floating point

play02:45

values so this won't actually work but

play02:47

it will work if I just quickly convert X

play02:49

and y into integers using this int

play02:52

function and then I put that in here and

play02:55

now this runs and we see all these

play02:58

circles up but I need to use that color

play03:00

so what I need to do here is come back

play03:03

and say ah forget about a a white circle

play03:07

let's fill based on that color let's say

play03:11

no stroke and now if I run it we can see

play03:14

here is my kitten made with circles okay

play03:20

so you could do this with any image you

play03:22

could do this with live video it would

play03:24

be interesting and this is just one

play03:25

possible way of doing it you can also

play03:27

sort of think about I didn't really I

play03:29

don't remember what I last left this the

play03:32

target number of circles I'm trying to

play03:33

create I'm still trying to create ten so

play03:36

let's look at this actually what happens

play03:37

more slowly and we're going to get more

play03:39

bigger circles because they have more

play03:41

time to kind of grow and this leads me I

play03:43

think to an interesting point which is

play03:45

the how I'm where I'm putting the

play03:48

circles in the ultimate size of these

play03:50

circles is entirely completely random

play03:53

but you might think about what is the

play03:55

creative way you could analyze the image

play03:57

and place a lot of initial circles where

play04:00

there where there's detail in the image

play04:02

and place very few initial circles where

play04:04

there is no detail in little detail in

play04:07

the image so that you grow larger

play04:09

circles and smaller circles for the

play04:11

points where you need to refine to have

play04:13

refine

play04:14

color and and and vice versa so I think

play04:18

that is something that I would love to

play04:22

to investigate you could probably think

play04:25

of like edge detection or other ways

play04:26

what are some other

play04:27

creative ways that you can figure out

play04:29

where to seed the circles based on based

play04:34

on the quality and the properties of the

play04:39

image itself and then if you do that

play04:41

with live video what would happen there

play04:42

so I hope you enjoyed this little

play04:46

addendum in a way it's a second coding

play04:47

challenge and that you make something

play04:48

with this and I'll try to also remember

play04:50

to release JavaScript versions of these

play04:52

for those who you want to try this stuff

play04:53

run it in the browser okay thanks for

play04:55

watching

play04:56

[Music]

Rate This

5.0 / 5 (0 votes)

Related Tags
Circle PackingImage ProcessingCoding ChallengeAlgorithm VisualizationCreative CodingInteractive ArtJavaScriptPixel AnalysisAnimationWeb Development