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

41
LINES

< > BotCompany Repo | #1033676 // scaledGrayBytesFromBWIntegralImage

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

Libraryless. Click here for Pure Java version (13149L/76K).

meta-for BWIntegralImage also as IBWIntegralImage {

  static byte[] scaledGrayBytesFromBWIntegralImage(int w, BWIntegralImage img) {
    ret scaledGrayBytesFromBWIntegralImage(img, w);
  }
  
  static byte[] scaledGrayBytesFromBWIntegralImage(BWIntegralImage img, int w, int h default heightForWidth(img, w)) {
    int w1 = img.getWidth(), h1 = img.getHeight();
    double stepX = doubleRatio(w1, w), stepY = doubleRatio(h1, h);
    byte[] pixels = new[w*h];
    int i = 0;
    double srcY = 0;
    
    if (stepX == 1 && stepY == 1) {
      // No scaling
      
      for y to h:
        for x to w: {
          int pixel = img.getPixelBrightness(x, y);
          pixels[i++] = clampToUByte(pixel);
        }
    } else {
      // With arbitrary scaling
      
      for y to h: {
        double srcX = 0, nextSrcY = srcY+stepY;
        
        for x to w: {
          double nextSrcX = srcX+stepX;
          int pixel = iround(img.getPixelAverage(srcX, srcY, nextSrcX, nextSrcY));
          pixels[i++] = clampToUByte(pixel);
          srcX = nextSrcX;
        }
        srcY = nextSrcY;
      }
    }
    
    ret pixels;
  }

}

Author comment

Began life as a copy of #1033440

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033676
Snippet name: scaledGrayBytesFromBWIntegralImage
Eternal ID of this version: #1033676/5
Text MD5: f38e44871bd093087bb2a56c7091d3c2
Transpilation MD5: 0620d3650c5f1926b87cb43f00baddc3
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-26 03:54:02
Source code size: 1173 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 75 / 134
Version history: 4 change(s)
Referenced in: [show references]