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

35
LINES

< > BotCompany Repo | #1019597 // scaleDownUsingIntegralImageBW (can also scale up)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6186L/37K).

1  
static BWImage scaleDownUsingIntegralImageBW(int w, BWIntegralImage img) {
2  
  ret scaleDownUsingIntegralImageBW(img, w);
3  
}
4  
5  
static BWImage scaleDownUsingIntegralImageBW(BWIntegralImage img, int w) {
6  
  ret scaleDownUsingIntegralImageBW(img, w, iround(w*img.h/(double) img.w));
7  
}
8  
9  
static BWImage scaleDownUsingIntegralImageBW(BWIntegralImage img, int w, int h) {
10  
  int w1 = img.w, h1 = img.h;
11  
  BWImage out = new(w, h);
12  
  for y to h:
13  
    for x to w: {
14  
      int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w);
15  
      int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h);
16  
      int area = (x2-x1)*(y2-y1);
17  
      int pixel = bwIntegralImage_sumRect(img, x1, y1, x2, y2)/area;
18  
      out.setByte(x, y, (byte) pixel);
19  
    }
20  
  ret out;
21  
}
22  
23  
static BWImage scaleDownUsingIntegralImageBW(IBWIntegralImage img, int w, int h default iround(w*img.getHeight()/(double) img.getWidth())) {
24  
  int w1 = img.getWidth(), h1 = img.getHeight();
25  
  BWImage out = new(w, h);
26  
  for y to h:
27  
    for x to w: {
28  
      int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w);
29  
      int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h);
30  
      int area = (x2-x1)*(y2-y1);
31  
      int pixel = bwIntegralImage_sumRect(img, x1, y1, x2, y2)/area;
32  
      out.setByte(x, y, (byte) pixel);
33  
    }
34  
  ret out;
35  
}

Author comment

Began life as a copy of #1019590

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1019597
Snippet name: scaleDownUsingIntegralImageBW (can also scale up)
Eternal ID of this version: #1019597/11
Text MD5: ea99cc2c8a471c0be393a37c3c2951b4
Transpilation MD5: fc03f30d392c4cf8b540295c73dea3a4
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-06 18:28:50
Source code size: 1258 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 404 / 544
Version history: 10 change(s)
Referenced in: [show references]