# Fast Pixel by Pixel Image Editing

**URL:** <https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876>\
**Category:** Coding Questions\
**Created:** [June 14, 2020, 10:09pm UTC](https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876 "2020-06-14T22:09:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [June 14, 2020, 10:09pm UTC](https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876/1 "2020-06-14T22:09:35Z")

</div>

I have an array of PImages upscaledImages[] pulled from a folder

How would I:

- Edit Individual pixel’s based on their contents
- Save the array of edited images, overwriting the unedited ones

All of this needs to be done in a semi-efficient manner because I am working with a lot of images

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 14, 2020, 11:08pm UTC](https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876/2 "2020-06-14T23:08:24Z")

</div>

Hi,

I think this is the way to go without using any arrays :

```auto
// The number of images
int nbImages = 50;

// Go through every image
for (int i=0; i<nbImages; i++) {
  // Load it (assuming that their names are image###.png)
  String filename = "image" + i + ".png";
  PImage img = loadImage(filename);
  
  // Loop through every pixels
  img.loadPixels();
  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y<img.height; y++) {
      int loc = x + y * img.width;
      
      // Do something with the pixel
      img.pixels[loc] = ...;
    }
  }
  img.updatePixels();
  
  // Override the image
  img.save(filename);
}

```

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [June 14, 2020, 11:45pm UTC](https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876/3 "2020-06-14T23:45:14Z")

</div>

How would I get the alpha value of the pixel at img.pixels[loc]

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 14, 2020, 11:47pm UTC](https://discourse.processing.org/t/fast-pixel-by-pixel-image-editing/21876/4 "2020-06-14T23:47:37Z")

</div>

Looking at the [Processing reference](https://processing.org/reference) is really handy 🙂 what you need is :

- [https://processing.org/reference/alpha\_.html](https://processing.org/reference/alpha_.html)

And also this nice tutorial on images and pixels by _Daniel Shiffman_ :

- [https://processing.org/tutorials/pixels/](https://processing.org/tutorials/pixels/)
