# Trouble with changing pixel colors

**URL:** <https://discourse.processing.org/t/trouble-with-changing-pixel-colors/18361>\
**Category:** Processing.py\
**Created:** [March 3, 2020, 7:13pm UTC](https://discourse.processing.org/t/trouble-with-changing-pixel-colors/18361 "2020-03-03T19:13:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cupofcalculus](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@cupofcalculus](https://discourse.processing.org/u/cupofcalculus)\
**Post date:** [March 3, 2020, 7:13pm UTC](https://discourse.processing.org/t/trouble-with-changing-pixel-colors/18361/1 "2020-03-03T19:13:09Z")

</div>

I’m wanting to edit individual pixel values. Checking my code as I go, I tested to see if it would copy the top and bottom rows of pixels, and ignore everything else. But instead I got a copy of the entire picture. What am I not understanding about the python version of Processing?

Basic code structure:

```auto
fname = 'picture.png'
img = [0]*2 # used to initialize a 2 slot array
imgIndex = 0

def setup():
  size(500, 500)
  this.surface.setResizable(True)
  img[0] = loadImage(fname)
  this.surface.setSize(img[0].width, img[0].height)
  img[1] = convolve(img[0])

def draw():
  image(img[imgIndex], 0, 0)

def convolve(source, kernel):
  target = createImage(source.width, source.height, RGB)
  for y in range(source.height):
      for x in range(source.width):
          c = source.get(x, y)
          if y in [0, source.height - 1]:
              target.set(x, y, c)
  return target

def keyReleased():
    global imgIndex
    if key == '0':
        imgIndex = 0
    elif key == '1':
        imgIndex = 1

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 3, 2020, 7:22pm UTC](https://discourse.processing.org/t/trouble-with-changing-pixel-colors/18361/2 "2020-03-03T19:22:18Z")

</div>

We need **background()** in **draw()** in order to clear the canvas each frame: 😉  
[Py.Processing.org/reference/background.html](http://Py.Processing.org/reference/background.html)
