classCol{floatr;floatg;floatb;Col(floatr_,floatg_,floatb_){r=r_;g=g_;b=b_;}}size(900,476);PImageimg;intmax=(height-1)+(width-1)*width;//int[] colors = new int[width*height];color[]colors=newcolor[width*height];ArrayList<Col>sorted_colors=newArrayList<Col>();img=loadImage("starry.jpg");loadPixels();// We must also call loadPixels() on the PImage since we are going to read its pixels.img.loadPixels();for(inty=0;y<height;y++){for(intx=0;x<width;x++){intloc=x+y*width;// The functions red(), green(), and blue() pull out the three color components from a pixel.floatr=red(img.pixels[loc]);floatg=green(img.pixels[loc]);floatb=blue(img.pixels[loc]);colors[loc]=color(r,g,b);}}for(intj=0;j<colors.length;j++){floatr=red(colors[j]);floath=int(saturation(colors[j]));floatg=green(colors[j]);floatb=blue(colors[j]);sorted_colors.add(newCol(r,g,b));}colorcol=color(0,0,0);floatar=0;floatag=0;floatab=0;intcounter=0;for(inti=0;i<sorted_colors.size();i++){if(counter==width){ar=ar/width;ag=ag/width;ab=ab/width;counter=0;intk=i-width;for(intj=k;j<i;j++){pixels[j]=color(ar,ag,ab);}}if(counter==0){ar=0;ag=0;ab=0;}counter+=1;ar+=sorted_colors.get(i).r;ag+=sorted_colors.get(i).g;ab+=sorted_colors.get(i).b;}updatePixels();