Use sort() in PImage to reorder pixels
in
Programming Questions
•
10 months ago
hi, i try to use sort on a Pimage to reorder pixels, pixels organised by their brightness values.
i dont know if the use of map is correct in this way.
On this case i get array out of bounds exception
why
is it because my int pixnumb (number of pixels) are not the same than loc (x+y*width)?
could you give me a little explication?
///////////////////////////////////////////////////////////
PImage img;
float[] order;
int pixnumb;
void setup() {
size(800, 500);
img=loadImage("333.jpg");
img.resize(800, 500);
pixnumb=800*500;
}
void draw() {
loadPixels();
img.loadPixels();
for (int y = 0; y<height;y++) {
for (int x=0; x<width;x++) {
for (int i = 0 ; i<pixnumb;i++) {
int loc = x+y*width;
order=new float[loc];
color c = int(brightness(img.get(x, y)));
order[i]= brightness(img.get(x, y));
order=sort(order);
color c2 = int(order[i]);
pixels[loc]=color(c2);
}
}
}
updatePixels();
}
1