Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundaryFill leads to stackoverflow for big interiors #80

Open
Marc-3d opened this issue Jun 28, 2024 · 0 comments
Open

BoundaryFill leads to stackoverflow for big interiors #80

Marc-3d opened this issue Jun 28, 2024 · 0 comments

Comments

@Marc-3d
Copy link

Marc-3d commented Jun 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant