Commit 777b6637 authored by Antonio Politi's avatar Antonio Politi

Fixed image show up

parent a157acb7
......@@ -159,7 +159,7 @@ class LocDialogParameters(DialogParameters):
fileExt = ['.lsm', '.czi']
if jobnr is not None and jobnr != ijob:
continue
if imgprefix not in filename[0]:
if imgprefix not in filename[0] and jobnr is None:
IJ.log("Nothing to do for " + afile)
continue
if filename[1] not in fileExt:
......@@ -172,7 +172,7 @@ class LocDialogParameters(DialogParameters):
if imageDef is None:
IJ.log("Could not open " + afile)
continue
[imageC, pixelSize, filepath, LUTs] = imageDef
[imageC, pixelSize, filepath] = imageDef
jobl['channel_seg'] = int(jobl['channel_seg'])
......@@ -210,8 +210,8 @@ class LocDialogParameters(DialogParameters):
channel_to_use = [jobl['channel_seg'] - 1]
for ithr in [1, 2]:
if jobl['channel_thr%d' % ithr] != "None":
channel_to_use.append(jobl['channel_thr%d' % ithr]-1)
channel_to_use.append(int(jobl['channel_thr%d' % ithr])-1)
imgs_to_use = [imageC[ch] for ch in channel_to_use] # this is for display
# segment channel channel_seg and create binary
try:
self.rois[ijob], self.Segs[ijob], self.Procs[ijob] = segmentChannel(imageC, areas, **jobl)
......@@ -219,58 +219,59 @@ class LocDialogParameters(DialogParameters):
self.exitWithError(str(err))
return
if self.rois[ijob] is None:
IJ.run("Read Write Windows Registry",
"action=write location=[HKCU\\%s] key=%s value=[%s] windows=REG_SZ" % (
zk.regkey, zk.subkey_codemic, msg.CODE_NOTHING))
for img in imageC[channel_to_use]:
img.show()
if self.showAllImages.isSelected():
for img in imgs_to_use:
img.show()
continue
self.Segs[ijob].setTitle(filename[0] + "_Binary")
# pick particle of interest and write commands for scope to registry
particle, ptsFcs, self.rois[ijob] = executeTask(self.rois[ijob], self.Segs[ijob], imageC, pixelSize,
**jobl)
# load and show original projected image using the required channels
# TODO: Clean up the showing part of the function
if self.showAllImages.isSelected():
Zp = ZProjector()
Zp.setMethod(ZProjector.MAX_METHOD)
imgP = list()
for img in imgs_to_use:
img.deleteRoi()
imgP.append(img.duplicate())
if imgP[0].getNSlices > 0:
for ind, img in enumerate(imgP):
Zp.setImage(img)
Zp.doProjection()
imgP[ind] = Zp.getProjection()
if len(imgP) > 1:
rgbmerge = RGBStackMerge()
imgO = rgbmerge.mergeHyperstacks(imgP, True)
else:
imgO = imgP[0]
imgO.setTitle('MAX_%s' % filename[0])
imgO.setDisplayMode(IJ.GRAYSCALE)
for img in imgs_to_use:
img.setDisplayMode(IJ.GRAYSCALE)
img.show()
imgO.show()
# self.Segs[ijob].setTitle(filename[0] + "_Binary")
# # switch color to Cyan for better visibility
# IJ.run(imageC[jobl['channel_seg'] - 1], "Cyan", "")
#
#
# # pick particle of interest and write commands for scope to registry
# particle, ptsFcs, self.rois[ijob] = executeTask(self.rois[ijob], self.Segs[ijob], imageC, pixelSize,
# **jobl)
#
# # load and show original projected image
#
# if show:
# Zp = ZProjector()
# Zp.setMethod(ZProjector.MAX_METHOD)
# imgP = []
# for img in imageC:
# imgP.append(img.duplicate())
# if imgP[0].getNSlices > 0:
# for ind, img in enumerate(imgP):
# Zp.setImage(img)
# Zp.doProjection()
# imgP[ind] = Zp.getProjection()
# #if len(imgP) > 1:
# # rgbmerge = RGBStackMerge()
# # imgO = rgbmerge.mergeChannels(imgP, True)
# # imgO.setLuts(LUTs)
# #else:
# #imgO = imgP[0]
# #imgO.setTitle('MAX_%s' % filename[0])
# #imgO.show()
# imageC[job['channel_seg']-1].show()
#
#
# if particle is None or len(particle) == 0:
# IJ.run("Collect Garbage", "")
# return
# # report results
# impOut = autTool.createOutputImg(self.Procs[ijob], self.rois[ijob], particle, ptsFcs)
# impOut.setTitle("Picked_particle")
# if show:
# impOut.show()
# self.saveOutputImg(impOut, filepath, ijob + 1)
# IJ.run("Collect Garbage", "")
if particle is None or len(particle) == 0:
IJ.run("Collect Garbage", "")
return
# report results
# switch color to Cyan for better visibility
IJ.run(self.Procs[ijob], "Cyan", "")
imgOut = autTool.createOutputImg(self.Procs[ijob], self.rois[ijob], particle, ptsFcs)
imgOut.setTitle("Picked_particle")
if show:
imgOut.show()
self.saveOutputImg(imgOut, filepath, ijob + 1)
IJ.run("Collect Garbage", "")
except BaseException, err:
self.exitWithError('%s at line %d' % (str(err), sys.exc_traceback.tb_lineno))
......
......@@ -64,7 +64,8 @@ class WindowEventHandler(WindowAdapter):
class FileListener(FileAlterationListenerAdaptor):
''' Define methods FileAlterationListenerAdaptor method run on file will be created at runTime'''
def __init__(self, runOnFile=None, onlyNewFiles=True):
def __init__(self, runOnFile = None, onlyNewFiles = True):
super(FileListener, self).__init__()
super(FileListener, self).__init__()
self.onlyNewFiles = onlyNewFiles
if runOnFile:
......@@ -93,7 +94,7 @@ class DialogMonitor(object):
waitForImageOpening = 0.2
__slots__ = ['frameMain', 'framePara', 'monitor', 'observer', 'listener', 'dirField', 'msgLabel1', 'msgLabel2']
def __init__(self, macroName, waitingtime = 1, pollingtime = 50):
def __init__(self, macroName, waitingtime = 0.2, pollingtime = 50):
# pollingTime should not be too short otherwise the system get confused. 50 ms
self.pollingTime = pollingtime
# if an image is to be opened wait a delay of sec before opening it
......@@ -119,13 +120,15 @@ class DialogMonitor(object):
panel.setLayout(BoxLayout(panel, BoxLayout.LINE_AXIS))
panel.setBorder(BorderFactory.createTitledBorder("Directory to monitor"))
self.dirField = JTextField('', 50)
self.dirField = JTextField('', 30)
panel.add(self.dirField)
panel.add(JButton('...', actionPerformed=self.open_folder))
self.onlyNewFiles = JCheckBox('analyze only new files', actionPerformed=self.restart)
self.showAllImages = JCheckBox('Show all images')
panel.add(self.onlyNewFiles)
panel.add(self.showAllImages)
self.onlyNewFiles.getModel().setSelected(True)
pane.add(panel, BorderLayout.NORTH)
......@@ -194,7 +197,8 @@ class DialogMonitor(object):
openfile and split channels returns Channel splitted ImageJ plus pixelSize filepath and filaname
:param filepath: path to file
:param time: start and end time point to analyze
:return:
:return: [imageC, pixelSize, filepath, LUTs]
"""
fileends = ['.czi', '.lsm']
if filepath == '':
......@@ -221,11 +225,9 @@ class DialogMonitor(object):
if imageC is None:
raise NameError('Fiji failed to open image ' + filepath)
pixelSize = imageC[0].getCalibration().pixelWidth
LUTs = list()
for i in range(0, len(imageC)):
IJ.run(imageC[i], "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel")
LUTs.append(imageC[i].getLuts())
return [imageC, pixelSize, filepath, LUTs]
for i, img in enumerate(imageC):
IJ.run(img, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel")
return [imageC, pixelSize, filepath]
def getPrefix(self, pip, task):
......@@ -295,10 +297,10 @@ class DialogMonitor(object):
self.activateButtons(1)
self.msgLabel1.setText("")
def runOnFile(self, file, show=True, jobnr=None):
def runOnFile(self, file, show = True, jobnr = None):
'''executed on new files or modified image files. To be defined in child class'''
IJ.log('No method runOnFile has been defined, just open the image')
imageDef = self.openFile(file, '', 1)
imageDef = self.openFile(file, time = [0, 0])
print imageDef
if imageDef is not None:
[imageC, pixelSize, filepath, filename] = imageDef
......@@ -343,7 +345,7 @@ class DialogMonitor(object):
try:
self.getParameters()
self.saving = 0
Thread(target=self.runOnFile, args=('', 1, int(event.getSource().getClientProperty("job")))).start()
Thread(target = self.runOnFile, args=('', 1, int(event.getSource().getClientProperty("job")))).start()
except Exception, err:
IJ.log('error ' + str(err))
......
Markdown is supported
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