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 (11471L/67K).

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(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/27
Text MD5: 5ec4cf95e8427fca719838c8e6dcf336
Transpilation MD5: 8c0362d0e605a1b831666db340fd6ffd
Author: stefan
Category: javax / image recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-26 21:36:51
Source code size: 1803 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 214 / 632
Version history: 26 change(s)
Referenced in: [show references]