added a plugin that allows the user to display his chosen sequence in imagej

This commit is contained in:
Guillaume Raffy 2019-09-27 14:20:00 +02:00
parent d71793ad9c
commit e8f23bb445
3 changed files with 115 additions and 38 deletions

View File

@ -0,0 +1,75 @@
#@output ImagePlus SEQUENCE
"""This script is supposed to be launched from fiji's jython interpreter
"""
#from ij import IJ # pylint: disable=import-error
#WHITE_ESTIMATE = IJ.openImage('/Users/graffy/ownCloud/ipr/lipase/lipase.git/white_estimate.tiff')
# # note: fiji's jython doesn't support encoding keyword
# https://imagej.net/Scripting_Headless
# String lipase_src_root_path
# String(label="Please enter your name",description="Name field") name
# OUTPUT String greeting
import sys
print('python version %s' % sys.version) # prints python version
from lipase.settings import UserSettings
# it is necassary to add lipase's root path to the path if run from fiji as script otherwise jython fails to find lipase's modules such as catalog
# sys.path.append(lipase_src_root_path) # pylint: disable=undefined-variable
# from lipase import Lipase, ImageLogger
from lipase.preprocessing import test_preprocessing # noqa: E402 pylint: disable=import-error,wrong-import-position
from lipase.imageengine import IImageEngine
from lipase.imagej.ijimageengine import IJImageEngine
from lipase.preprocessing import WhiteEstimator
from lipase.catalog import ImageCatalog
from lipase.imagej import open_sequence_in_imagej
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)
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)
choices = gd.getChoices()
IJ.log("choices = %s" % choices)
sequence_choice = choices[0]
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'
print("chosen sequence : %s" % selected_sequence_id)
return catalog.sequences[selected_sequence_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:
return
sequence_as_stack = open_sequence_in_imagej(sequence)
print(type(sequence_as_stack))
global SEQUENCE
SEQUENCE = sequence_as_stack
# note : when launched from fiji, __name__ doesn't have the value "__main__", as when launched from python
run_script()

View File

@ -127,44 +127,6 @@ class Sequence(object):
white_sequence = seqid_to_white[self.sequence_id]
return self.catalog.sequences[white_sequence]
def as_hyperstack(self):
hyperstack = IJ.createHyperStack(self.sequence_id, self.width, self.height, self.num_channels, self.num_slices, self.num_frames, self.num_bits_per_pixels)
for channel_index in range(self.num_channels):
for frame_index in range(self.num_frames):
slice_index = 0
src_image_file_path = self.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
# print(src_image_file_path)
src_image = IJ.openImage(src_image_file_path)
# print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor())
return hyperstack
def as_stack(self, channel_id):
'''
:param str channel_id: eg 'DM300_327-353_fluo'
'''
channel_index = self.get_channel_index(channel_id)
hyperstack = IJ.createHyperStack(self.sequence_id, self.width, self.height, 1, self.num_slices, self.num_frames, self.num_bits_per_pixels)
for frame_index in range(self.num_frames):
slice_index = 0
src_image_file_path = self.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
# print(src_image_file_path)
src_image = IJ.openImage(src_image_file_path)
# print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor())
return hyperstack
def open_in_imagej(self):
# ip = IJ.createHyperStack(title=self.sequence_id, width=self.width, height= self.height, channels=1, slices=1, frames=self.get_num_frames(), bitdepth=16)
hyperstack = self.as_hyperstack()
hyperstack.show()
for channel_index in range(self.num_channels):
hyperstack.setPositionWithoutUpdate(channel_index + 1, 1, 1)
IJ.run("Enhance Contrast", "saturated=0.35")
return hyperstack
class ImageCatalog(object):
def __init__(self, raw_images_root):

View File

@ -0,0 +1,40 @@
from ij import IJ # pylint: disable=import-error
def open_sequence_as_hyperstack(sequence):
hyperstack = IJ.createHyperStack(sequence.sequence_id, sequence.width, sequence.height, sequence.num_channels, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels)
for channel_index in range(sequence.num_channels):
for frame_index in range(sequence.num_frames):
slice_index = 0
src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
# print(src_image_file_path)
src_image = IJ.openImage(src_image_file_path)
# print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor())
return hyperstack
def open_sequence_as_stack(sequence, channel_id):
'''
:param str channel_id: eg 'DM300_327-353_fluo'
'''
channel_index = sequence.get_channel_index(channel_id)
hyperstack = IJ.createHyperStack(sequence.sequence_id, sequence.width, sequence.height, 1, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels)
for frame_index in range(sequence.num_frames):
slice_index = 0
src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
# print(src_image_file_path)
src_image = IJ.openImage(src_image_file_path)
# print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor())
return hyperstack
def open_sequence_in_imagej(sequence):
# ip = IJ.createHyperStack(title=sequence.sequence_id, width=sequence.width, height= sequence.height, channels=1, slices=1, frames=sequence.get_num_frames(), bitdepth=16)
hyperstack = open_sequence_as_hyperstack(sequence)
hyperstack.show()
for channel_index in range(sequence.num_channels):
hyperstack.setPositionWithoutUpdate(channel_index + 1, 1, 1)
IJ.run("Enhance Contrast", "saturated=0.35")
return hyperstack