Hi,
I would not use dilate or erode as they will (most of the time) change
the shape
of the mask exterior. The better way to do it is with cluster,
however you don't
need to use a size threshold (which might miss some holes). What I do
instead
is the following:
invert the mask
run cluster and get the cluster index map
detect any index value that is touching the edge of the image, as
that
must be part of the background
remove all the clusters that are part of the background
add the remaining clusters to the original image
The first, second and last commands are easy, but the middle two
require a little scripting. I suggest the following:
make a mask that only includes the edges, which is most easily
done with fslmaths and the -roi command. For example, if the
image was 256x256x120 you'd do:
fslmaths image -mul 0 -add 1 -roi 1 254 1 254 1 118 0 1 -sub 1 -
mul -1 edgemask
then do a loop where you
get the maximum value of the cluster index, masked with this edgemask
if the maximum is zero then stop, otherwise remove all voxels with this
index value from the unmasked cluster index volume
once this loop is over, just binarise the remaining cluster index
volume
and add this to your original mask
This will guarantee that the edge voxels are not affected, but will
close
any gaps within your mask.
All the best,
Mark
On 24 Feb 2009, at 00:56, Dianne Patterson wrote:
> If the holes are small, then dilate once and erode once (using
> fslmaths)...this is a "close" operation. Tiny holes are filled by
> the dilation and then, since they are filled, they are not eroded
> open again.
>
> If the holes are largish, then it is a little harder...but I've done
> the following:
> create an inverse mask...that way all your holes become chunks...
> then use the cluster utility to keep only clusters over a certain
> size...then take the inverse of this cleaned up mask...and you
> should get the mask you want back.
>
> These methods are not perfect, but are better than manual cleanup.
>
> -Dianne
>
> On Mon, Feb 23, 2009 at 5:36 PM, Kyle Kern <[log in to unmask]>
> wrote:
> Hi,
>
> is there an easy way to fill in holes within a binary mask that
> doesn't change the shape of
> the mask exterior?
>
> thanks in advance,
>
> Kyle Kern
>
>
>
>
> --
> Dianne Patterson, Ph.D.
> [log in to unmask]
> University of Arizona
> SLHS 328
> 621-5105
|