Nov-20-2019, 05:08 PM
(This post was last modified: Nov-20-2019, 08:52 PM by DreamingInsanity.)
I have a folder full of images that I crop to a certain size (100x100 in this case) then I average the colour of the images.
Now for a bit of logic (this is where I might have gone wrong):
If I have an image of which the size is
See, if the image is 567 pixels wide, and each one is scaled by 100, it should become 56,700 pixels wide right? Well, it does. And that would mean each pixel position -
However, for some reason, each image I paste seems to be much smaller than it should be.
Let me use the exact image I am using now - it is 768x432, meaning with images pixels 'scaled by 100' it would become 76800x43200, and each pixel is now an entire image. But this is the output I actually get:
![[Image: J6bvFJ4.png]](https://i.imgur.com/J6bvFJ4.png)
It seems like each image is so much smaller - but according to my logic, there should be no empty space because the images should fill up the whole 'canvas'. Why is going on? Why are the pasted images so small?
Cropping code:
Pasting code:
Now for a bit of logic (this is where I might have gone wrong):
If I have an image of which the size is
567,376
and I make the pixels '100 times bigger' - I am actually replacing each pixel with one of the images that I cropped previously, which is technically scaling each pixel 100 times bigger - that in turn would make the image 100 times bigger.See, if the image is 567 pixels wide, and each one is scaled by 100, it should become 56,700 pixels wide right? Well, it does. And that would mean each pixel position -
[0,0], [0,1], [0,2], [0,3]
- would be 100 times larger - [0,0], [0,100], [0,200] ,[0,300]
At each of these new values, if I pasted a 100x100 image, after enough images it should fill up the new image entirely (after 567 images exactly - 567*100=56700)However, for some reason, each image I paste seems to be much smaller than it should be.
Let me use the exact image I am using now - it is 768x432, meaning with images pixels 'scaled by 100' it would become 76800x43200, and each pixel is now an entire image. But this is the output I actually get:
![[Image: J6bvFJ4.png]](https://i.imgur.com/J6bvFJ4.png)
It seems like each image is so much smaller - but according to my logic, there should be no empty space because the images should fill up the whole 'canvas'. Why is going on? Why are the pasted images so small?
Cropping code:
1 2 3 4 5 6 7 8 9 10 |
width, height = img.size #get dimensions crop_size = 100 if (crop_size > width or crop_size > height): #if image is too small to be cropped img.close() #just close it left = (width - crop_size) / 2 #crop from centre out top = (height - crop_size) / 2 right = (width + crop_size) / 2 bottom = (height + crop_size) / 2 try : #if the image was closed, it cant perform operations so the error will need to be caught img = img.crop((left, top, right, bottom)) |
1 2 3 4 5 6 7 8 |
to_make = Image. open (options[ 'to_create' ]) #open the image user wants to recreate img = Image.new( 'RGB' , (to_make.width * 100 , to_make.height * 100 ), color = ( 0 , 0 , 0 )) #create the new image for x in range ( 0 ,to_make.width): for y in range ( 0 ,to_make.height): pix_col = to_make.getpixel((x, y)) #get the pixel color closest = find_closest(pix_col, rgb) #find the closest matching image to the color of the pixel on the image a = Image. open (links[rgb.index(closest)]) #gets the path to the image using the rgb colour img.paste(a, (x * to_make.width, y * to_make.height)) #pastes image at 100,100 rather than 1,1 otherwise there will be overlap |