-1

Suppose I had a PNG image like this: https://www.box.com/s/dc4dut3yw1vhagm4y9ks

And I want to increase the red dots size which means, they have to fill their square neighbors too. Like below:

www -> rrr

wrw -> rrr

www -> rrr

Amir
  • 1,087
  • 1
  • 9
  • 26

1 Answers1

1

I'm pretty sure this can be further optimized... basicly it loads the image twice, im1 and draw1 are read, if a red dot is found there in draw2 in range [x+-1, y+-1] is changed. Finaly im2 made from draw2 is saved.

#!/usr/bin/env python

import Image

im1 = Image.open("hil0.png")
im2 = Image.open("hil0.png")
w, h = im1.size

draw1 = im1.load()
draw2 = im2.load()

for x in range(w):
    for y in range(h):
        if draw1[x,y] == (255,0,0):
            for dx in [-1,0,1]:
                for dy in [-1,0,1]:
                    nx = x+dx
                    ny = y+dy
                    # print nx, ny
                    if nx>=0 and ny>=0 and nx<w and ny<h:
                        draw2[ nx, ny ] = (255,0,0)



# im2.show()
im2.save("hil1.png")
max.haredoom
  • 848
  • 8
  • 7