# Pixel Sorting with threshold

**URL:** <https://discourse.processing.org/t/pixel-sorting-with-threshold/17462>\
**Category:** Coding Questions\
**Created:** [January 30, 2020, 5:29pm UTC](https://discourse.processing.org/t/pixel-sorting-with-threshold/17462 "2020-01-30T17:29:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexx](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@Alexx](https://discourse.processing.org/u/Alexx)\
**Post date:** [January 30, 2020, 5:29pm UTC](https://discourse.processing.org/t/pixel-sorting-with-threshold/17462/1 "2020-01-30T17:29:57Z")

</div>

Hi. I’m new to Processing. Hope someone is able to help me.

In my sketch the pixel sorting work on width, but I I need it to be vertical non horizontal … how?

Thank you.

This is the code:

```auto
int mode = 0;

int threshold;

PImage img;

String fileType = “jpg”;

void setup() {

img = loadImage(“Tree.jpg”);
size(1200, 675);
image(img, width, height);
frameRate(60);

}

void draw() {
img.loadPixels();

for (int k=height; k<height*width; k++) {
if (threshold < 150000) {
if (brightness(img.pixels[k]) > threshold) {
img.pixels[k] = color(
int(red(img.pixels[height])),
int(green(img.pixels[height])),
int(blue(img.pixels[height])));
}

  else {
    img.pixels[height] = color(
    int(red(img.pixels[k-1])),
    int(green(img.pixels[k-1])),
    int(blue(img.pixels[k-1])));
  }
  threshold = threshold+10;
}

  else {
  threshold = 0;
}

}

img.updatePixels();
image(img, 0, 0);
}

```

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [January 31, 2020, 8:39am UTC](https://discourse.processing.org/t/pixel-sorting-with-threshold/17462/2 "2020-01-31T08:39:26Z")

</div>

Hi @Alexx  
I changed the quotation marks around the strings but then I get a problem with

```auto
    if (threshold < 150000) { //150000
      if (brightness(img.pixels[k]) > threshold) {

```

This throws up: ArrayIndexOutOfBoundsException: 270000 Probably because `threshold` is not given a value (other than zero).

Do you want to isolate each vertical line of pixels in your image and then sort their positions based on brightness? If so, you might this helpful: [https://processing.org/tutorials/pixels/](https://processing.org/tutorials/pixels/)

The tutorial includes this example [http://learningprocessing.com/examples/chp15/example-15-08-Brightness](http://learningprocessing.com/examples/chp15/example-15-08-Brightness)
