public FImage2D invert() { FImage2D r = new FImage2D( xsize, ysize ); int i = 0, j = 0 ; while(i < xsize && j < ysize){ r.set(i,j,255 - get(i,j)); i++; j++; // Enumerate all (i,j) in the 'r' image // and set r(i,j) = 255 - image(i,j) // here should be your code } return r; }