Libraryless. Click here for Pure Java version (9093L/54K).
sclass ParameterizedSegmenter implements IF1<BufferedImage, L<Rect>> { !include #1024657 // Image Segmenter Parameters // input transient BufferedImage image; // output transient BufferedImage filteredImage1; // before distanceToColor transient BufferedImage filteredImage; transient L<Rect> segments; run { BufferedImage image = this.image; int w = image.getWidth(), h = image.getHeight(); filteredImage = null; if (filterLevel != 0) if (eq(filter, 'blur)) image = filteredImage = new BoxBlurFilter(filterLevel).filter(image, null); else if (eq(filter, 'min)) image = filteredImage = new MinimumFilter(filterLevel).filter(image, null); else if (eq(filter, 'max)) image = filteredImage = new MaximumFilter(filterLevel).filter(image, null); else print("Unknown filter type: " + filter); filteredImage1 = filteredImage; new AutoSegmenter as; as.g = gridSize; as.contrastThreshold = contrastThreshold; BWImage bw; if (distanceFromColor) { bw = img_distanceFromColor_withGain(image, rgbFromInts(dc_r, dc_g, dc_b), dc_gain); filteredImage = bw.getBufferedImage(); } else bw = BWImage(image); segments = as.go(bw); IntRange wr = doubleToIntRange_endPlus1(w, widthRange); IntRange hr = doubleToIntRange_endPlus1(h, heightRange); IntRange xr = doubleToIntRange_endPlus1(w, xRange); IntRange yr = doubleToIntRange_endPlus1(h, yRange); segments = filterRectsByWidthRange(segments, wr); segments = filterRectsByHeightRange(segments, hr); segments = filterRectsByCenterXRange(segments, xr); segments = filterRectsByCenterYRange(segments, yr); } public L<Rect> get(BufferedImage img) { image = img; run(); ret segments; } void distanceFromColor(RGB color) { distanceFromColor = true; dc_r = color.redInt(); dc_g = color.greenInt(); dc_b = color.blueInt(); } public ParameterizedSegmenter clone() { ret shallowNonTransientClone(this); } toString { ret sfu(this); } }
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024658 |
Snippet name: | ParameterizedSegmenter - the "old" image segmenter (BWImage-based) |
Eternal ID of this version: | #1024658/10 |
Text MD5: | 43d98204a7d0e2cd1d9a69a4a4e1a2d7 |
Transpilation MD5: | 456753fcf068a9ca64da4297906b8869 |
Author: | stefan |
Category: | javax / image analysis |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-12 03:06:56 |
Source code size: | 2156 bytes / 65 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 329 / 757 |
Version history: | 9 change(s) |
Referenced in: | [show references] |