Skip to content
Snippets Groups Projects
Commit 1c45425f authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Elevate whether to use a specific z-index or MIP to find best focus in zmask

parent 09b24fa8
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
from extensions.chaeo.util import autonumber_new_directory, get_matching_files, loop_workflow
from extensions.chaeo.workflows import export_patches_from_multichannel_zstack
from model_server.accessors import CziImageFileAccessor, write_accessor_data_to_file, InMemoryDataAccessor
from model_server.process import rescale
def export_single_channel_tif_from_multichannel_czi(input_file_path, output_folder_path, channel, **kwargs):
in_acc = CziImageFileAccessor(input_file_path)
data = in_acc.get_one_channel_data(channel).data
if 'rescale_zmask_clip' in kwargs:
data = rescale(data, clip=kwargs['rescale_zmask_clip'])
outf = Path(output_folder_path) / (Path(input_file_path).stem + '.tif')
write_accessor_data_to_file(
outf,
InMemoryDataAccessor(data),
)
print(f'Wrote file: {outf}')
if __name__ == '__main__':
root = Path('c:/Users/rhodes/projects/proj0012-trec-handoff/owncloud-sync/TREC-HD/Images/')
where_czi = (root / 'TREC_STOP_24_Bilbao/231008_automic/20231008-162336/Selection').__str__()
where_output = autonumber_new_directory(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0017/output',
'batch-output'
)
px_ilp = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/exp0017/pxAF405_dim8bit.ilp').__str__()
params = {
'ilastik_project_file': px_ilp,
'pxmap_threshold': 0.25,
'pixel_class': 0,
'zmask_channel': 0,
'zmask_zindex': 3,
'patches_channel': 2,
'mask_type': 'boxes',
'zmask_filters': {'area': (1e3, 1e8)},
'zmask_expand_box_by': (128, 3),
'export_pixel_probabilities': True,
'export_2d_patches_for_training': True,
'draw_bounding_box_on_2d_patch': True,
'export_2d_patches_for_annotation': True,
'export_3d_patches': False,
'export_annotated_zstack': True,
'export_patch_masks': True,
'rescale_zmask_clip': 0.01,
'rgb_overlay_channels': (1, None, None),
'rgb_overlay_weights': (0.5, 1.0, 1.0)
}
input_files = get_matching_files(where_czi, 'czi', coord_filter={})
loop_workflow(
input_files,
where_output,
export_patches_from_multichannel_zstack,
params,
catch_and_continue=False,
)
print('Finished')
\ No newline at end of file
......@@ -23,6 +23,7 @@ def export_patches_from_multichannel_zstack(
pxmap_threshold: float,
pixel_class: int,
zmask_channel: int,
zmask_zindex: None, # None for MIP,
patches_channel: int,
rescale_zmask_clip: int = None,
mask_type: str = 'boxes',
......@@ -46,7 +47,11 @@ def export_patches_from_multichannel_zstack(
ti.click('file_input')
# MIP and classify pixels
zmask_data = stack.get_one_channel_data(channel=zmask_channel).data.max(axis=-1, keepdims=True)
if isinstance(zmask_zindex, int):
assert 0 < zmask_zindex < stack.nz
zmask_data = stack.get_one_channel_data(channel=zmask_channel).data[:, :, :, zmask_zindex]
else:
zmask_data = stack.get_one_channel_data(channel=zmask_channel).data.max(axis=-1, keepdims=True)
if rescale_zmask_clip:
zmask_data = rescale(zmask_data, rescale_zmask_clip)
mip = InMemoryDataAccessor(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment