Skip to content

Commit ee743fe

Browse files
authored
refactor: update average ring count logic and increment version to 0.6.1 (#37)
1 parent 452f99f commit ee743fe

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

tree-disk-rings/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tree-disk-rings"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "A package for tree disk rings detection in images"
55
authors = ["Tony <[email protected]>"]
66
license = "MIT"

tree-disk-rings/src/treediskrings/analyzer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def tree_ring_detection(img_in: np.ndarray) -> Tuple[
5151
)
5252

5353
devernay_curves_s, l_nodes_s, average_ring_count = sampling_edges(
54-
devernay_curves_f, img_pre
54+
devernay_curves_f, img_pre, img_in
5555
)
5656
devernay_curves_c, l_nodes_c = connect_chains(devernay_curves_s, img_pre)
5757
devernay_curves_p = postprocessing(devernay_curves_c, l_nodes_c, img_pre)
@@ -98,7 +98,7 @@ def tree_ring_detection_age_detect(
9898
)
9999

100100
devernay_curves_s, l_nodes_s, average_ring_count = sampling_edges(
101-
devernay_curves_f, img_pre
101+
devernay_curves_f, img_pre, img_in
102102
)
103103

104104
return (

tree-disk-rings/src/treediskrings/processing/sampling.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ def draw_ray_curve_and_intersections(
203203
filename: str,
204204
) -> None:
205205
"""
206-
Draws rays, curves, and intersections on an image and saves it.
206+
Draws rays, curves, and intersections on an image and saves it.<br>
207+
Rays are blue.<br>
208+
Curves are green.<br>
209+
Intersection points are red.
207210
208211
Args:
209212
dots_lists (List[Node]): List of nodes representing intersections.
@@ -230,6 +233,7 @@ def draw_ray_curve_and_intersections(
230233
def sampling_edges(
231234
l_ch_f: List[Curve],
232235
img_pre: np.ndarray,
236+
img_in: np.ndarray,
233237
) -> Tuple[List[Chain], List[Node], int]:
234238
"""
235239
Samples Devernay curves using ray directions. Implements Algorithm 6 in the supplementary material.
@@ -248,35 +252,40 @@ def sampling_edges(
248252
center = (config.cy, config.cx)
249253

250254
# Build rays from the center using the configured number of rays (config.nr)
251-
l_rays = build_rays(height, width, center)
255+
rays = build_rays(height, width, center)
252256

253257
# Compute intersections between rays and curves, returning nodes and chains.
254258
l_nodes_s, l_ch_s = intersections_between_rays_and_devernay_curves(
255-
l_rays, l_ch_f, center, height, width
259+
rays, l_ch_f, center, height, width
256260
)
257-
generate_virtual_center_chain(l_ch_s, l_nodes_s, height, width)
258261

259-
# Calculate average ring count based on intersections along the rays.
260-
counts = []
261-
for ray in l_rays:
262-
count = 0
263-
for curve in l_ch_f:
264-
if ray.geometry.intersects(curve.geometry):
265-
inter = ray.geometry.intersection(curve.geometry)
266-
if not inter.is_empty:
267-
count += 1
268-
counts.append(count)
269-
average_ring_count = int(round(np.mean(counts))) if counts else 0
262+
# Compute average ring count based on the number of intersection points (nodes) per ray
263+
average_ring_count = len(l_nodes_s) / config.nr if l_nodes_s else 0
264+
average_ring_count = int(round(average_ring_count))
265+
266+
# call by reference, modifies the list of chains and nodes
267+
generate_virtual_center_chain(l_ch_s, l_nodes_s, height, width)
270268

271269
# Debug purposes, not illustrated in the paper
272270
if config.debug:
273271
img_draw = np.zeros((height, width, 3), dtype=np.uint8)
272+
273+
# save with empty background
274274
draw_ray_curve_and_intersections(
275275
l_nodes_s,
276-
l_rays,
276+
rays,
277277
l_ch_f,
278278
img_draw,
279279
f"{config.output_dir}/dots_curve_and_rays.png",
280280
)
281281

282+
# save with preprocess image
283+
draw_ray_curve_and_intersections(
284+
l_nodes_s,
285+
rays,
286+
l_ch_f,
287+
img_in,
288+
f"{config.output_dir}/dots_curve_and_rays_pre.png",
289+
)
290+
282291
return l_ch_s, l_nodes_s, average_ring_count

0 commit comments

Comments
 (0)