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

96
LINES

< > BotCompany Repo | #1031932 // URecognizer [backup with xClip, yClip]

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

Libraryless. Click here for Pure Java version (7002L/40K).

sclass URecognizer {
  IIntegralImage image;
  
  *() {}
  *(IIntegralImage *image) {}
  *(BufferedImage image) {
    this.image = IntegralImage(image);
  }
  
  // returns 0, 1 or 2
  int posterizeToInt(double x) {
    ret ifloor(clampZeroToOne(x)*3);
  }

  // returns 0, .5 or 1
  double posterizeInPlace(double x) {
    ret posterizeToInt(x)*.5;
  }
  
  class Cell {
    // Original image and which part we are looking at
    DoubleRange xClip, yClip;
  
    // color transformations in place
    DoubleRange[] colorClips = new[3];
  
    Cell copy() {
      new Cell c;
      c.xClip = xClip;
      arrayCopy(colorClips, c.colorClips);
      ret c;
    }
  
    Rect rectInImage() {
      ret toRect_floor(doubleRectFromRanges(xClip, yClip));
    }
  
    // get color of cell
  
    double color(int channel) {
      double color = ii_averageBrightnessOfArea(image, rectInImage(), channel);
      ret transformBetweenDoubleRanges(color, colorClips[channel], zeroToOne());
    }
    
    // unposterized color of all 3 channels
    double[] color() {
      double[] c = new[3];
      for i to 3:
        c[i] = color(i);
      ret c;
    }
    
    toString {
      ret "Color: " + asList(color());
    }
  
    int posterizedIntColor(int channel) {
      ret posterizeToInt(color(channel));
    }
  
    // get sub-cells
  
    Cell[] xSplit() {
      Cell[] cells = new[3];
      for i to 3: cells[i] = xSlice(i/3.0, (i+1)/3.0);
      ret cells;
    }
  
    Cell xSlice(double a, double b) {
      Cell c = copy();
      c.xClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), xClip);
      ret c;
    }
    
    Cell[] ySplit() {
      Cell[] cells = new[3];
      for i to 3: cells[i] = ySlice(i/3.0, (i+1)/3.0);
      ret cells;
    }
  
    Cell ySlice(double a, double b) {
      Cell c = copy();
      c.yClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), yClip);
      ret c;
    }
  }

  // make the root cell
  Cell rootCell() {
    new Cell c;
    c.xClip = doubleRange(0, image.getWidth());
    c.yClip = doubleRange(0, image.getHeight());
    for i to 3: c.colorClips[i] = doubleRange(0, 255);
    ret c;
  }
}

Author comment

Began life as a copy of #1031930

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031932
Snippet name: URecognizer [backup with xClip, yClip]
Eternal ID of this version: #1031932/4
Text MD5: b77a8c251349350772ec73df8563e83f
Transpilation MD5: 5a8a19dc832fd7f4b08a1ba9c61a50bd
Author: stefan
Category: javax / image recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-02 05:24:02
Source code size: 2258 bytes / 96 lines
Pitched / IR pitched: No / No
Views / Downloads: 78 / 129
Version history: 3 change(s)
Referenced in: [show references]