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

Fix ingestion of segmentation masks #15

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ingestion_tools/scripts/common/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def pyramid_to_mrc(
mrcfiles.append(os.path.basename(filename))

if write:
newfile = mrcfile.new(filename, self.data, overwrite=True)
newfile = mrcfile.new(filename, pyramid[0], overwrite=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the processed mask data instead of original data.

self.update_headers(newfile, header_mapper, voxel_spacing)
newfile.flush()
newfile.close()
Expand Down
36 changes: 18 additions & 18 deletions ingestion_tools/scripts/importers/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def __init__(
glob_string: str,
glob_vars: dict[str, str],
file_format: str,
is_viz_default: bool = False,
is_visualization_default: bool = False,
):
self.glob_string = glob_string.format(**glob_vars)
self.file_format = file_format
self.shape = shape
self.is_viz_default = is_viz_default
self.is_viz_default = is_visualization_default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also rename the class variable to is_visualization_default for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with the last commit.

if self.file_format not in ["mrc"]:
raise NotImplementedError("We only support MRC files for segmentation masks")

Expand All @@ -107,13 +107,13 @@ def __init__(
glob_vars: dict[str, str],
file_format: str,
mask_label: int = 1, # No explicit label means we are dealing with a binary mask already
is_viz_default: bool = False,
is_visualization_default: bool = False,
):
self.glob_string = glob_string.format(**glob_vars)
self.file_format = file_format
self.shape = "SegmentationMask" # Don't expose SemanticSegmentationMask to the public portal.
self.label = mask_label
self.is_viz_default = is_viz_default
self.is_viz_default = is_visualization_default

if self.file_format not in ["mrc"]:
raise NotImplementedError("We only support MRC files for segmentation masks")
Expand All @@ -138,15 +138,15 @@ def __init__(
glob_vars: dict[str, str],
file_format: str,
columns: str,
is_viz_default: bool = False,
is_visualization_default: bool = False,
delimiter: str = ",",
):
self.glob_string = glob_string.format(**glob_vars)
self.file_format = file_format
self.columns = columns
self.shape = shape
self.delimiter = delimiter
self.is_viz_default = is_viz_default
self.is_viz_default = is_visualization_default
if self.file_format not in ["csv", "csv_with_header"]:
raise NotImplementedError("We only support CSV files for Point files")

Expand All @@ -170,16 +170,16 @@ def load(
annotation_set = []
with fs.open(csvfilename, "r") as data:
points = csv.reader(data, delimiter=self.delimiter)
if skip_header:
next(points)
for coord in points:
annotation_set.append(
self.point(
float(coord[coord_order[0]]),
float(coord[coord_order[1]]),
float(coord[coord_order[2]]),
),
)
if skip_header:
next(points)
for coord in points:
annotation_set.append(
self.point(
float(coord[coord_order[0]]),
float(coord[coord_order[1]]),
float(coord[coord_order[2]]),
),
)
Comment on lines +180 to +189
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation so the file is actually open.

return annotation_set

def get_metadata(self, output_prefix: str):
Expand Down Expand Up @@ -227,7 +227,7 @@ def __init__(
file_format: str,
binning: int,
glob_string: str,
is_viz_default: bool = False,
is_visualization_default: bool = False,
order: str | None = None,
filter_value: str | None = None,
):
Expand All @@ -239,7 +239,7 @@ def __init__(
self.glob_string = glob_string.format(**glob_vars)
self.order = order
self.filter_value = ""
self.is_viz_default = is_viz_default
self.is_viz_default = is_visualization_default
if filter_value:
self.filter_value = filter_value.format(**glob_vars)
valid_formats = self.map_functions.keys()
Expand Down