在处理过程中重绘当前像素周围的选定像素区域



我是处理新手。 我正在尝试更改每个像素周围像素的颜色(或其他参数,如色调、饱和度等(。

我没有得到任何改变,而不是想要的结果。请帮助任何人(+(

PImage imgg;
void setup() {
size(250,166);  
imgg = loadImage("input.jpg");
loadPixels();
image(imgg,0,0);
}
void draw() {
for (int i = 0; i < imgg.width; i++) {
for (int j = 0; j < imgg.height; j++) {
//get the brightness value of the current pixel
int Bright_coeff = int(brightness(pixels[j*imgg.width+i]));
//calculate the area around the current pixel
int Bright_dist = Bright_coeff/10  ;
//area around that pixel will update its color
for (int x = 0; x < imgg.width; x++ ){
for (int y = 0; y < imgg.height; y++){
//check if the distance between iterating pixels and current pixel from above cycle is less than Bright_dist
if ( dist(x, y, i, j)<Bright_dist ){
color qwerty = color(random(1,255),random(1,255),random(1,255)) ;
pixels[y*imgg.width+x] = qwerty;
updatePixels();
}else {
updatePixels();
}
}
}    
}
}
}

loadPixels()加载当前显示窗口的像素数据。
loadPixels必须完成,在图像被image()绘制到窗口后:

PImage imgg;
void setup() {
size(128,128);  
imgg = loadImage("input.jpg");
image(imgg,0,0);
loadPixels();
}

执行draw()后,显示仅更新一次。updatePixels()设置显示窗口的像素数据。在draw()结束时这样做就足够了:

void draw() {
// [...]
updatePixels();
}

最新更新