There is a topic on processinghacks about
dynamic window size.
Size needs to be the first command you mention at the beginning of setup(). That's just unfortunately the way it works because size() is a special method. Furthermore, there should be no second call of draw(), you've specified noLoop(): the code in draw() will only be executed once.
Most of your operations on the image you are loading can be done off screen. I put an example below of how this can be done.
Code:
PImage pimage;
void setup() {
size(400, 400);
smooth();
for(int i = 0; i < width; i += 6){
ellipse(i, i, i, i);
}
loadPixels();
pimage = new PImage(width, height);
//the next method copies the screen into pimage
pimage.copy(g, 0, 0, width, height, 0, 0, pimage.width, pimage.height);
}
void draw() {
image(pimage, 0, 0);
}
void mousePressed(){
for(int i = 0; i < pimage.pixels.length; i++){
pimage.pixels[i] = color(255 - red(pimage.pixels[i]));
}
pimage.updatePixels();
}