Reputation: 159
I have two images:
outline
).surface
).I want to merge those two images in a way that will leave no holes between them. To this end I:
surface
and dilated it 10 timessurface
and outline
ndi.binary_closing
with the dilated surface as a maskoutline = ...
surface = ...
merged = np.logical_or(outline, surface)
dilated_surface = ndimage.binary_dilation(surface, iterations=10)
merged = ndimage.binary_closing(merged, mask=dilated_surface)
According to documentation mask should only impact which pixels can be changed. So Why am I getting two completley different results when running it this way in comparison to without mask? I mean the holes on the edges of the mask.
I know I can instead do:
closed = ndi.binary_closing(merged)
merged[neighborhood_mask] = closed[neighborhood_mask]
but it gives slightly different results (understandably) and I want to understand the masking better.
Here are the results:
And there is the merged image alone along with surface:
Upvotes: 0
Views: 72
Reputation: 1
import numpy as np
from scipy import ndimage
outline = ... # binary outline image
surface = ... # binary surface image
# Merge the outline and surface
merged = np.logical_or(outline, surface)
# Dilate the surface
dilated_surface = ndimage.binary_dilation(surface, iterations=10)
# Apply binary closing globally
closed_global = ndimage.binary_closing(merged)
# Apply the closed result to the neighborhood of the dilated surface
merged[dilated_surface] = closed_global[dilated_surface]
# Now `merged` contains the final result with no gaps
Upvotes: 0