JuliaImages / JuliaImages/ImageDraw.jl

BoundaryFill leads to stackoverflow for big interiors

Open
#80 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
27
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hi all,

I understand that BoundaryFill recursively paints the pixels within a boundary. This recursive approach leads to stack overflow in my computer.

In my particular case, I computed a convex hull, converted it into an ImageDraw.Polygon, and painted its outline with ImageDraw.draw!:

using ColorTypes 

ch_mask = zeros( Gray{Float32}, size(mask) )

draw!( ch_mask, ch_poly, Gray{Float32}(1) )
convex hull

image

Using the centroid of the convex hull as a reference, I try to paint the interior with this code... but I consistently get a stack overflow error:

bf = ImageDraw.BoundaryFill( ch_centroid[2], ch_centroid[1], Gray{Float32}(1), Gray{Float32}(1) )

bf( ch_mask, [ CartesianIndex(0,0), ], ch_centroid[2], ch_centroid[1] )

image

This is how much was painted before the stack overflow occurred:

partial fill

image




In case it helps, I ended up using connected components labelling from the outline of the convex hull to solve my problem, which generalizes to 3D and runs very fast:

using ImageComponentAnalysis 

ch_mask_img = Float32.( ch_mask );

lbls = ImageComponentAnalysis.label_components( ch_mask_img .== 0 ); 

lbl_centroid = lbls[ ch_centroid... ]

Gray{Float32}.( lbls .== lbl_centroid )
working pipeline

image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the BoundaryFill entry point and reproduce the stack overflow with a large interior like the convex-hull example. Check how the issue's BoundaryFill call traverses the mask; done means large interiors can be filled without stack overflow, while preserving the existing boundary behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.