Libraryless. Click here for Pure Java version (15882L/94K).
1 | // S&P, then regions |
2 | sclass Gazelle22_ImageToRegions { |
3 | BufferedImage inputImage; |
4 | BWIntegralImage ii; |
5 | SnPSettings snpSettings; |
6 | BWImage posterized; |
7 | BWImage_FastRegions regions; |
8 | Map<IImageRegion<BWImage>, Double> scoredRegions; |
9 | bool wasRun; |
10 | |
11 | settable bool withDiagonals; // also walk diagonally? |
12 | |
13 | FunctionTimings<S> timings; |
14 | |
15 | *(FunctionTimings<S> *timings, BufferedImage *inputImage, SnPSettings *snpSettings) {} |
16 | |
17 | Decolorizer decolorizer() { ret snpSettings.decolorizer; } |
18 | |
19 | run { |
20 | set wasRun; |
21 | var decolorizer = decolorizer(); |
22 | timings.do(decolorizer != null ? "bwIntegralImage w/decolorizer" : "bwIntegralImage", -> |
23 | ii = bwIntegralImage_withMeta(inputImage, decolorizer)); |
24 | |
25 | timings.do("scaleAndPosterize", -> |
26 | posterized = scaleAndPosterize(ii, snpSettings)); |
27 | regions = new BWImage_FastRegions(posterized); |
28 | regions.collectBounds(); |
29 | regions.withDiagonals(withDiagonals); |
30 | timings.do("Regions", regions); |
31 | } |
32 | |
33 | // information about original screenshot if available |
34 | ScreenShotMeta screenShotMeta() { |
35 | ret optCast ScreenShotMeta(getMetaSrc(inputImage)); |
36 | } |
37 | |
38 | Pt coordinatesFromScreen(Pt p) { |
39 | var meta = screenShotMeta(); |
40 | if (meta == null) null; |
41 | var r = meta.bounds; |
42 | if (!r.contains(p)) null; |
43 | p = translatePt(p, -r.x, -r.y); |
44 | ret scalePt(p, doubleRatio(snpSettings.pixelRows, r.h)); |
45 | } |
46 | |
47 | Pt coordinatesToScreen(Pt p) { |
48 | var meta = screenShotMeta(); |
49 | if (meta == null) null; |
50 | var r = meta.bounds; |
51 | ret translatePt(r.x, r.y, |
52 | scalePt(p, doubleRatio(r.h, snpSettings.pixelRows))); |
53 | } |
54 | |
55 | BWImage_FastRegions regions aka get() { |
56 | if (!wasRun) run(); |
57 | ret regions; |
58 | } |
59 | |
60 | int nRegions() { ret regions().nRegions(); } |
61 | } |
Began life as a copy of #1016056
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034028 |
Snippet name: | Gazelle22_ImageToRegions (BufferedImage -> BWIntegralImage -> regions) |
Eternal ID of this version: | #1034028/15 |
Text MD5: | 48840cc6a99ce0f56d9ed1971f9cf1ce |
Transpilation MD5: | 70bc7da09dcf4ead56e1b717876294cc |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-25 23:22:36 |
Source code size: | 1803 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 262 / 464 |
Version history: | 14 change(s) |
Referenced in: | [show references] |