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

14
LINES

< > BotCompany Repo | #1033573 // posterizeIBWImage

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

Libraryless. Click here for Pure Java version (127L/1K).

static IBWImage posterizeIBWImage(int brightnessLevels, IBWImage img) {
  if (brightnessLevels >= 256 || img == null) ret img;
  int w = img.getWidth(), h = img.getHeight();
  
  ret new IBWImage {
    public int getWidth() { ret w; }
    public int getHeight() { ret h; }
    
    public float getFloatPixel(int x, int y) {
      ret (float) quantizeToNLevelsBetweenZeroAndOne_stretch(
        brightnessLevels, img.getFloatPixel(x, y));
    }
  };
}

Author comment

Began life as a copy of #1022982

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1033573
Snippet name: posterizeIBWImage
Eternal ID of this version: #1033573/3
Text MD5: 293852658bc2e9e49f0dcaba481647ff
Transpilation MD5: 2da8b067a2cc25769885a5cfcd2fba04
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-03 20:04:38
Source code size: 464 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 147 / 215
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1033589 - iBWImageFromFunction
#1033678 - posterizeBWImage