-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples/segment blockwise script (#273)
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,5 @@ tmp/ | |
# daisy logs | ||
daisy_logs/ | ||
|
||
*.csv | ||
*.csv | ||
*.private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
steps: | ||
gaussian_smooth: | ||
sigma: 2.0 | ||
threshold: | ||
threshold: 200 | ||
label: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
import scipy.ndimage | ||
import yaml | ||
|
||
logger = logging.getLogger(__file__) | ||
|
||
|
||
def segment_function(input_array, block, config_path): | ||
""" | ||
Segment a 3D block using a small numpy-based post-processing script. | ||
Args: | ||
input_array (np.ndarray): The 3D array to segment. | ||
block (daisy.Block): The block object. | ||
config_path (str): The path to the configuration yaml file. | ||
Returns: | ||
np.ndarray: The segmented 3D array. | ||
""" | ||
data = input_array.to_ndarray(block.read_roi) | ||
steps = yaml.load(config_path, Loader=yaml.FullLoader) | ||
|
||
# Apply the segmentation function here | ||
for step, params in steps.items(): | ||
if step == "gaussian_smooth": | ||
sigma = params.get("sigma", 1.0) | ||
logger.info(f"Applying Gaussian smoothing with sigma={sigma}") | ||
data = scipy.ndimage.gaussian_filter(data, sigma=sigma) | ||
elif step == "threshold": | ||
threshold = params.get("threshold", 0.5) | ||
logger.info(f"Applying thresholding with threshold={threshold}") | ||
data = data > threshold | ||
elif step == "label": | ||
structuring_element = params.get("structuring_element", None) | ||
logger.info("Applying labeling") | ||
data, _ = scipy.ndimage.label(data, structuring_element) # type: ignore | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This file contains the commands used to run an example of the segment-blockwise command. | ||
# The arguments to the segment-blockwise command are: | ||
# -sf: path to the python file with the segmentation_function (in this case the empanada_function.py file) | ||
# -tr: Total ROI to process. It is a list of 3 elements, each one is a list with the start and end of the ROI in the x, y and z axis respectively. | ||
# e.g. -tr "[320000:330000, 100000:110000, 10000:20000]" \ | ||
# -rr: ROI to read. It is a list of 3 elements, each one is a list with the start and end of the ROI in the x, y and z axis respectively. | ||
# -wr: ROI to write. It is a list of 3 elements, each one is a list with the start and end of the ROI in the x, y and z axis respectively. | ||
# -nw: Number of workers to use. | ||
# -ic: Input container. It is the path to the input zarr file. | ||
# -id: Input dataset. It is the path to the input dataset inside the input zarr file. | ||
# -oc: Output container. It is the path to the output zarr file. | ||
# -od: Output dataset. It is the path to the output dataset inside the output zarr file. | ||
# --config_path: Path to the config yaml file. | ||
|
||
|
||
dacapo segment-blockwise \ | ||
-sf segment_function.py \ | ||
-rr "[256,256,256]" \ | ||
-wr "[256,256,256]" \ | ||
-nw 32 \ | ||
-ic predictions/c-elegen/bw/c_elegen_bw_op50_ld_scratch_0_300000.zarr \ | ||
-id ld/ld \ | ||
-oc predictions/c-elegen/bw/jrc_c-elegans-bw-1_postprocessed.zarr \ | ||
-od ld \ | ||
--config_path segment_config.yaml |