Commit c9dfb71e authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

Merge branch 'fix_widgets_stack' into 'master'

Fix roi bugs

See merge request !122
parents 3e3f1b4f 8abe583d
Pipeline #46974 failed with stage
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "22/02/2021" __date__ = "26/04/2021"
import copy import copy
import glob import glob
...@@ -668,7 +668,7 @@ class Dataset(): ...@@ -668,7 +668,7 @@ class Dataset():
return Dataset(_dir=_dir, data=new_data, dims=self.__dims, in_memory=self._in_memory) return Dataset(_dir=_dir, data=new_data, dims=self.__dims, in_memory=self._in_memory)
def apply_roi(self, origin=None, size=None, center=None, indices=None): def apply_roi(self, origin=None, size=None, center=None, indices=None, roi_dir=None):
""" """
Applies a region of interest to the data. Applies a region of interest to the data.
...@@ -681,13 +681,16 @@ class Dataset(): ...@@ -681,13 +681,16 @@ class Dataset():
:param indices: Indices of the images to apply background subtraction. :param indices: Indices of the images to apply background subtraction.
If None, the roi is applied to all the data. If None, the roi is applied to all the data.
:type indices: Union[None, array_like] :type indices: Union[None, array_like]
:param roi_dir: Directory path for the new dataset
:type roi_dir: str
:returns: dataset with data with roi applied. :returns: dataset with data with roi applied.
Note: To preserve consistence of shape between images, if `indices` Note: To preserve consistence of shape between images, if `indices`
is not None, only the data modified is returned. is not None, only the data modified is returned.
:rtype: Dataset :rtype: Dataset
""" """
roi_dir = self.dir + "/" + self.treated + "/roi/" if roi_dir is None:
roi_dir = self.dir + "/" + self.treated + "/roi/"
self.running_data = self.get_data(indices) self.running_data = self.get_data(indices)
if not os.path.isdir(roi_dir): if not os.path.isdir(roi_dir):
os.mkdir(roi_dir) os.mkdir(roi_dir)
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "11/12/2020" __date__ = "26/04/2021"
# import os # import os
...@@ -61,6 +61,7 @@ class ROISelectionWidget(qt.QWidget): ...@@ -61,6 +61,7 @@ class ROISelectionWidget(qt.QWidget):
self.indices = None self.indices = None
self.bg_indices = None self.bg_indices = None
self.bg_dataset = None self.bg_dataset = None
self._original_dataset = True
self.setLayout(qt.QVBoxLayout()) self.setLayout(qt.QVBoxLayout())
self._sv = StackViewMainWindow() self._sv = StackViewMainWindow()
...@@ -179,8 +180,10 @@ class ROISelectionWidget(qt.QWidget): ...@@ -179,8 +180,10 @@ class ROISelectionWidget(qt.QWidget):
self.roi = RectangleROI() self.roi = RectangleROI()
self.roi.setGeometry(origin=self.getRoi().getOrigin(), size=self.getRoi().getSize()) self.roi.setGeometry(origin=self.getRoi().getOrigin(), size=self.getRoi().getSize())
self.thread = OperationThread(self, self._update_dataset.apply_roi) self.thread = OperationThread(self, self._update_dataset.apply_roi)
roi_dir = self._update_dataset.dir if not self._original_dataset else None
self.thread.setArgs(size=numpy.flip(self.roi.getSize()), self.thread.setArgs(size=numpy.flip(self.roi.getSize()),
center=numpy.flip(self.roi.getCenter())) center=numpy.flip(self.roi.getCenter()),
roi_dir=roi_dir)
self.thread.finished.connect(self._updateData) self.thread.finished.connect(self._updateData)
self.thread.start() self.thread.start()
...@@ -199,6 +202,7 @@ class ROISelectionWidget(qt.QWidget): ...@@ -199,6 +202,7 @@ class ROISelectionWidget(qt.QWidget):
self._okB.setEnabled(True) self._okB.setEnabled(True)
if self.thread.data: if self.thread.data:
self._update_dataset = self.thread.data self._update_dataset = self.thread.data
self._original_dataset = False
assert self._update_dataset is not None assert self._update_dataset is not None
self.setStack(self._update_dataset) self.setStack(self._update_dataset)
self.resetROI() self.resetROI()
...@@ -212,15 +216,15 @@ class ROISelectionWidget(qt.QWidget): ...@@ -212,15 +216,15 @@ class ROISelectionWidget(qt.QWidget):
Signal emitted with the roi parameters. Signal emitted with the roi parameters.
""" """
if self.roi: if self.roi:
if self.bg_dataset is not None:
self.bg_dataset = self.bg_dataset.apply_roi(size=numpy.flip(self.roi.getSize()),
center=numpy.flip(self.roi.getCenter()))
self.sigComputed.emit(self.roi.getOrigin().tolist(), self.roi.getSize().tolist()) self.sigComputed.emit(self.roi.getOrigin().tolist(), self.roi.getSize().tolist())
else: else:
self.sigComputed.emit([], []) self.sigComputed.emit([], [])
def getDataset(self): def getDataset(self):
return self._update_dataset, self.indices, self.bg_indices, self.bg_dataset bg_dataset = (self.bg_dataset.apply_roi(size=numpy.flip(self.roi.getSize()),
center=numpy.flip(self.roi.getCenter()))
if self.bg_dataset is not None else None)
return self._update_dataset, self.indices, self.bg_indices, bg_dataset
def getStackViewColormap(self): def getStackViewColormap(self):
""" """
...@@ -254,6 +258,7 @@ class ROISelectionWidget(qt.QWidget): ...@@ -254,6 +258,7 @@ class ROISelectionWidget(qt.QWidget):
""" """
self.roi = None self.roi = None
self._update_dataset = self.dataset self._update_dataset = self.dataset
self._original_dataset = True
self.setStack(self.dataset) self.setStack(self.dataset)
def clearStack(self): def clearStack(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment