DEV Community

Discussion on: NFT images generator using Python Jupyter Notebook

Collapse
 
victorquanlam profile image
Victor Quan Lam

May I know how many images you put into your background, circle and square folder? thanks

Collapse
 
aminassianse profile image
Armen Minassian

I just have two of each.

backgrounds (folder name)
-> blue.png
-> orange.png
circles
-> blue-circle.png
-> orange-circle.png
squares
-> blue-square.png
-> orange-square.png

Thread Thread
 
victorquanlam profile image
Victor Quan Lam

Ok. Can you try to reduce the total images down to 8?

Thread Thread
 
aminassianse profile image
Armen Minassian

Reduce to 8? I only have 6 total images. blue.png, orange.png (background pics), two circles and two squares. Six total images.

Thread Thread
 
aminassianse profile image
Armen Minassian

Oh I see what you meant. I reduced it to 8 and It worked. What can I do to generate more images though? I mean the goal is generate a couple thousand images.

Thread Thread
 
aminassianse profile image
Armen Minassian

Could you explain the way the weights work?

Thread Thread
 
victorquanlam profile image
Victor Quan Lam • Edited

You can add different colours and shapes (rectangle, star) to generate more images to get familiar. A good practice would be having different characters with a set of variation. For instance:
different

Furthermore, you can add more colours to create more images according to the following example.

rarity

[shape]_weights should be added up to 100 (optional) and the less the shape weights the less likely it will be populated.

\\ random.choices(your list, weights) is the method that returns a list with the randomly selected element from the specified sequence. [weights] is the possibility for each value.
new_image ["Circle"] = random.choices(circle, circle_weights)[0]
Enter fullscreen mode Exit fullscreen mode


`

Thread Thread
 
aminassianse profile image
Armen Minassian

background = ["Blue", "Orange"]
background_weights = [30, 40]

circle = ["Blue", "Orange"]
circle_weights = [30, 15]

square = ["Blue","Orange"]
square_weights = [30, 15]

turtle = ["Blue","Orange"]
turtle_weights = [30,15]

For example I added a new attribute called turtle above ^. But when the composite is formed the result images are only of the turtle and it doesn't include any of the orange or blue backgrounds or squares and circles.

Thread Thread
 
victorquanlam profile image
Victor Quan Lam • Edited

Can you try to add a new composite? It will let the processor know which combination of shapes you want to generate.

for item in all_images:

    im1 = Image.open(f'./layers/backgrounds/{background_files[item["Background"]]}.jpg').convert('RGBA')
    im2 = Image.open(f'./layers/circles/{circle_files[item["Circle"]]}.png').convert('RGBA')
    im3 = Image.open(f'./layers/squares/{square_files[item["Square"]]}.png').convert('RGBA')

// add this line of code
    im4 = Image.open(f'./layers/squares/{square_files[item["Turtle"]]}.png').convert('RGBA')

    #Create each composite
    com1 = Image.alpha_composite(im1, im2)
    com2 = Image.alpha_composite(com1, im3)

// add new combination 3
com3 = Image.alpha_composite(com2, im4 )

    #Convert to RGB
    rgb_im = com3.convert('RGB')
Enter fullscreen mode Exit fullscreen mode


`

You can use for statement to handle this process better. something like this
`

for shape in shapeList:
    // generate rgb_img....
Enter fullscreen mode Exit fullscreen mode


`