for(int x = 1; x < w-1; x++) { for(int y = 1; y < h-1; y++) { for(int z = 1; z < d-1; z++) { if(isExtrema(x,y,z)) { //... }}}}