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

Combined mono and multichannel patch export methods

parent cb1bba3e
No related branches found
No related tags found
No related merge requests found
......@@ -247,24 +247,4 @@ def export_patches_from_zstack(
for roi in patches_df.itertuples(): # just used for label info
_export_patch(roi)
return exported
def export_multichannel_patches_from_zstack(
where: Path,
roiset,
rgb_overlay_channels: list = None,
rgb_overlay_weights: list = [1.0, 1.0, 1.0],
white_channel: int = None,
**kwargs
):
"""
Export RGB patches where each patch is assignable to a channel of the input stack
:param ch_rgb_overlay: tuple of integers (R, G, B) that assign a stack channel index to an RGB channel
:param overlay_gain: optional, tuple of float (R, G, B) multipliers that can be used to balance relative brightness
:param rgb_white_channel: int, index of stack channel that becomes grayscale signal in export patches
"""
kwargs['white_channel'] = white_channel
kwargs['rgb_overlay_channels'] = rgb_overlay_channels
kwargs['rgb_overlay_weights'] = rgb_overlay_weights
return export_patches_from_zstack(where, roiset, **kwargs)
\ No newline at end of file
return exported
\ No newline at end of file
......@@ -7,7 +7,7 @@ from model_server.conf.testing import output_path
from model_server.extensions.chaeo.conf.testing import multichannel_zstack, pixel_classifier, pipeline_params
from extensions.chaeo.params import RoiSetExportParams, RoiSetMetaParams
from model_server.extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack
from model_server.extensions.chaeo.products import export_patches_from_zstack
from model_server.extensions.chaeo.workflows import infer_object_map_from_zstack
from model_server.extensions.chaeo.zmask import get_label_ids, RoiSet
from model_server.base.accessors import generate_file_accessor, InMemoryDataAccessor, write_accessor_data_to_file
......@@ -248,8 +248,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
)
def test_multichannel_to_mono_2d_patches(self):
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
output_path / 'multichannel' / 'mono_2d_patches',
self.roiset,
white_channel=3,
......@@ -259,7 +258,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
self.assertEqual(result.chroma, 1)
def test_multichannnel_to_mono_2d_patches_rgb_bbox(self):
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
output_path / 'multichannel' / 'mono_2d_patches_rgb_bbox',
self.roiset,
white_channel=3,
......@@ -270,7 +269,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
self.assertEqual(result.chroma, 3)
def test_multichannnel_to_rgb_2d_patches_bbox(self):
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
output_path / 'multichannel' / 'rgb_2d_patches_bbox',
self.roiset,
white_channel=4,
......@@ -283,7 +282,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
self.assertEqual(result.chroma, 3)
def test_multichannnel_to_rgb_2d_patches_contour(self):
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
output_path / 'multichannel' / 'rgb_2d_patches_contour',
self.roiset,
rgb_overlay_channels=(3, None, None),
......@@ -296,7 +295,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
self.assertEqual(result.get_one_channel_data(2).data.max(), 0) # blue channel is black
def test_multichannel_to_multichannel_tif_patches(self):
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
output_path / 'multichannel' / 'multichannel_tif_patches',
self.roiset,
)
......@@ -309,9 +308,4 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa
'test_multichannel_annotated_zstack',
)
# files = export_multichannel_patches_from_zstack(
# output_path / 'multichannel_to_multichannel_tif_patches',
# self.roiset,
# )
# result = generate_file_accessor(Path(files[0]['location']) / files[0]['patch_filename'])
# self.assertEqual(result.chroma, 5)
......@@ -14,7 +14,7 @@ from model_server.base.models import InstanceSegmentationModel
from model_server.base.process import pad, rescale, resample_to_8bit
from model_server.extensions.chaeo.annotators import draw_boxes_on_3d_image
from model_server.extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack
from model_server.extensions.chaeo.products import export_patches_from_zstack
from extensions.chaeo.params import RoiFilter, RoiSetMetaParams, RoiSetExportParams
from model_server.extensions.chaeo.accessors import MonoPatchStack, Multichannel3dPatchStack
from model_server.extensions.chaeo.process import mask_largest_object
......@@ -247,12 +247,12 @@ class RoiSet(object):
subdir, self, white_channel=channel, prefix=pr, make_3d=True, **kp
)
if k == 'annotated_patches_2d':
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
subdir, self, prefix=pr, make_3d=False, white_channel=channel,
bounding_box_channel=1, bounding_box_linewidth=2, **kp,
)
if k == 'patches_2d':
files = export_multichannel_patches_from_zstack(
files = export_patches_from_zstack(
subdir, self, white_channel=channel, prefix=pr, make_3d=False, **kp
)
df_patches = pd.DataFrame(files)
......
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