Skip to content

Commit 80ec431

Browse files
committed
saenopySheroid and saenopy2D show empy image when image is not found
1 parent aaee9a5 commit 80ec431

File tree

6 files changed

+59
-24
lines changed

6 files changed

+59
-24
lines changed

saenopy/gui/common/PipelineModule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def setResult(self, result: Result):
180180
# self.t_slider.setRange(0, len(result.images) - 1)
181181
#else:
182182
# self.t_slider.setRange(0, len(result.stacks) - 2)
183-
self.t_slider.setRange(0, data["time_point_count"])
183+
self.t_slider.setRange(0, data["time_point_count"] - 1)
184184

185185
self.state_changed(result)
186186
if self.tab is not None:

saenopy/gui/spheroid/modules/DeformationDetector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def update_display(self, *, plotter=None):
182182

183183
import imageio
184184
t = self.t_slider.value()
185-
im = imageio.v2.imread(self.result.images[t]).astype(float)
185+
im = self.result.get_image_data(t).astype(float)
186+
#im = imageio.v2.imread(self.result.images[t]).astype(float)
186187
im0 = im.copy()
187188
im = im - im.min()
188189
im = (im / im.max() * 255).astype(np.uint8)

saenopy/gui/spheroid/modules/path_editor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ def start_path_change(parent, result):
1111
if not path_editor.exec():
1212
return
1313

14-
path_changer = PathChanger(result.template.replace("*", "{t}"), path_editor.input_folder.value())
14+
path_changer = PathChanger(result.template.replace("*", "{t}"), path_editor.input_folder.value().replace("*", "{t}"))
15+
print(result.images)
1516
result.images = [path_changer.change_path(path) for path in result.images]
17+
print(result.images)
1618
result.template = path_changer.change_path(result.template.replace("*", "{t}")).replace("{t}", "*")
1719

1820
#if path_editor.input_folder2 is not None:

saenopy/gui/spheroid/modules/result.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import numpy as np
12
import io
23
from typing import List
4+
import traceback
5+
from natsort import natsorted
6+
import re
37

8+
from tifffile import imread
49
import matplotlib.pyplot as plt
510

611
from saenopy.saveable import Saveable
7-
import numpy as np
8-
from tifffile import imread
912
from saenopy.result_file import make_path_absolute
10-
from natsort import natsorted
11-
import re
13+
1214

1315

1416
class Mesh2D:
@@ -18,7 +20,7 @@ class Mesh2D:
1820
class ResultSpheroid(Saveable):
1921
__save_parameters__ = ['template', 'images', 'output', 'pixel_size', 'time_delta',
2022
'thresh_segmentation', 'continuous_segmentation',
21-
'custom_mask', 'n_min', 'n_max',
23+
'custom_mask', 'n_min', 'n_max', 'shape',
2224

2325
'piv_parameters', 'force_parameters',
2426

@@ -56,6 +58,8 @@ def __init__(self, template, images, output, **kwargs):
5658
self.template = template
5759
self.images = images
5860
self.output = str(output)
61+
if "shape" not in kwargs:
62+
kwargs["shape"] = None
5963
if "res_data" not in kwargs:
6064
kwargs["res_data"] = {}
6165
self.res_data = {}
@@ -97,7 +101,17 @@ def get_data_structure(self):
97101
}
98102

99103
def get_image_data(self, time_point, channel="default", use_reference=False):
100-
im = imread(self.images[time_point])
104+
try:
105+
im = imread(self.images[time_point])
106+
except FileNotFoundError as err:
107+
traceback.print_exception(err)
108+
h = 255
109+
w = 255
110+
if self.shape is not None:
111+
h, w = self.shape[:2]
112+
im = np.zeros([h, w, 3], dtype=np.uint8)
113+
im[:, :, 0] = 255
114+
im[:, :, 2] = 255
101115
if len(im.shape) == 2:
102116
return im[:, :, None, None]
103117
return im[:, :, :, None]

saenopy/gui/tfm2d/modules/path_editor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def start_path_change(parent, result):
1515
result.reference_stack = path_editor.input_folder2.value()
1616
result.input = path_editor.input_folder3.value()
1717

18+
path_b = Path(result.input)
19+
path_a = Path(result.reference_stack)
20+
path_b = path_b.parent / (path_b.stem + "_corrected" + path_b.suffix)
21+
path_a = path_a.parent / (path_a.stem + "_corrected" + path_a.suffix)
22+
result.input_corrected = str(path_b)
23+
result.reference_stack_corrected = str(path_a)
24+
1825
#if path_editor.input_pack.value():
1926
# for stack in result.stacks:
2027
# stack.pack_files()

saenopy/gui/tfm2d/modules/result.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
from tifffile import imread
77
import matplotlib.pyplot as plt
8+
import traceback
89

910
from saenopy.saveable import Saveable
1011
from saenopy.result_file import make_path_absolute
@@ -85,24 +86,34 @@ def __init__(self, output, bf, input, reference_stack, pixel_size, **kwargs):
8586
super().__init__(**kwargs)
8687

8788
def get_image(self, index, corrected=True):
88-
if index == 0:
89-
if corrected:
90-
try:
91-
im = imread(self.input_corrected)
92-
except FileNotFoundError:
89+
try:
90+
if index == 0:
91+
if corrected:
92+
try:
93+
im = imread(self.input_corrected)
94+
except FileNotFoundError:
95+
im = imread(self.input)
96+
else:
9397
im = imread(self.input)
98+
elif index == -1:
99+
im = imread(self.bf)
94100
else:
95-
im = imread(self.input)
96-
elif index == -1:
97-
im = imread(self.bf)
98-
else:
99-
if corrected:
100-
try:
101-
im = imread(self.reference_stack_corrected)
102-
except FileNotFoundError:
101+
if corrected:
102+
try:
103+
im = imread(self.reference_stack_corrected)
104+
except FileNotFoundError:
105+
im = imread(self.reference_stack)
106+
else:
103107
im = imread(self.reference_stack)
104-
else:
105-
im = imread(self.reference_stack)
108+
except FileNotFoundError as err:
109+
traceback.print_exception(err)
110+
h = 255
111+
w = 255
112+
if self.shape is not None:
113+
h, w = self.shape[:2]
114+
im = np.zeros([h, w, 3], dtype=np.uint8)
115+
im[:, :, 0] = 255
116+
im[:, :, 2] = 255
106117
if self.shape is None:
107118
self.shape = im.shape
108119
return im

0 commit comments

Comments
 (0)