Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #1001445 // toGrayScale

JavaX fragment (include)

1  
static RGBImage toGrayScale(RGBImage img, int bits) {
2  
  int steps = 1 << bits;
3  
  int w = img.getWidth(), h = img.getHeight();
4  
  RGBImage bw = new RGBImage(w, h);
5  
  for (int y = 0; y < h; y++)
6  
    for (int x = 0; x < w; x++) {
7  
      float b = img.getPixel(x, y).getBrightness();
8  
      int bx = (int) (b*steps);
9  
      double b2 = Math.min(1f, Math.max(0f, bx/(float) steps));
10  
      bw.setPixel(x, y, new RGB(b2));
11  
    }
12  
  return bw;
13  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001445
Snippet name: toGrayScale
Eternal ID of this version: #1001445/1
Text MD5: e348ea765c17e5525734b94c038c9500
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-16 17:55:35
Source code size: 444 bytes / 13 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 636 / 874
Referenced in: [show references]