1

I have seen an image of a girl which is made up of multiple images of her.So I want to achieve the same thing using a python script.(I am completely new to image processing)

I am using pil library for this script.

import sys,os
from PIL import Image
img = Image.open("DSC_0149.jpg")
pixels = img.load()
for i in range(img.size[0]):   
    for j in range(img.size[1]):
        pixels[i,j] = (i, j, 100) # I will change this to some pic image.
img.show()

I am trying first just to change the colour of pixel retaining the pic,But this code dint work.

Can anyone guide me how to achieve it.

Edit : I want to fill the picture with multiple pictures and yet RETAIN the original picture. Something like this : http://www.photoshopessentials.com/photo-effects/photo-fill/ but in a much better way.

user3425344
  • 3,357
  • 4
  • 20
  • 31
  • Plase, attach an image with an example of your desired final effect. It seens like you want something so different of what you are currently putting in words and code, that people can't answer. – jsbueno May 26 '16 at 17:57
  • @jsbueno Please see the link http://www.photoshopessentials.com/photo-effects/photo-fill/ But this is not very perfect. – user3425344 May 26 '16 at 18:14

2 Answers2

0

So first you need to edit each pixel with this to change the color:

If it is rgb:

img.putpixel((10,15),(r,g,b))

or

faster: pixels[1, 1] = (r, g, b)

otherwise:

Is it possible to change the color of one individual pixel in Python?

After knowing how to edit each pixel you have to create a small copy of your image with a resize like this:

Copy Image:

// Not tested : Make sure it's rgb
img = Image.new( 'RGB', (img.size[0],(img.size[1]), "black") # create a new black image
pixels = img.load() # create the pixel map

for i in range(img.size[0]):    # for every pixel:
    for j in range(img.size[1]):
        pixels[i,j] = other_image_pixel[i,j] # set the colour accordingly

https://opensource.com/life/15/2/resize-images-python

Apply a Color filter to each small image to match the area color you will replace with this image.

Community
  • 1
  • 1
Destrif
  • 2,104
  • 1
  • 14
  • 22
  • But if I change the value of each pixel, the shape of original picture is not retained.I want to fill the entire pic with different pics RETAINING the original picture. – user3425344 May 26 '16 at 09:59
  • Steps: Copy beginning Image, resize copy, add filter to subimage(copy) to fit beggining image, finally fill current image with each subimage. – Destrif May 26 '16 at 10:05
  • But how do I ''Fill" current image with subimage? I just cant simply change the value of each pixel since that will not retain the persons face in current image. – user3425344 May 26 '16 at 17:26
  • You will set(fill) each pixel-group of the biginning image, with the sub-Image. You do not need to keep the beginning image, since you have a small copy of it that when assembled will represent the big one. Imagine it like a puzzle where each puzzel peace is the sub-image with a filter. You do not keep the big picture since, you have each part of the puzzle that will create it. – Destrif May 27 '16 at 07:09
0

The best way to understand the whole process is to take time to read this code in the same language, it's around 200 lines:

https://github.com/codebox/mosaic

Hope it solve your problems

Destrif
  • 2,104
  • 1
  • 14
  • 22