Added the ability of the user to choose the channel for which he wants to compute the white estimate.
As a result the Estimate White plugin is now usable.
This commit is contained in:
parent
e6217b38a3
commit
d71793ad9c
|
@ -28,13 +28,79 @@ from lipase.imagej.ijimageengine import IJImageEngine
|
|||
from lipase.preprocessing import WhiteEstimator
|
||||
from lipase.catalog import ImageCatalog
|
||||
|
||||
from ij import IJ
|
||||
from ij.gui import GenericDialog, DialogListener
|
||||
from java.awt.event import ItemListener
|
||||
|
||||
# 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()
|
||||
for channel_id in channel_ids:
|
||||
self.channel_choice.add(channel_id)
|
||||
|
||||
|
||||
def ask_for_sequence(catalog):
|
||||
title = 'select the sequence to process'
|
||||
gd = GenericDialog(title)
|
||||
# gd.addDialogListener(MyListener())
|
||||
sequence_ids = catalog.sequences.keys()
|
||||
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_channel_id = catalog.sequences[selected_sequence_id].get_channel_names()[gd.getNextChoiceIndex()] # eg 'DM300_327-353_fluo'
|
||||
print("chosen sequence : %s" % selected_sequence_id)
|
||||
print("chosen channel : %s" % selected_channel_id)
|
||||
return {'sequence': catalog.sequences[selected_sequence_id], 'channel_id':selected_channel_id}
|
||||
|
||||
|
||||
def run_script():
|
||||
user_settings = UserSettings()
|
||||
IImageEngine.set_instance(IJImageEngine())
|
||||
catalog = ImageCatalog(user_settings.raw_images_root_path)
|
||||
sequence = catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2']
|
||||
user_selection = ask_for_sequence(catalog)
|
||||
if len(user_selection) == 0:
|
||||
return
|
||||
sequence = user_selection['sequence']
|
||||
channel_id = user_selection['channel_id']
|
||||
white_estimator = WhiteEstimator(open_size=75, close_size=75, average_size=75)
|
||||
white_estimate = white_estimator.estimate_white([sequence], ['DM300_327-353_fluo'])
|
||||
white_estimate = white_estimator.estimate_white([sequence], [channel_id])
|
||||
print(type(white_estimate))
|
||||
global WHITE_ESTIMATE
|
||||
WHITE_ESTIMATE = white_estimate.ij_image
|
||||
|
|
|
@ -98,6 +98,10 @@ class Sequence(object):
|
|||
summary = self.mmm['Summary']
|
||||
return summary['ChNames'][channel_index]
|
||||
|
||||
def get_channel_names(self):
|
||||
summary = self.mmm['Summary']
|
||||
return summary['ChNames']
|
||||
|
||||
def get_black(self):
|
||||
''' returns the black sequence related to the the sequence self
|
||||
|
||||
|
|
Loading…
Reference in New Issue