Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 29 additions & 3 deletions flamingo_tools/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import trimesh
from elf.io import open_file
from elf.wrapper.resized_volume import ResizedVolume
from elf.wrapper.base import WrapperBase
from elf.util import normalize_index, squeeze_singletons
from nifty.tools import blocking
from skimage.measure import marching_cubes, regionprops_table
from skimage.transform import downscale_local_mean
from scipy.ndimage import binary_dilation
from tqdm import tqdm

Expand Down Expand Up @@ -346,12 +349,35 @@ def compute_object_measures(
measures.to_csv(output_table_path, sep="\t", index=False)


# Refactor to elf?
class ResizedVolumeLocalMean(WrapperBase):
def __init__(self, volume, factors):
super().__init__(volume)
self._scale = factors
self._shape = tuple(int(np.ceil(s / f)) for s, f in zip(volume.shape, self._scale))

@property
def shape(self):
return self._shape

@property
def scale(self):
return self._scale

def __getitem__(self, key):
index, to_squeeze = normalize_index(key, self.shape)
index = tuple(slice(s.start * f, s.stop * f) for s, f in zip(index, self._scale))
out = self.volume[index]
out = downscale_local_mean(out, self._scale)
return squeeze_singletons(out, to_squeeze)


def compute_sgn_background_mask(
image_path: str,
segmentation_path: str,
image_key: Optional[str] = None,
segmentation_key: Optional[str] = None,
threshold_percentile: float = 35.0,
threshold_percentile: int = 35,
scale_factor: Tuple[int, int, int] = (16, 16, 16),
n_threads: Optional[int] = None,
cache_path: Optional[str] = None,
Expand Down Expand Up @@ -388,7 +414,7 @@ def compute_sgn_background_mask(
return mask

original_shape = image.shape
downsampled_shape = tuple(int(np.round(sh / sf)) for sh, sf in zip(original_shape, scale_factor))
downsampled_shape = tuple(int(np.ceil(sh / sf)) for sh, sf in zip(original_shape, scale_factor))

low_res_mask = np.zeros(downsampled_shape, dtype="bool")

Expand All @@ -399,7 +425,7 @@ def compute_sgn_background_mask(
blocks = blocking((0, 0, 0), downsampled_shape, chunk_shape)
n_blocks = blocks.numberOfBlocks

img_resized = ResizedVolume(image, downsampled_shape)
img_resized = ResizedVolumeLocalMean(image, scale_factor)
seg_resized = ResizedVolume(segmentation, downsampled_shape, order=0)

def _compute_block(block_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import flamingo_tools.s3_utils as s3_utils

OUTPUT_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/mobie_project/cochlea-lightsheet/tables/measurements/" # noqa
OUTPUT_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/mobie_project/cochlea-lightsheet/tables/measurements2" # noqa
JSON_ROOT = "/user/pape41/u12086/Work/my_projects/flamingo-tools/reproducibility/object_measures"
COCHLEAE = [
"M_LR_000143_L",
Expand Down Expand Up @@ -65,7 +65,7 @@ def process_cochlea(cochlea, start_slurm):


def main():
start_slurm = False
start_slurm = True
for cochlea in COCHLEAE:
process_cochlea(cochlea, start_slurm)

Expand Down
2 changes: 1 addition & 1 deletion reproducibility/object_measures/repro_object_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def repro_object_measures(
default_component_list = [1]
default_bg_mask = None

with open(json_file, 'r') as myfile:
with open(json_file, "r") as myfile:
data = myfile.read()
param_dicts = json.loads(data)

Expand Down
Loading