contrek 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +1 -1
- data/LICENSE-MIT.md +9 -0
- data/README.md +58 -17
- data/contrek.gemspec +0 -1
- data/ext/cpp_polygon_finder/PolygonFinder/CMakeLists.txt +14 -2
- data/ext/cpp_polygon_finder/PolygonFinder/LICENSE_AGPL.txt +661 -0
- data/ext/cpp_polygon_finder/PolygonFinder/examples/example.cpp +9 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/ContrekApi.h +9 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +4 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.cpp +13 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +74 -82
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +12 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +0 -10
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +0 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +64 -46
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +14 -23
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +39 -44
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +5 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +6 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +4 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +12 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.h +3 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.cpp +1 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.cpp +35 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +5 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +11 -11
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +2 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +16 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +2 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.cpp +2 -5
- data/ext/cpp_polygon_finder/extconf.rb +12 -2
- data/lib/contrek/bitmaps/painting.rb +1 -0
- data/lib/contrek/finder/concurrent/cursor.rb +7 -5
- data/lib/contrek/finder/concurrent/finder.rb +2 -1
- data/lib/contrek/finder/concurrent/part.rb +12 -3
- data/lib/contrek/finder/concurrent/partitionable.rb +7 -5
- data/lib/contrek/finder/node.rb +61 -32
- data/lib/contrek/finder/node_cluster.rb +30 -27
- data/lib/contrek/finder/polygon_finder.rb +4 -4
- data/lib/contrek/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b2690fa75c9a6671f9c8ea91522d3adaf8600bfc0739dad4c8eb4a14b80d97e
|
|
4
|
+
data.tar.gz: 38db9719cc44356ec32d33031e877edda131a970ec0fb5e385f9c31e19699858
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4827a05d797400b0245c8225274dc070870e83186d51da4b4f16bb8368359597967012b65cedbff39f808fa9d1eafad5e3012e144f10afb801d564a2ff916dca
|
|
7
|
+
data.tar.gz: 690435e9531d0c8c47c703e41c4719333b91edbe60232a5183c30e21a2822c06b827498b49afbda4785cff404e3abdaf776f0a0b4aec9c9b58a0a9fbf29c8844
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -47,4 +47,14 @@ All notable changes to this project will be documented in this file.
|
|
|
47
47
|
|
|
48
48
|
## [1.1.2] - 2026-02-09
|
|
49
49
|
### Changed
|
|
50
|
-
- Transitioned to an Open Core licensing model: Ruby Gem (MIT) and C++ Core Engine (AGPLv3).
|
|
50
|
+
- Transitioned to an Open Core licensing model: Ruby Gem (MIT) and C++ Core Engine (AGPLv3).
|
|
51
|
+
|
|
52
|
+
## [1.1.3] - 2026-02-21
|
|
53
|
+
### Changed
|
|
54
|
+
- Added support for 8-way pixel connectivity (omnidirectional) in addition to the standard 4-way mode.
|
|
55
|
+
- Optimized C++ and Ruby algorithms for initial spatial pixel tracking to improve performance.
|
|
56
|
+
|
|
57
|
+
## [1.1.4] - 2026-02-28
|
|
58
|
+
### Changed
|
|
59
|
+
- Fixed an infinite loop bug in multithreading during inner sequence joining in Omnidirectional mode.
|
|
60
|
+
- Optimized C++ and Ruby algorithms for initial spatial tangential sequence determination.
|
data/Gemfile.lock
CHANGED
data/LICENSE-MIT.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2018 -- 2026 by Emanuele Cesaroni.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
# Contrek
|
|
2
2
|
Contrek is a Ruby gem powered by a <u>standalone C++17 core library</u> for fast contour tracing and edge detection in PNG images. It employs a **topological approach** to extract polygonal contours, representing shapes as a connected graph of shared endpoints. This ensures perfect adjacency and structural integrity for shape analysis and raster-to-vector workflows, such as PNG to SVG conversion, managed via libspng (0.7.4) with multithreading support.
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
## About Contrek library
|
|
6
|
+
|
|
5
7
|
Contrek (**con**tour **trek**king) simply scans your png bitmap and returns shape contour as close polygonal lines, both for the external and internal sides. It can compute the nesting level of the polygons found with a tree structure. It supports various levels and modes of compression and approximation of the found coordinates. It is capable of multithreaded processing, splitting the image into vertical strips and recombining the coordinates in pairs.
|
|
6
8
|
|
|
7
9
|
In the following image all the non-white pixels have been examined and the result is the red polygon for the outer contour and the green one for the inner one
|
|
8
10
|

|
|
9
11
|
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
For optimal performance and efficient memory management with large images (20k+), it is highly recommended to install **tcmalloc**.
|
|
16
|
+
|
|
17
|
+
**Ubuntu / Debian:**
|
|
18
|
+
```bash
|
|
19
|
+
sudo apt-get install libgoogle-perftools-dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
|
|
10
23
|
## Install
|
|
11
24
|
|
|
12
25
|
Add this line to your application's Gemfile:
|
|
@@ -99,7 +112,7 @@ Regarding multithreading:
|
|
|
99
112
|
|
|
100
113
|
- The treemap option is currently ignored (multithreaded treemap support will be introduced in upcoming revisions).
|
|
101
114
|
|
|
102
|
-
By not declaring native option CPP Multithreading optimized code is used. In the above example a [105 MP image](spec/files/images/sample_10240x10240.png) is examined by 4 threads working on 4 tiles (total compute time about 1.
|
|
115
|
+
By not declaring native option CPP Multithreading optimized code is used. In the above example a [105 MP image](spec/files/images/sample_10240x10240.png) is examined by 4 threads working on 4 tiles (total compute time about 1.2 secs with image load).
|
|
103
116
|
|
|
104
117
|
```ruby
|
|
105
118
|
result = Contrek.contour!(
|
|
@@ -113,15 +126,42 @@ result = Contrek.contour!(
|
|
|
113
126
|
)
|
|
114
127
|
puts result.metadata[:benchmarks].inspect
|
|
115
128
|
|
|
116
|
-
{ compress:
|
|
117
|
-
init:
|
|
118
|
-
inner:
|
|
119
|
-
outer:
|
|
120
|
-
total:
|
|
129
|
+
{ compress: 26.37,
|
|
130
|
+
init: 354.339,
|
|
131
|
+
inner: 17.9427,
|
|
132
|
+
outer: 93.6252,
|
|
133
|
+
total: 380.709
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
```
|
|
124
137
|
|
|
138
|
+
### Connectivity Modes
|
|
139
|
+
|
|
140
|
+
Contrek supports different pixel connectivity rules to define how polygons are traced and merged. This is controlled by the `:connectivity` option.
|
|
141
|
+
|
|
142
|
+
| Value | Name | Type | Description |
|
|
143
|
+
| :--- | :--- | :--- | :--- |
|
|
144
|
+
| `4` | **Orthogonal** | Default | Only pixels sharing an edge (N, S, E, W) are connected. |
|
|
145
|
+
| `8` | **Omnidirectional** | Extended | Includes diagonal neighbors (sharing a corner). |
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
To enable **Omnidirectional** (8-way) connectivity, pass `connectivity: 8` in the options hash:
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
result = Contrek.contour!(
|
|
152
|
+
png_file_path: "./spec/files/images/sample_10240x10240.png",
|
|
153
|
+
options: {
|
|
154
|
+
number_of_threads: 4,
|
|
155
|
+
class: "value_not_matcher",
|
|
156
|
+
color: {r: 255, g: 255, b: 255, a: 255},
|
|
157
|
+
finder: {
|
|
158
|
+
number_of_tiles: 4,
|
|
159
|
+
connectivity: 8, # 8 for Omnidirectional, 4 for Orthogonal
|
|
160
|
+
compress: {uniq: true}}
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
125
165
|
## Result
|
|
126
166
|
|
|
127
167
|
The result structure contains polygon coordinates and a set of metadata. Polygon coordinates can be accessed via:
|
|
@@ -248,23 +288,24 @@ This process is applied recursively, merging bands until a single final band rem
|
|
|
248
288
|
One of the most complex test you can find under the spec folder is named "scans poly 1200x800", scans this [image](spec/files/images/sample_1200x800.png) computing coordinates to draw polygons drawn in this [result](spec/files/stored_samples/sample_1200x800.png).
|
|
249
289
|
On pure ruby implementation kept time
|
|
250
290
|
```ruby
|
|
251
|
-
{ :scan=>
|
|
252
|
-
:build_tangs_sequence=>
|
|
253
|
-
:plot=>
|
|
291
|
+
{ :scan=>775.435,
|
|
292
|
+
:build_tangs_sequence=>38.916,
|
|
293
|
+
:plot=>101.876,
|
|
254
294
|
:compress=>0.002,
|
|
255
|
-
:total=>
|
|
295
|
+
:total=>916.229
|
|
296
|
+
}
|
|
256
297
|
```
|
|
257
298
|
This the one for the native C++
|
|
258
299
|
```ruby
|
|
259
|
-
{ scan:
|
|
260
|
-
build_tangs_sequence:
|
|
261
|
-
plot:
|
|
262
|
-
compress: 0.
|
|
263
|
-
total:
|
|
300
|
+
{ scan: 5.077878999999999,
|
|
301
|
+
build_tangs_sequence: 0.697222999999999,
|
|
302
|
+
plot: 2.00479,
|
|
303
|
+
compress: 0.00071,
|
|
304
|
+
total: 7.780602
|
|
264
305
|
}
|
|
265
306
|
```
|
|
266
307
|
|
|
267
|
-
About
|
|
308
|
+
About 130x faster. Times are in microseconds; system: AMD Ryzen 7 3700X 8-Core Processor (BogoMIPS: 7199,99) on Ubuntu distro.
|
|
268
309
|
|
|
269
310
|
## 🛠 C++ Standalone Library Usage
|
|
270
311
|
|
|
@@ -338,7 +379,7 @@ int main() {
|
|
|
338
379
|
|
|
339
380
|
## License
|
|
340
381
|
|
|
341
|
-
This project is licensed under the terms of
|
|
382
|
+
This project is licensed under the terms of a dual-license.
|
|
342
383
|
|
|
343
384
|
See [LICENSE.md](LICENSE.md).
|
|
344
385
|
|
data/contrek.gemspec
CHANGED
|
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
end
|
|
16
16
|
s.metadata = {
|
|
17
17
|
"homepage_uri" => "https://github.com/runout77/contrek",
|
|
18
|
-
"source_code_uri" => "https://github.com/runout77/contrek",
|
|
19
18
|
"documentation_uri" => "https://github.com/runout77/contrek#readme",
|
|
20
19
|
"changelog_uri" => "https://github.com/runout77/contrek/blob/main/CHANGELOG.md"
|
|
21
20
|
}
|
|
@@ -3,11 +3,19 @@ project(ContrekCore C CXX)
|
|
|
3
3
|
|
|
4
4
|
set(CMAKE_CXX_STANDARD 17)
|
|
5
5
|
set(CMAKE_C_STANDARD 11)
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -march=native -DNDEBUG -Ofast -flto")
|
|
7
8
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -fPIC -DNDEBUG")
|
|
8
9
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -flto=auto -Wl,--no-as-needed")
|
|
9
10
|
|
|
10
11
|
find_package(ZLIB REQUIRED)
|
|
12
|
+
find_library(TCMALLOC_LIB tcmalloc) # <--- Cerca tcmalloc nel sistema
|
|
13
|
+
|
|
14
|
+
if(TCMALLOC_LIB)
|
|
15
|
+
message(STATUS "Contrek: tcmalloc found in ${TCMALLOC_LIB}")
|
|
16
|
+
else()
|
|
17
|
+
message(WARNING "Contrek: tcmalloc not found; standard one will be used.")
|
|
18
|
+
endif()
|
|
11
19
|
|
|
12
20
|
file(GLOB_RECURSE CPP_SOURCES "*.cpp")
|
|
13
21
|
file(GLOB_RECURSE C_SOURCES "*.c")
|
|
@@ -32,7 +40,11 @@ if(BUILD_EXAMPLES)
|
|
|
32
40
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/example.cpp")
|
|
33
41
|
message(STATUS "Contrek: Compiling example option ON")
|
|
34
42
|
add_executable(contrek_test examples/example.cpp)
|
|
35
|
-
|
|
43
|
+
if(TCMALLOC_LIB)
|
|
44
|
+
target_link_libraries(contrek_test PRIVATE ContrekLib ${TCMALLOC_LIB})
|
|
45
|
+
else()
|
|
46
|
+
target_link_libraries(contrek_test PRIVATE ContrekLib)
|
|
47
|
+
endif()
|
|
36
48
|
else()
|
|
37
49
|
message(WARNING "Contrek: examples/example.cpp not found!")
|
|
38
50
|
endif()
|