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

Support mono PNG too

parent 4a2312f0
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,8 @@ czifile = {
'z': 1,
}
filename = 'test_img.png'
pngfile = {
filename = 'rgb.png'
rgbpngfile = {
'filename': filename,
'path': root / filename,
'w': 64,
......@@ -22,6 +22,16 @@ pngfile = {
'z': 1
}
filename = 'mono.png'
monopngfile = {
'filename': filename,
'path': root / filename,
'w': 64,
'h': 128,
'c': 1,
'z': 1
}
filename = 'zmask-test-stack.tif'
tifffile = {
'filename': filename,
......
......@@ -124,7 +124,10 @@ class PngFileAccessor(GenericImageFileAccessor):
except Exception:
FileAccessorError(f'Unable to access data in {fpath}')
self._data = np.expand_dims(arr, 3)
if len(arr.shape) == 3: # rgb
self._data = np.expand_dims(arr, 3)
else: # mono
self._data = np.expand_dims(arr, (2, 3))
class CziImageFileAccessor(GenericImageFileAccessor):
"""
......
......@@ -2,7 +2,7 @@ import unittest
import numpy as np
from conf.testing import czifile, output_path, pngfile, tifffile
from conf.testing import czifile, output_path, monopngfile, rgbpngfile, tifffile
from model_server.accessors import CziImageFileAccessor, DataShapeError, generate_file_accessor, InMemoryDataAccessor, PngFileAccessor, write_accessor_data_to_file, TifSingleSeriesFileAccessor
class TestCziImageFileAccess(unittest.TestCase):
......@@ -99,8 +99,11 @@ class TestCziImageFileAccess(unittest.TestCase):
fh_shape_dict = {se.axes[i]: se.shape[i] for i in range(0, len(se.shape))}
self.assertEqual(fh_shape_dict, acc.shape_dict, 'Axes are not preserved in TIF output')
def test_read_rgb_png(self):
def test_read_png(self, pngfile=rgbpngfile):
acc = PngFileAccessor(pngfile['path'])
self.assertEqual(acc.hw, (pngfile['h'], pngfile['w']))
self.assertEqual(acc.chroma, 3)
self.assertEqual(acc.chroma, pngfile['c'])
self.assertEqual(acc.nz, 1)
def test_read_mono_png(self):
return self.test_read_png(pngfile=monopngfile)
\ No newline at end of file
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