java - how to quantize the image to MxN blocks -


certainly, writing program image ascii conversion. have convert image grayscale, don't know write code of quantizing image mxn blocks

  1. for every sub-image of mxn size, compute average gray value
  2. store computed average gray value new image).

here program:

public static char[][] imagetoascii(image img, int blockwidth, int blockheight) {     {         // convert image type image bufferedimage         bufferedimage bufimg = convert(img);          // scan through each row of image         for(int j=0; j<bufimg.getheight(); j++)         {             // scan through each columns of image             for(int i=0; i<bufimg.getwidth(); i++)             {                 // returns integer pixel in default rgb color model                 int values=bufimg.getrgb(i,j);                 // convert single integer pixel value rgb color                 color oldcolor = new color(values);                  int red = oldcolor.getred();        // red value                 int green = oldcolor.getgreen();    // green value                 int blue = oldcolor.getblue();  // blue value                  // convert rgb grayscale using formula                 // gray = 0.299 * r + 0.587 * g + 0.114 * b                 double grayval = 0.299*red + 0.587*green + 0.114*blue;                  // assign each channel of rgb same value                 color newcolor = new color((int)grayval, (int)grayval, (int)grayval);                  // integer representation of rgb color                 // , assign original position             bufimg.setrgb(i, j, newcolor.getrgb());          }                return null; 

maybe need divide image blocks of mxn size. similar microblock in video coding.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -