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

55
LINES

< > BotCompany Repo | #1027205 // IBWIntegralImage

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

Libraryless. Click here for Pure Java version (12542L/73K).

sinterface IBWIntegralImage extends MakesBufferedImage, IBWImage, IMeta {
  public int getWidth();
  public int getHeight();
  
  // implement one of the following two methods!
  
  // integer version (both coordinates & brightnesses are ints)
  public default int getIIValue(int x, int y) {
    ret iround(getIIValue((double) x, (double) y));
  }
  
  // floating point version (both coordinates & brightnesses are doubles)
  public default double getIIValue(double x, double y) {
    ret getIIValue(ifloor(x), ifloor(y));
  }
  
  // 0.0 to 255.0
  default public double getPixelAverage(int x1, int y1, int x2, int y2) {
    int area = (x2-x1)*(y2-y1);
    ret doubleRatio(getPixelSum(x1, y1, x2, y2), area);
  }
  
  default public dbl getPixelAverage(dbl x1, dbl y1, dbl x2, dbl y2) {
    dbl area = (x2-x1)*(y2-y1);
    ret doubleRatio(getPixelSum(x1, y1, x2, y2), area);
  }
  
  default public double getPixelAverage(Rect r) {
    ret getPixelAverage(r.x, r.y, r.x2(), r.y2());
  }
  
  default public int getPixelSum(int x1, int y1, int x2, int y2) {
    ret bwIntegralImage_sumRect(this, x1, y1, x2, y2);
  }
  
  default public double getPixelSum(double x1, double y1, double x2, double y2) {
    ret bwIntegralImage_sumRect(this, x1, y1, x2, y2);
  }
  
  default public int getPixelBrightness aka getInt(int x, int y) {
    ret getPixelSum(x, y, x+1, y+1);
  }
  
  default public int getPixelBrightness(Pt p) { ret getPixelBrightness(p.x, p.y); }
  
  public default BufferedImage getBufferedImage() {
    //ret scaleDownUsingIntegralImageBW(this, w).getBufferedImage();
    ret grayImageFromIBWIntegralImage(this);
  }
  
  // implementing IBWImage
  public default float getFloatPixel(int x, int y) {
    ret getPixelBrightness(x, y)/255f;
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1027205
Snippet name: IBWIntegralImage
Eternal ID of this version: #1027205/28
Text MD5: 99c4f06068b996d43ae2606eaf3ff0cf
Transpilation MD5: 8e3b942401575e1865a6af7c26d6907e
Author: stefan
Category: javax / image recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-06 21:11:38
Source code size: 1814 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 367 / 854
Version history: 27 change(s)
Referenced in: [show references]