Skip to content

BoundaryFill leads to stackoverflow for big interiors #80

Description

@Marc-3d

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions