Newer
Older
# that the button is still in use, because it gets a blue color.
self.button_changecellvalue.setChecked(False)
"""This functions creates from the ExchangeCellValues.py file a
window which takes two integer entries and then swaps the cells having
the given integer values.
"""
# creates a dialog window from the ExchangeCellValues.py file
dlg = ecv.CustomDialog(self)
# if the user presses 'ok', it executes the code
if dlg.exec_():
# it tests if both value to be swapped are not empty.
if dlg.entry1.text()!= '' and dlg.entry2.text() != '':
# reads out the values and converts it into integers.
value1 = int(dlg.entry1.text())
value2 = int(dlg.entry2.text())
# calls the function which does the swap
self.m.ExchangeCellValue(value1,value2)
# if the button to display the values of the cell is checked,
# the values are again displayed on the graph after the swap
# of cells.
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
def SelectChannel(self, index):
"""This function is called when the button to select different channels
is used. From the displayed list in the button, the chosen index
corresponnds to the same index in the list of channels from the reader.
So, it sets the default channel with the new index (called index below)
"""
# This function attributes the FOV chosen by the user corresponding to
# the index in the list of options.
self.reader.default_channel = index
# update the pictures using the same function as the one used to
# change the fields of view.
self.ChangeFOV()
"""This function is called when the button containing the list of
fields od view is used.
The index correspondds to the field of view selected in the list.
# This function attributes the FOV chosen by the user corresponding to
# the index in the list of options. First the mask is automatically
# saved.
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
# the new index is set.
# it updates the fov in the plot with the new index.
self.ChangeFOV()
# the flag of the fluorescence extraction is set to False (such that
# if the user extracts fluorescence data in the new field of view,
# there is a dialog box asking to select the corresponding xls file
# for this field of view. IF there is no data sheet for this fov, the
# user can enter a new name to make a new file.)
self.FlagFluoExtraction = False
# it changes the fov or channel according to the choice of the user
# and it updates the plot shown and it initializes the new fov/channel
# at t=0 by default.
# load the image and mask for the current plot
self.m.currpicture = self.reader.LoadOneImage(self.Tindex,self.FOVindex)
self.m.plotmask = self.reader.LoadMask(self.Tindex,self.FOVindex)
# sets the image and the mask to 0 for the previous plot
self.m.prevpicture = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.prevplotmask = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
# load the image and the mask for the next plot.
self.m.nextpicture = self.reader.LoadOneImage(self.Tindex+1, self.FOVindex)
self.m.nextplotmask = self.reader.LoadMask(self.Tindex+1, self.FOVindex)
# once the images and masks are loaded into the variables, they are
# displaye in the gui.
self.m.UpdateBckgrndPicture()
# enables the next frame button in case it was disabled when the
# fov/channel was changed
self.button_nextframe.setEnabled(True)
# disables the previous frame button in case it was active before
# changing fov/channel.
self.button_previousframe.setEnabled(False)
# updates the title of the plots to display the right time indices
# aboves the plots.
self.UpdateTitleSubplots()
# if the button to show cell values is active, it shows the values again.
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
# if the button to hide the mask was checked before changing fov/channel,
# it hides the mask again.
if self.button_hidemask.isChecked():
self.m.HideMask()
# the button to set the time index is also set to 0/default again.
self.button_timeindex.setText('')
# enables the neural network buttons if there is already an
# existing prediction for the current image.
self.EnableCNNButtons()
def ChangeTimeFrame(self):
"""This funcion is called whenever the user gives an new time index,
to jump to the new given index, onces "enter" button is pressed.
"""
# it reads out the text in the button and converts it to an int.
newtimeindex = int(self.button_timeindex.text())
if newtimeindex >= 0 and newtimeindex <= self.reader.sizet-1:
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
if self.Tindex == 0:
self.button_nextframe.setEnabled(True)
self.m.nextpicture = self.reader.LoadOneImage(self.Tindex+1,self.FOVindex)
self.m.nextplotmask = self.reader.LoadMask(self.Tindex+1, self.FOVindex)
self.m.currpicture = self.reader.LoadOneImage(self.Tindex, self.FOVindex)
self.m.plotmask = self.reader.LoadMask(self.Tindex, self.FOVindex)
self.m.prevpicture = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.prevplotmask = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.UpdateBckgrndPicture()
self.button_previousframe.setEnabled(False)
elif self.Tindex == self.reader.sizet-1:
self.button_previousframe.setEnabled(True)
self.m.prevpicture = self.reader.LoadOneImage(self.Tindex-1, self.FOVindex)
self.m.prevplotmask = self.reader.LoadMask(self.Tindex-1, self.FOVindex)
self.m.currpicture = self.reader.LoadOneImage(self.Tindex, self.FOVindex)
self.m.plotmask = self.reader.LoadMask(self.Tindex, self.FOVindex)
self.m.nextpicture = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.nextplotmask = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.UpdateBckgrndPicture()
self.button_nextframe.setEnabled(False)
self.button_nextframe.setEnabled(True)
self.button_previousframe.setEnabled(True)
self.m.prevpicture = self.reader.LoadOneImage(self.Tindex-1, self.FOVindex)
self.m.prevplotmask = self.reader.LoadMask(self.Tindex-1, self.FOVindex)
self.m.currpicture = self.reader.LoadOneImage(self.Tindex, self.FOVindex)
self.m.plotmask = self.reader.LoadMask(self.Tindex, self.FOVindex)
self.m.nextpicture = self.reader.LoadOneImage(self.Tindex+1,self.FOVindex)
self.m.nextplotmask = self.reader.LoadMask(self.Tindex+1, self.FOVindex)
self.UpdateTitleSubplots()
self.button_timeindex.clearFocus()
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
if self.button_hidemask.isChecked():
self.m.HideMask()
self.EnableCNNButtons()
else:
self.button_timeindex.clearFocus()
return
# def keyPressEvent(self, event):
## print('keypressevengda211111')
## print(event.key())
# if not self.button_nextframe.isChecked() and event.key() == Qt.Key_Right:
# self.button_nextframe.setChecked(True)
# self.ForwardTime()
# self.button_nextframe.setChecked(False)
# else:
# print('inside keypressevent')
# event.ignore()
def CellCorrespActivation(self):
self.Disable(self.button_cellcorespondance)
self.statusBar.showMessage('Doing the cell correspondance')
if self.Tindex != 0:
self.m.plotmask,_ = self.reader.CellCorrespondance(self.Tindex, self.FOVindex)
self.m.updatedata()
else:
self.m.plotmask = self.reader.LoadSeg(self.Tindex, self.FOVindex)
self.m.updatedata()
self.Enable(self.button_cellcorespondance)
self.button_cellcorespondance.setChecked(False)
self.statusBar.clearMessage()
self.Disable(self.button_segment)
self.EnableCorrectionsButtons()
self.m.SegmentedMask = self.reader.LoadSeg(self.Tindex, self.FOVindex)
self.m.tempplotmask = self.m.plotmask.copy()
self.m.plotmask = self.m.SegmentedMask.copy()
self.m.currmask.set_data((self.m.SegmentedMask%10 + 1)*(self.m.SegmentedMask != 0))
self.m.ax.draw_artist(self.m.currplot)
self.m.ax.draw_artist(self.m.currmask)
self.m.update()
self.m.flush_events()
# update the graph
self.button_SetSegmentation.setEnabled(True)
self.button_savesegmask.setEnabled(True)
else:
self.m.SegmentedMask = self.m.plotmask.copy()
self.m.plotmask = self.m.tempplotmask.copy()
self.m.updatedata()
self.button_SetSegmentation.setEnabled(False)
self.button_savesegmask.setEnabled(False)
self.Enable(self.button_segment)
segparamvalue = int(self.button_SetSegmentation.text())
self.m.plotmask = self.reader.Segment(segparamvalue, self.Tindex,self.FOVindex)
self.m.currmask.set_data((self.m.plotmask%10 + 1)*(self.m.plotmask != 0))
self.m.ax.draw_artist(self.m.currplot)
self.m.ax.draw_artist(self.m.currmask)
self.m.update()
self.m.flush_events()
# self.m.SegmentedMask = self.reader.Segment(segparamvalue, self.Tindex, self.FOVindex)
# update the plots to display the segmentation view
def ButtonSaveSegMask(self):
"""saves the segmented mask
"""
self.reader.SaveSegMask(self.Tindex, self.FOVindex, self.m.plotmask)
"""if the buttons is checked it shows the thresholded version of the
prediction, if it is not available it justs displays a null array.
The buttons for the setting a threshold a value and to save it are then
activated once this button is enabled.
"""
if self.button_threshold.isChecked():
self.Disable(self.button_threshold)
self.m.ThresholdMask = self.reader.LoadThreshold(self.Tindex, self.FOVindex)
self.m.currmask.set_data(self.m.ThresholdMask)
self.m.ax.draw_artist(self.m.currplot)
self.m.ax.draw_artist(self.m.currmask)
self.m.update()
self.m.flush_events()
self.button_SetThreshold.setEnabled(True)
self.button_savethresholdmask.setEnabled(True)
else:
self.m.updatedata()
self.button_SetThreshold.setEnabled(False)
self.button_savethresholdmask.setEnabled(False)
self.Enable(self.button_threshold)
def ThresholdPrediction(self):
thresholdvalue = float(self.button_SetThreshold.text())
self.m.ThresholdMask = self.reader.ThresholdPred(thresholdvalue, self.Tindex,self.FOVindex)
self.m.currmask.set_data(self.m.ThresholdMask)
self.m.ax.draw_artist(self.m.currplot)
self.m.ax.draw_artist(self.m.currmask)
self.m.update()
self.m.flush_events()
# self.m.ThresholdMask = self.reader.ThresholdPred(thresholdvalue, self.Tindex, self.FOVindex)
# update the plots to display the thresholded view
def ButtonSaveThresholdMask(self):
"""saves the thresholed mask
"""
# pass
self.reader.SaveThresholdMask(self.Tindex, self.FOVindex, self.m.ThresholdMask)
"""This function is called when the previous frame buttons is pressed
and it tests if the buttons is enabled and if so it calls the
BackwardTime() function. It should avoid the let the user do multiple
clicks and that the function is then called afterwards several times,
once the frames and masks of the current time index have been loaded.
"""
if self.button_previousframe.isEnabled():
self.button_previousframe.setEnabled(False)
# self.button_nextframe.disconnect()
# self.button_nextframe.setShortcut('')
# self.button_nextframe.setEnabled(False)
# print(self.button_nextframe.isEnabled())
# self.button_nextframe.setChecked(False)
# self.Testbool = False
self.BackwardTime()
# self.button_nextframe.setShortcut(Qt.Key_Right)
# self.button_nextframe.pressed.connect(self.Test)
# self.button_nextframe.setChecked(False)
if self.Tindex >0:
self.button_previousframe.setEnabled(True)
# self.button_nextframe.pressed.connect(self.Test)
# self.button_nextframe.setChecked(False)
# self.Testbool = True
else:
# print('jamais la dedans?')
return
"""This function is called when the next frame buttons is pressed
and it tests if the buttons is enabled and if so it calls the
ForwardTime() function. It should avoid the let the user do multiple
clicks and that the function is then called afterwards several times,
once the frames and masks of the current time index have been loaded.
"""
# self.button_nextframe.setShortcutEnabled(False)
if self.button_nextframe.isEnabled():
self.button_nextframe.setEnabled(False)
# self.button_nextframe.disconnect()
# self.button_nextframe.setShortcut('')
# self.button_nextframe.setEnabled(False)
# print(self.button_nextframe.isEnabled())
# self.button_nextframe.setChecked(False)
# self.Testbool = False
self.ForwardTime()
# self.button_nextframe.setShortcut(Qt.Key_Right)
# self.button_nextframe.pressed.connect(self.Test)
# self.button_nextframe.setChecked(False)
self.button_nextframe.setEnabled(True)
# self.button_nextframe.pressed.connect(self.Test)
# self.button_nextframe.setChecked(False)
# self.Testbool = True
else:
return
# print('jamais la dedans?')
# if QKeyEvent.key() == Qt.Key_Right:
# QKeyEvent.ignore()
"""This function switches the frame in forward time index. And it tests
several conditions if t == lastTimeIndex-1, because then the next frame
button has to be disabled. It also tests if the show value of cells
button and hidemask are active in order to hide/show the mask or to
show the cell values.
"""
# print(self.Tindex)
# the t frame is defined as the currently shown frame on the display.
# If the button "Next time frame" is pressed, this function is called
self.statusBar.showMessage('Loading the next frame...')
# self.button_nextframe.setEnabled(False)
# self.button_nextframe.disconnect()
self.Disable(self.button_nextframe)
if self.Tindex + 1 < self.reader.sizet - 1 :
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
self.m.prevpicture = self.m.currpicture.copy()
self.m.prevplotmask = self.m.plotmask.copy()
self.m.currpicture = self.m.nextpicture.copy()
self.m.plotmask = self.m.nextplotmask.copy()
self.m.nextpicture = self.reader.LoadOneImage(self.Tindex+2, self.FOVindex)
self.m.nextplotmask = self.reader.LoadMask(self.Tindex+2, self.FOVindex)
self.m.UpdateBckgrndPicture()
if self.Tindex + 1 == 1:
self.button_previousframe.setEnabled(True)
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
self.m.prevpicture = self.m.currpicture.copy()
self.m.prevplotmask = self.m.plotmask.copy()
self.m.currpicture = self.m.nextpicture.copy()
self.m.plotmask = self.m.nextplotmask.copy()
self.m.nextpicture = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.nextplotmask = np.zeros([self.reader.sizey,self.reader.sizex], dtype = np.uint16)
self.m.UpdateBckgrndPicture()
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
self.Tindex = self.Tindex+1
self.UpdateTitleSubplots()
if self.button_hidemask.isChecked():
self.m.HideMask()
self.Enable(self.button_nextframe)
# self.button_nextframe.setChecked(False)
self.statusBar.clearMessage()
# if self.Tindex < self.reader.sizet - 1 :
# self.button_nextframe.setEnabled(True)
self.button_timeindex.setText(str(self.Tindex))
"""This function switches the frame in backward time index. And it
several conditions if t == 1, because then the button previous frame has to
be disabled. It also tests if the show value of cells button and
hidemask are active in order to hide/show the mask or to show the cell
values.
"""
# print(self.Tindex)
# the t frame is defined as the currently shown frame on the display.
# If the button "Previous time frame" is pressed, this function is called
self.statusBar.showMessage('Loading the previous frame...')
# self.button_previousframe.setEnabled(False)
# self.button_previousframe.disconnect()
self.Disable(self.button_previousframe)
if self.Tindex == 1:
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
self.m.nextpicture = self.m.currpicture.copy()
self.m.nextplotmask = self.m.plotmask.copy()
self.m.currpicture = self.m.prevpicture.copy()
self.m.plotmask = self.m.prevplotmask.copy()
self.m.prevpicture = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.prevplotmask = np.zeros([self.reader.sizey, self.reader.sizex], dtype = np.uint16)
self.m.UpdateBckgrndPicture()
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
self.m.nextpicture = self.m.currpicture.copy()
self.m.nextplotmask = self.m.plotmask.copy()
self.m.currpicture = self.m.prevpicture.copy()
self.m.plotmask = self.m.prevplotmask.copy()
self.m.prevpicture = self.reader.LoadOneImage(self.Tindex-2, self.FOVindex)
self.m.prevplotmask = self.reader.LoadMask(self.Tindex-2, self.FOVindex)
self.m.UpdateBckgrndPicture()
if self.Tindex-1 == self.reader.sizet-2:
self.button_nextframe.setEnabled(True)
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
# self.button_previousframe.clicked.connect(self.BackwardTime)
self.Tindex = self.Tindex-1
self.UpdateTitleSubplots()
if self.button_hidemask.isChecked():
self.m.HideMask()
self.button_previousframe.setEnabled(True)
# self.button_previousframe.setChecked(False)
self.statusBar.clearMessage()
self.button_timeindex.setText(str(self.Tindex))
def MouseDraw(self):
"""
This function is called whenever the brush or the eraser button is
pressed. On the first press event it calls the self.m.OneClick, which
tests whether it is a right click or a left click. If it a right click
it assigns the value of the pixel which has been right clicked
to self.cellval, meaning that the next drawn pixels will be set to this
value.
If it is left clicked, then it draws a 3x3 square with the current
value of self.cellval.
If after left clicking you drag the mouse, then you start drawing
using the mouse and it stops once you release the left click.
Same for the eraser button, it sets directly the value of self.cellval
to 0.
"""
self.statusBar.showMessage('Drawing using the brush, right click to set a value...')
self.Disable(self.button_drawmouse)
self.m.tempmask = self.m.plotmask.copy()
self.id2 = self.m.mpl_connect('button_press_event', self.m.OneClick)
self.id = self.m.mpl_connect('motion_notify_event', self.m.PaintBrush)
self.id3 = self.m.mpl_connect('button_release_event', self.m.ReleaseClick)
pixmap = QtGui.QPixmap('./icons/brush2.png')
cursor = QtGui.QCursor(pixmap, 1,1)
QApplication.setOverrideCursor(cursor)
self.statusBar.showMessage('Erasing by setting the values to 0...')
self.Disable(self.button_eraser)
self.m.cellval = 0
self.id2 = self.m.mpl_connect('button_press_event', self.m.OneClick)
self.id = self.m.mpl_connect('motion_notify_event', self.m.PaintBrush)
self.id3 = self.m.mpl_connect('button_release_event', self.m.ReleaseClick)
pixmap = QtGui.QPixmap('./icons/eraser.png')
cursor = QtGui.QCursor(pixmap, 1,1)
QApplication.setOverrideCursor(cursor)
else:
self.m.mpl_disconnect(self.id3)
self.m.mpl_disconnect(self.id2)
self.m.mpl_disconnect(self.id)
QApplication.restoreOverrideCursor()
self.Enable(self.button_drawmouse)
self.Enable(self.button_eraser)
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
self.statusBar.clearMessage()
"""This function updates the title of the plots according to the
current time index. So it called whenever a frame or a fov is changed.
"""
if self.Tindex == 0:
self.m.titlecurr.set_text('Time index {}'.format(self.Tindex))
self.m.titleprev.set_text('No frame {}'.format(''))
self.m.titlenext.set_text('Next Time index {}'.format(self.Tindex+1))
# self.m.ax.set_title('Time index {}'.format(self.Tindex))
# self.m.ax2.set_title('No frame {}'.format(''))
# self.m.ax3.set_title('Next Time index {}'.format(self.Tindex+1))
# self.m.update()
# self.m.flush_events()
self.m.draw()
elif self.Tindex == self.reader.sizet-1:
self.m.titlecurr.set_text('Time index {}'.format(self.Tindex))
self.m.titleprev.set_text('Previous time index {}'.format(self.Tindex-1))
self.m.titlenext.set_text('No frame {}'.format(''))
# self.m.ax.set_title('Time index {}'.format(self.Tindex))
# self.m.ax2.set_title('Previous time index {}'.format(self.Tindex-1))
# self.m.ax3.set_title('No frame {}'.format(''))
# self.m.update()
# self.m.flush_events()
self.m.draw()
else:
self.m.titlecurr.set_text('Time index {}'.format(self.Tindex))
self.m.titleprev.set_text('Previous time index {}'.format(self.Tindex-1))
self.m.titlenext.set_text('Next Time index {}'.format(self.Tindex+1))
# self.m.ax.set_title('Time index {}'.format(self.Tindex))
# self.m.ax2.set_title('Previous time index {}'.format(self.Tindex-1))
# self.m.ax3.set_title('Next Time index {}'.format(self.Tindex+1))
# self.m.update()
# self.m.flush_events()
self.m.draw()
this method is called when the button New Cell is clicked. If the button
state corresponds to True (if is activated) then it connects the mouse
clicks on the pyqt window to the canvas (so to the matplolib figure).
The connection has an "id" which is given by the integer self.id
After the connections is made, it calls the Disable function with argument 0
which turns off the other button(s).
If the button is clicked but it is deactivated then it disconnects the
connection between the canvas and the window (the user can not interact
Storemouseclicks is a list corresponding to the coordinates of all mouse
clicks between the activation and the deactivation of the button.
So if it is empty, it does not draw anything because no clicks
But if it has some coordinates, it will draw a polygon where the vertices
are the coordinates of all the mouseclicks.
Once the figure has been updated with a new polygon, the other button(s)
"""
if self.button_newcell.isChecked():
self.statusBar.showMessage('Draw a new cell...')
self.m.tempmask = self.m.plotmask.copy()
self.id = self.m.mpl_connect('button_press_event', self.m.MouseClick)
self.Disable(self.button_newcell)
self.m.mpl_disconnect(self.id)
if self.m.storemouseclicks and self.TestSelectedPoints():
self.m.DrawRegion(True)
else:
self.m.updatedata()
self.Enable(self.button_newcell)
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
self.statusBar.clearMessage()
"""This function is just used to catch an exception, when the new cell
or the add region function is called. If all the dots drawn by the user
are located on one line (horizontal or vertical) the DrawRegion
function calls a method to create a polygon and
it can not make a polygon out of straight line so it gives an error.
In order to prevent this error, this function avoids to attempt to draw
by returning False if the square are all on one line.
"""
allx = list(np.array(self.m.storemouseclicks)[:,0])
ally = list(np.array(self.m.storemouseclicks)[:,1])
resultx = all(elem == allx[0] for elem in allx)
resulty = all(elem == ally[0] for elem in ally)
if resultx or resulty:
return False
else:
return True
this method is called when the button Add region is clicked. If the button
state corresponds to True (if is activated) then it connects the mouse
clicks on the pyqt window to the canvas (so to the matplolib figure).
The connection has an "id" which is given by the integer self.id
After the connections is made, it calls the Disable function with argument 1
which turns off the other button(s).
If the button is clicked and it is deactivated then it disconnects the
connection between the canvas and the window (the user can not interact
Storemouseclicks is a list corresponding to the coordinates of all mouse
clicks between the activation and the deactivation of the button.
So if it is empty, it does not draw anything because no clicks
But if it has some coordinates, it will draw a polygon where the vertices
are the coordinates of all the mouseclicks.
Once the figure has been updated with a new polygon, the other button(s)
"""
if self.button_add_region.isChecked():
self.statusBar.showMessage('Adding a region to an existing cell...')
self.m.tempmask = self.m.plotmask.copy()
self.id = self.m.mpl_connect('button_press_event', self.m.MouseClick)
self.Disable(self.button_add_region)
# test if the list is not empty and if the dots are not all in the same line
if self.m.storemouseclicks and self.TestSelectedPoints():
self.m.DrawRegion(False)
else:
self.m.updatedata()
self.Enable(self.button_add_region)
if self.button_showval.isChecked():
self.m.ShowCellNumbersCurr()
self.m.ShowCellNumbersNext()
self.m.ShowCellNumbersPrev()
"""
this functions turns on buttons all the buttons, depending on the time
index. (next and previous buttons should not be turned on if t = 0
or t = lasttimeindex)
"""
if self.button_segment.isChecked():
self.EnableCorrectionsButtons()
self.button_home.setEnabled(True)
self.button_zoom.setEnabled(True)
self.button_pan.setEnabled(True)
self.button_back.setEnabled(True)
self.button_forward.setEnabled(True)
else:
for k in range(0, len(self.buttonlist)):
if button != self.buttonlist[k]:
self.buttonlist[k].setEnabled(True)
if self.Tindex == 0:
self.button_previousframe.setEnabled(False)
if self.Tindex == self.reader.sizet-1:
self.button_nextframe.setEnabled(False)
this functions turns off all the buttons except the one given in
argument.
"""
flag = False
if button == self.button_add_region or button == self.button_newcell or button == self.button_exval or button == self.button_changecellvalue or button == self.button_drawmouse or button == self.button_eraser:
if self.button_segment.isChecked():
flag = True
for k in range(0,len(self.buttonlist)):
if button != self.buttonlist[k]:
self.buttonlist[k].setEnabled(False)
if flag:
self.button_segment.setEnabled(True)
if button == self.button_segment or button == self.button_threshold:
self.button_home.setEnabled(True)
self.button_zoom.setEnabled(True)
self.button_pan.setEnabled(True)
self.button_back.setEnabled(True)
self.button_forward.setEnabled(True)
def EnableCNNButtons(self):
if self.reader.TestPredExisting(self.Tindex, self.FOVindex):
# self.button_cnn.setEnabled(False)
self.button_threshold.setEnabled(True)
self.button_segment.setEnabled(True)
self.button_cellcorespondance.setEnabled(True)
self.button_extractfluorescence.setEnabled(True)
else:
# self.button_cnn.setEnabled(True)
self.button_threshold.setEnabled(False)
self.button_segment.setEnabled(False)
self.button_cellcorespondance.setEnabled(False)
self.button_extractfluorescence.setEnabled(False)
def EnableCorrectionsButtons(self):
self.button_newcell.setEnabled(True)
self.button_add_region.setEnabled(True)
self.button_drawmouse.setEnabled(True)
self.button_eraser.setEnabled(True)
self.button_exval.setEnabled(True)
self.button_changecellvalue.setEnabled(True)
self.button_showval.setEnabled(True)
def DisableCorrectionsButtons(self):
self.button_newcell.setEnabled(False)
self.button_add_region.setEnabled(False)
self.button_drawmouse.setEnabled(False)
self.button_eraser.setEnabled(False)
self.button_exval.setEnabled(False)
self.button_changecellvalue.setEnabled(False)
self.button_showval.setEnabled(False)
def ButtonSaveMask(self):
"""
When this function is called, it saves the current mask
(self.m.plotmask)
"""
self.reader.SaveMask(self.Tindex, self.FOVindex, self.m.plotmask)
class PlotCanvas(FigureCanvas):
def __init__(self, parent=None):
"""this class defines the canvas. It initializes a figure, which is then
used to plot our data using imshow.
# define three subplots corresponding to the previous, current and next
# time index.
fig, (self.ax2, self.ax, self.ax3) = plt.subplots(1,3, sharex = True, sharey = True)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
# this is some mambo jambo.
FigureCanvas.setSizePolicy(self,
QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
# the self.currpicture attribute takes the original data and will then
self.ThresholdMask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype = np.uint16)
self.SegmentedMask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype = np.uint16)
# this line is just here to not attribute a zero value to the plot
# because if so, then it does not update the plot and it stays blank.
# (it is unclear why..if someone finds a better solution)
self.prevpicture = self.currpicture.copy()
self.currplot, self.currmask = self.plot(self.currpicture, self.plotmask, self.ax)
self.previousplot, self.previousmask = self.plot(self.prevpicture, self.prevplotmask, self.ax2)
self.prevpicture = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype = np.uint16)
self.prevplotmask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype =np.uint16)
# print('set visible')
# self.ax2.set_visible(False)
self.nextplot, self.nextmask = self.plot(self.nextpicture, self.nextplotmask, self.ax3)
self.previousplot.set_data(self.prevpicture)
self.previousmask.set_data((self.prevplotmask%10+1)*(self.prevplotmask != 0))
self.ax2.draw_artist(self.previousplot)
self.ax2.draw_artist(self.previousmask)
self.update()
self.flush_events()
self.titlecurr = self.ax.set_title('Time index {}'.format(parent.Tindex))
self.titleprev = self.ax2.set_title('No frame {}'.format(''))
self.titlenext = self.ax3.set_title('Next Time index {}'.format(parent.Tindex+1))
# these variables are just set to test the states of the buttons
# (button turned on or off, etc..) of the buttons in the methods
# used in this class.
self.button_showval_check = parent.button_showval
self.button_newcell_check = parent.button_newcell
self.button_add_region_check = parent.button_add_region
self.button_drawmouse_check = parent.button_drawmouse
self.button_eraser_check = parent.button_eraser
self.button_hidemask_check = parent.button_hidemask
# It will plot for the first time and return the imshow function
self.currmask.set_clim(0, 10)
self.previousmask.set_clim(0,10)
self.nextmask.set_clim(0,10)
# This attribute is a list which stores all the clicks of the mouse.
self.storemouseclicks = []
# This attribute is used to store the square where the mouse has been
# in order than to draw lines (Paintbrush function)
self.storebrushclicks = [[False,False]]
# self.cellval is the variable which sets the value to the pixel