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

[hotPixelRemoval] Added specific widget

parent b1f79929
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "10/10/2019"
from silx.gui import qt
from silx.gui.colors import Colormap
from silx.gui.plot.StackView import StackViewMainWindow
from darfix.core.imageOperations import hot_pixel_removal
from .utils import ChooseDimensionWidget
from .operationThread import OperationThread
class HotPixelRemovalWidget(qt.QWidget):
"""
Widget to apply hot pixel removal to the images in a dataset.
"""
signalComputed = qt.Signal()
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self._thread = OperationThread(hot_pixel_removal)
self.setLayout(qt.QVBoxLayout())
self._sv = StackViewMainWindow()
self._sv.setColormap(Colormap(name='viridis', normalization='linear'))
self._chooseDimensionWidget = ChooseDimensionWidget(self)
self._chooseDimensionWidget.hide()
self._computeB = qt.QPushButton("Compute hot pixel removal")
self.layout().addWidget(self._sv)
self.layout().addWidget(self._computeB)
self._computeB.clicked.connect(self.computeBS)
self._chooseDimensionWidget.filterChanged.connect(self._filterStack)
self._chooseDimensionWidget.stateDisabled.connect(self._wholeStack)
def hideButton(self):
self._computeB.hide()
def showButton(self):
self._computeB.show()
def computeBS(self):
"""
Function that starts the thread to compute the hot pixel removal.
"""
self._thread.setArgs(self.dataset.data)
self._thread.finished.connect(self._updateData)
self._thread.start()
self._computeB.setEnabled(False)
def _updateData(self):
"""
Updates the stack with the data computed in the thread
"""
self._thread.finished.disconnect(self._updateData)
self._computeB.setEnabled(True)
self.dataset.data = self._thread.data
# self.dataset.data = hot_pixel_removal(self.dataset.data)
assert self.dataset.data is not None
self.setStack(self.dataset.data)
self.signalComputed.emit()
def setDataset(self, dataset):
"""
Dataset setter. Saves the dataset and updates the stack with the dataset
data
:param Dataset dataset: dataset
"""
self.dataset = dataset
self.setStack(dataset.data)
if self.dataset.get_reshaped_data() is not None:
self._chooseDimensionWidget.show()
self._chooseDimensionWidget.setDimensions(self.dataset.dims)
def clearStack(self):
self._sv.setStack(None)
def _filterStack(self, dim=0, val=0):
data = self.dataset.get_reshaped_data(dim, val)
if data.shape[0]:
self.setStack(data)
else:
self.setStack(None)
def _wholeStack(self):
self.setStack(self.dataset.data)
def setStack(self, *arg, **kwargs):
"""
Sets the data passed as aguments in the stack.
Mantains the current frame showed in the view.
"""
nframe = self._sv.getFrameNumber()
self._sv.setStack(*arg, **kwargs)
self._sv.setFrameNumber(nframe)
\ No newline at end of file
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