The user can now display just a specific channel of a sequence

This will be useful to allow the user to perform some processings on the currently opened stack instead of choosing the stack from a list each time an image processing is launched : this will ease adjustment of image processing parameters.
This commit is contained in:
Guillaume Raffy 2019-10-09 14:36:09 +02:00
parent 738a3a8c25
commit 44dacc1a97
1 changed files with 60 additions and 10 deletions

View File

@ -1,3 +1,4 @@
#@output ImagePlus SEQUENCE
"""This script is supposed to be launched from fiji's jython interpreter
"""
@ -32,11 +33,39 @@ from ij import IJ
from ij.gui import GenericDialog, DialogListener
from java.awt.event import ItemListener
# def SequenceSelectorDialog(GenericDialog):
#
# def __init__(self):
# title = 'select the sequence to process'
# GenericDialog.__init__(self)
# class MyListener(DialogListener):
# def dialogItemChanged(self, gd, event):
# IJ.log("Something was changed (event = %s)" % event)
# IJ.log("event's attributes : %s" % str(dir(event)))
# # Something was changed (event = java.awt.event.ItemEvent[ITEM_STATE_CHANGED,item=res_soleil2018/DARK/DARK_40X_60min_1 im pae min_1/Pos0,stateChange=SELECTED] on choice0)
# # event's attributes : ['ACTION_EVENT_MASK', 'ADJUSTMENT_EVENT_MASK', 'COMPONENT_EVENT_MASK', 'CONTAINER_EVENT_MASK', 'DESELECTED', 'FOCUS_EVENT_MASK', 'HIERARCHY_BOUNDS_EVENT_MASK', 'HIERARCHY_EVENT_MASK', 'ID', 'INPUT_METHOD_EVENT_MASK', 'INVOCATION_EVENT_MASK', 'ITEM_EVENT_MASK', 'ITEM_FIRST', 'ITEM_LAST', 'ITEM_STATE_CHANGED', 'KEY_EVENT_MASK', 'MOUSE_EVENT_MASK', 'MOUSE_MOTION_EVENT_MASK', 'MOUSE_WHEEL_EVENT_MASK', 'PAINT_EVENT_MASK', 'RESERVED_ID_MAX', 'SELECTED', 'TEXT_EVENT_MASK', 'WINDOW_EVENT_MASK', 'WINDOW_FOCUS_EVENT_MASK', 'WINDOW_STATE_EVENT_MASK', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'getID', 'getItem', 'getItemSelectable', 'getSource', 'getStateChange', 'hashCode', 'item', 'itemSelectable', 'notify', 'notifyAll', 'paramString', 'setSource', 'source', 'stateChange', 'toString', 'wait']
class SequenceChoiceListener(ItemListener):
def __init__(self, channel_choice, catalog):
ItemListener.__init__(self)
self.channel_choice = channel_choice
self.catalog = catalog
def itemStateChanged(self, event):
IJ.log("SequenceChoiceListener : Something was changed (event = %s)" % event)
# SequenceChoiceListener : Something was changed (event = java.awt.event.ItemEvent[ITEM_STATE_CHANGED,item=res_soleil2018/DARK/DARK_40X_60min_1 im pae min_1/Pos0,stateChange=SELECTED] on choice3)
IJ.log("SequenceChoiceListener : event's attributes : %s" % str(dir(event)))
# SequenceChoiceListener : event's attributes : ['ACTION_EVENT_MASK', 'ADJUSTMENT_EVENT_MASK', 'COMPONENT_EVENT_MASK', 'CONTAINER_EVENT_MASK', 'DESELECTED', 'FOCUS_EVENT_MASK', 'HIERARCHY_BOUNDS_EVENT_MASK', 'HIERARCHY_EVENT_MASK', 'ID', 'INPUT_METHOD_EVENT_MASK', 'INVOCATION_EVENT_MASK', 'ITEM_EVENT_MASK', 'ITEM_FIRST', 'ITEM_LAST', 'ITEM_STATE_CHANGED', 'KEY_EVENT_MASK', 'MOUSE_EVENT_MASK', 'MOUSE_MOTION_EVENT_MASK', 'MOUSE_WHEEL_EVENT_MASK', 'PAINT_EVENT_MASK', 'RESERVED_ID_MAX', 'SELECTED', 'TEXT_EVENT_MASK', 'WINDOW_EVENT_MASK', 'WINDOW_FOCUS_EVENT_MASK', 'WINDOW_STATE_EVENT_MASK', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'getID', 'getItem', 'getItemSelectable', 'getSource', 'getStateChange', 'hashCode', 'item', 'itemSelectable', 'notify', 'notifyAll', 'paramString', 'setSource', 'source', 'stateChange', 'toString', 'wait']
IJ.log("SequenceChoiceListener : event.item : %s" % str(event.item))
IJ.log("SequenceChoiceListener : type(event.item) : %s" % str(type(event.item)))
selected_sequence_id = event.item
selected_sequence = self.catalog.sequences[selected_sequence_id]
channel_ids = selected_sequence.get_channel_names()
self.channel_choice.removeAll()
self.channel_choice.add('all')
for channel_id in channel_ids:
self.channel_choice.add(channel_id)
def ask_for_sequence(catalog):
title = 'select the sequence to process'
@ -46,25 +75,45 @@ def ask_for_sequence(catalog):
assert len(sequence_ids) > 0
default_sequence_id = sequence_ids[0]
gd.addChoice('sequence', sequence_ids, default_sequence_id)
channel_ids = catalog.sequences[default_sequence_id].get_channel_names()
gd.addChoice('channel', channel_ids, channel_ids[0])
choices = gd.getChoices()
IJ.log("choices = %s" % choices)
sequence_choice = choices[0]
channel_choice = choices[1]
sequence_choice.addItemListener(SequenceChoiceListener(channel_choice, catalog))
gd.showDialog()
if gd.wasCanceled():
return {}
selected_sequence_id = sequence_ids[gd.getNextChoiceIndex()] # eg 'res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2'
selected_sequence = catalog.sequences[selected_sequence_id]
selected_channel_index = gd.getNextChoiceIndex()
if selected_channel_index == 0:
selected_channel_id = 'all'
else:
selected_channel_id = selected_sequence.get_channel_names()[selected_channel_index - 1] # eg 'DM300_327-353_fluo'
print("chosen sequence : %s" % selected_sequence_id)
return catalog.sequences[selected_sequence_id]
print("chosen channel : %s" % selected_channel_id)
return {'sequence': selected_sequence, 'channel_id':selected_channel_id}
def run_script():
user_settings = UserSettings()
IImageEngine.set_instance(IJImageEngine())
catalog = ImageCatalog(user_settings.raw_images_root_path)
sequence = ask_for_sequence(catalog)
if sequence is None:
user_selection = ask_for_sequence(catalog)
if len(user_selection) == 0:
return
sequence_as_stack = open_sequence_in_imagej(sequence)
sequence = user_selection['sequence']
channel_id = str(user_selection['channel_id'])
#white_estimator = WhiteEstimator(open_size=OPEN_SIZE, close_size=CLOSE_SIZE, average_size=AVERAGE_SIZE)
#white_estimate = white_estimator.estimate_white([sequence], [channel_id])
IJ.log("channel_id = %s (type = %s)" % (channel_id, str(type(channel_id))))
if channel_id == 'all':
sequence_as_stack = open_sequence_in_imagej(sequence)
else:
hyperstack = sequence.as_hyperstack(selected_channel_ids=[channel_id], selected_frames=None, selected_slices=None)
sequence_as_stack = hyperstack.hyperstack
print(type(sequence_as_stack))
global SEQUENCE
@ -72,3 +121,4 @@ def run_script():
# note : when launched from fiji, __name__ doesn't have the value "__main__", as when launched from python
run_script()