Skip to content

Commit

Permalink
Removal of spurious pixels (#349)
Browse files Browse the repository at this point in the history
* Removal of spurious pixelsn

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* minor simplification of spurious pixel removal code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove debug print statement

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: alessandrofelder <[email protected]>
Co-authored-by: Alessandro Felder <[email protected]>
  • Loading branch information
4 people authored Aug 9, 2024
1 parent c1e80ee commit 71f6d5b
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pooch
from brainglobe_utils.IO.image import load_nii
from rich.progress import track
from skimage.measure import label, regionprops

from brainglobe_atlasapi import utils
from brainglobe_atlasapi.atlas_generation.mesh_utils import (
Expand Down Expand Up @@ -74,6 +75,21 @@ def create_atlas(working_dir, resolution):
reference_image = (reference_image - dmin) * dscale
reference_image = reference_image.astype(np.uint16)

# mask: put 1 where there is an annotation
annotation_mask = np.zeros(annotation_image.shape)
annotation_mask[annotation_image > 0] = 1

# find the connected regions in the mask
labeled_image = label(annotation_mask)
regions = regionprops(labeled_image)

# find the pixels belonging to the largest region
largest_region = max(regions, key=lambda region: region.area)
largest_mask = labeled_image == largest_region.label

# keep only annotations in the largest connected region
annotation_image = annotation_image * largest_mask

hierarchy = []

# create dictionaries # create dictionary from data read from the CSV file
Expand Down

0 comments on commit 71f6d5b

Please sign in to comment.