Skip to content

Commit 7bb07b3

Browse files
authored
Merge pull request #59 from computational-cell-analytics/bg-mask-update
I will go ahead and merge it because the intensity measurement for the whole cochlea has been checked and I want to have it available on the main branch.
2 parents 923bd0e + e7992d4 commit 7bb07b3

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

flamingo_tools/measurements.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import trimesh
1111
from elf.io import open_file
1212
from elf.wrapper.resized_volume import ResizedVolume
13+
from elf.wrapper.base import WrapperBase
14+
from elf.util import normalize_index, squeeze_singletons
1315
from nifty.tools import blocking
1416
from skimage.measure import marching_cubes, regionprops_table
17+
from skimage.transform import downscale_local_mean
1518
from scipy.ndimage import binary_dilation
1619
from tqdm import tqdm
1720

@@ -366,12 +369,35 @@ def compute_object_measures(
366369
measures.to_csv(output_table_path, sep="\t", index=False)
367370

368371

372+
# Refactor to elf?
373+
class ResizedVolumeLocalMean(WrapperBase):
374+
def __init__(self, volume, factors):
375+
super().__init__(volume)
376+
self._scale = factors
377+
self._shape = tuple(int(np.ceil(s / f)) for s, f in zip(volume.shape, self._scale))
378+
379+
@property
380+
def shape(self):
381+
return self._shape
382+
383+
@property
384+
def scale(self):
385+
return self._scale
386+
387+
def __getitem__(self, key):
388+
index, to_squeeze = normalize_index(key, self.shape)
389+
index = tuple(slice(s.start * f, s.stop * f) for s, f in zip(index, self._scale))
390+
out = self.volume[index]
391+
out = downscale_local_mean(out, self._scale)
392+
return squeeze_singletons(out, to_squeeze)
393+
394+
369395
def compute_sgn_background_mask(
370396
image_path: str,
371397
segmentation_path: str,
372398
image_key: Optional[str] = None,
373399
segmentation_key: Optional[str] = None,
374-
threshold_percentile: float = 35.0,
400+
threshold_percentile: int = 35,
375401
scale_factor: Tuple[int, int, int] = (16, 16, 16),
376402
n_threads: Optional[int] = None,
377403
cache_path: Optional[str] = None,
@@ -408,7 +434,7 @@ def compute_sgn_background_mask(
408434
return mask
409435

410436
original_shape = image.shape
411-
downsampled_shape = tuple(int(np.round(sh / sf)) for sh, sf in zip(original_shape, scale_factor))
437+
downsampled_shape = tuple(int(np.ceil(sh / sf)) for sh, sf in zip(original_shape, scale_factor))
412438

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

@@ -419,7 +445,7 @@ def compute_sgn_background_mask(
419445
blocks = blocking((0, 0, 0), downsampled_shape, chunk_shape)
420446
n_blocks = blocks.numberOfBlocks
421447

422-
img_resized = ResizedVolume(image, downsampled_shape)
448+
img_resized = ResizedVolumeLocalMean(image, scale_factor)
423449
seg_resized = ResizedVolume(segmentation, downsampled_shape, order=0)
424450

425451
def _compute_block(block_id):

reproducibility/object_measures/process_all_object_measures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import flamingo_tools.s3_utils as s3_utils
77

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

6666

6767
def main():
68-
start_slurm = False
68+
start_slurm = True
6969
for cochlea in COCHLEAE:
7070
process_cochlea(cochlea, start_slurm)
7171

reproducibility/object_measures/repro_object_measures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def repro_object_measures(
2121
default_component_list = [1]
2222
default_bg_mask = None
2323

24-
with open(json_file, 'r') as myfile:
24+
with open(json_file, "r") as myfile:
2525
data = myfile.read()
2626
param_dicts = json.loads(data)
2727

0 commit comments

Comments
 (0)