Skip to content

Commit

Permalink
feat: add support to handle RGB brightfield images
Browse files Browse the repository at this point in the history
  • Loading branch information
raimund-schluessler committed Oct 30, 2024
1 parent 50486e5 commit 6edc418
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bmlab/export/fluorescence_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def export(self, configuration):
for image_key in image_keys:
channel = repetition.payload.get_channel(image_key)
img_data = repetition.payload.get_image(image_key)
# Average all images acquired
img_data = np.nanmean(img_data, axis=0).astype(np.ubyte)

# Average all images acquired if grayscale
if repetition.payload.get_class(image_key).casefold() == 'image_grayscale':
img_data = np.nanmean(img_data, axis=0).astype(np.ubyte)

# Construct export path and create it if necessary
if self.file.path.parent.name == 'RawData':
Expand Down Expand Up @@ -162,8 +164,8 @@ def export(self, configuration):
image_warped =\
Image.merge("RGB", (blank, blank, image_warped))
image_alpha = Image.fromarray(
(255 * np.logical_not(
np.isnan(image_data_warped))).astype(np.ubyte))
np.nanmean(255 * np.logical_not(
np.isnan(image_data_warped)), axis=tuple(range(2,image_data_warped.ndim))).astype(np.ubyte))
image_warped.putalpha(image_alpha)

filename = path / f"{self.file.path.stem}" \
Expand Down
22 changes: 22 additions & 0 deletions bmlab/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,28 @@ def get_channel(self, image_key):
except Exception:
return None

def get_class(self, image_key):
""""
Returns the image class of a payload image
with the given key
"""
try:
return self.data.get(image_key).attrs\
.get('IMAGE_SUBCLASS')[0].decode('utf-8')
except Exception:
return None

def get_mode(self, image_key):
""""
Returns the interlace mode of a payload image
with the given key
"""
try:
return self.data.get(image_key).attrs\
.get('INTERLACE_MODE')[0].decode('utf-8')
except Exception:
return None

def get_ROI(self, image_key):
"""
Returns the region of interest of a payload image
Expand Down
Binary file added tests/data/ColorImage.h5
Binary file not shown.
24 changes: 24 additions & 0 deletions tests/test_export_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ def test_export_fluorescence(tmp_dir):
assert os.path.exists(plots_dir / image)


def test_export_color_images(tmp_dir):
shutil.copy(
data_file_path('ColorImage.h5'), Path.cwd() / 'ColorImage.h5')

session = Session.get_instance()
session.set_file(Path('ColorImage.h5'))

ec = ExportController()
config = ec.get_configuration()
config['fluorescenceCombined']['export'] = False
config['brillouin']['export'] = False
ec.export(config)

session.clear()

plots_dir = tmp_dir.parent / 'Plots'
images = [
'ColorImage_FLrep0_channelbrightfield.png',
'ColorImage_FLrep0_channelbrightfield_aligned.png',
]
for image in images:
assert os.path.exists(plots_dir / image)


def test_export_fluorescence_combined(tmp_dir):
shutil.copy(
data_file_path('Fluorescence.h5'), Path.cwd() / 'Fluorescence.h5')
Expand Down

0 comments on commit 6edc418

Please sign in to comment.