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

23
LINES

< > BotCompany Repo | #1025285 // scaledBufferedImageFromIntegralImage_direct (slower than the non-direct version)

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

Libraryless. Click here for Pure Java version (5277L/34K).

static BufferedImage scaledBufferedImageFromIntegralImage_direct(int w, IntegralImage img) {
  ret scaledBufferedImageFromIntegralImage_direct(img, w);
}

static BufferedImage scaledBufferedImageFromIntegralImage_direct(IntegralImage img, int w) {
  ret scaledBufferedImageFromIntegralImage_direct(img, w, rowsForColsWithAspectRatio(w, img.w, img.h));
}

static BufferedImage scaledBufferedImageFromIntegralImage_direct(IntegralImage img, int w, int h) {
  int w1 = img.w, h1 = img.h;
  BufferedImage out = newBufferedImage(w, h);
  for y to h:
    for x to w: {
      int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w);
      int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h);
      int area = (x2-x1)*(y2-y1);
      int r = integralImage_sumRect(img, x1, y1, x2, y2, 0)/area;
      int g = integralImage_sumRect(img, x1, y1, x2, y2, 1)/area;
      int b = integralImage_sumRect(img, x1, y1, x2, y2, 2)/area;
      out.setRGB(x, y, (r << 16) | (g << 8) | b);
    }
  ret out;
}

Author comment

Began life as a copy of #1025282

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025285
Snippet name: scaledBufferedImageFromIntegralImage_direct (slower than the non-direct version)
Eternal ID of this version: #1025285/4
Text MD5: 594c19b275fd30f5865ce77a833885b4
Transpilation MD5: 374338a7d66ddd115a7d391b58778e31
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-18 15:05:04
Source code size: 987 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 243 / 331
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)