preprocess_sequence plugin : added the ablilty to smooth the dark image to avoid infinite pixel values in the result
infinite pixel values happen when a pixel in the dark image has the same value as its counterpart in the white image (in a dark area, this can happen)
This commit is contained in:
parent
e397e3aa0f
commit
ae6de7ffef
|
@ -1,10 +1,22 @@
|
||||||
|
#@ String (choices={"no smooth", "gaussian blur"}, style="listBox", value="gaussian blur") DARK_SMOOTH_METHOD
|
||||||
|
#@ Float (label="dark image gaussian blur sigma", style="slider", min=0.0, max=10.0, stepSize=0.1, value=3.0) DARK_GAUSSIAN_BLUR_SIGMA
|
||||||
#@ ImagePlus (label="the input image stack") INPUT_STACK
|
#@ ImagePlus (label="the input image stack") INPUT_STACK
|
||||||
#@ ImagePlus (label="the input white image") INPUT_WHITE
|
#@ ImagePlus (label="the input white image") INPUT_WHITE
|
||||||
#@ ImagePlus (label="the input dark image") INPUT_DARK
|
#@ ImagePlus (label="the input dark image") INPUT_DARK
|
||||||
#@output ImagePlus PREPROCESSED_STACK
|
#@output ImagePlus PREPROCESSED_STACK
|
||||||
|
|
||||||
|
# failed attempt to use alternative input parameters for headless testing but visibility=INVISIBLE doesn't make their widget disappear, unfortunately (see https://imagej.net/Script_parameters.html#Default_values)
|
||||||
|
## String (label="the input image stack", visibility=INVISIBLE) INPUT_STACK_FILE
|
||||||
|
## String (label="the input white image", visibility=INVISIBLE) INPUT_WHITE_FILE
|
||||||
|
## String (label="the input dark image", visibility=INVISIBLE) INPUT_DARK_FILE
|
||||||
|
|
||||||
"""This script is supposed to be launched from fiji's jython interpreter
|
"""This script is supposed to be launched from fiji's jython interpreter
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# to use log.info (see 3d_analytics_CH.py sample)
|
||||||
|
#@LogService log
|
||||||
|
|
||||||
|
|
||||||
#from ij import IJ # pylint: disable=import-error
|
#from ij import IJ # pylint: disable=import-error
|
||||||
|
|
||||||
#WHITE_ESTIMATE = IJ.openImage('/Users/graffy/ownCloud/ipr/lipase/lipase.git/white_estimate.tiff')
|
#WHITE_ESTIMATE = IJ.openImage('/Users/graffy/ownCloud/ipr/lipase/lipase.git/white_estimate.tiff')
|
||||||
|
@ -32,17 +44,9 @@ from lipase.catalog import ImageCatalog
|
||||||
|
|
||||||
from ij import IJ
|
from ij import IJ
|
||||||
from ij.gui import GenericDialog, DialogListener
|
from ij.gui import GenericDialog, DialogListener
|
||||||
|
from ij.plugin.filter import GaussianBlur
|
||||||
from java.awt.event import ItemListener
|
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']
|
|
||||||
|
|
||||||
|
|
||||||
def run_script():
|
def run_script():
|
||||||
user_settings = UserSettings()
|
user_settings = UserSettings()
|
||||||
|
@ -63,19 +67,26 @@ def run_script():
|
||||||
if src_dark.get_pixel_type() != PixelType.F32:
|
if src_dark.get_pixel_type() != PixelType.F32:
|
||||||
src_dark = src_dark.clone(clone_pixel_type=PixelType.F32)
|
src_dark = src_dark.clone(clone_pixel_type=PixelType.F32)
|
||||||
|
|
||||||
|
global DARK_SMOOTH_METHOD
|
||||||
|
global DARK_GAUSSIAN_BLUR_SIGMA
|
||||||
|
log.info('DARK_SMOOTH_METHOD=%s' % DARK_SMOOTH_METHOD)
|
||||||
|
if DARK_SMOOTH_METHOD == 'gaussian blur':
|
||||||
|
log.info('smoothing dark image with gaussian blur filter (sigma=%f)' % DARK_GAUSSIAN_BLUR_SIGMA)
|
||||||
|
# ij.plugin.filter.GaussianBlur
|
||||||
|
# blurGaussian
|
||||||
|
gaussian_blur = GaussianBlur()
|
||||||
|
accuracy = 0.0002 # comes from https://imagej.nih.gov/ij/developer/source/ij/plugin/filter/GaussianBlur.java.html
|
||||||
|
gaussian_blur.blurFloat(src_dark.ij_image.getProcessor(), DARK_GAUSSIAN_BLUR_SIGMA, DARK_GAUSSIAN_BLUR_SIGMA, accuracy)
|
||||||
|
|
||||||
dst_preproc_stack = IImageEngine.get_instance().create_hyperstack(width=src_hyperstack.get_width(), height=src_hyperstack.get_height(), num_channels=src_hyperstack.num_channels(), num_slices=src_hyperstack.num_slices(), num_frames=src_hyperstack.num_frames(), pixel_type=PixelType.F32)
|
dst_preproc_stack = IImageEngine.get_instance().create_hyperstack(width=src_hyperstack.get_width(), height=src_hyperstack.get_height(), num_channels=src_hyperstack.num_channels(), num_slices=src_hyperstack.num_slices(), num_frames=src_hyperstack.num_frames(), pixel_type=PixelType.F32)
|
||||||
|
|
||||||
src_image_feeder = StackImageFeeder(src_hyperstack)
|
src_image_feeder = StackImageFeeder(src_hyperstack)
|
||||||
# dst_image_feeder = StackImageFeeder(dst_preproc_stack)
|
|
||||||
|
|
||||||
src_it = iter(src_image_feeder)
|
src_it = iter(src_image_feeder)
|
||||||
# dst_it = iter(dst_image_feeder)
|
|
||||||
frame_index = 0
|
frame_index = 0
|
||||||
for src_image in src_it:
|
for src_image in src_it:
|
||||||
nomin_image = ie.subtract(src_image, src_dark)
|
nomin_image = ie.subtract(src_image, src_dark)
|
||||||
denom_image = ie.subtract(src_white, src_dark)
|
denom_image = ie.subtract(src_white, src_dark)
|
||||||
# preproc_image = IImageEngine.get_instance().create_image(width=src_hyperstack.get_width(), height=src_hyperstack.get_height(), pixel_type=PixelType.F32)
|
|
||||||
# preproc_image = dst_it.next()
|
|
||||||
preproc_image = ie.divide(nomin_image, denom_image)
|
preproc_image = ie.divide(nomin_image, denom_image)
|
||||||
dst_preproc_stack.set_image(preproc_image, frame_index=frame_index, slice_index=0, channel_index=0) # TODO: use frame_index, slice_index and channel_index from feeder
|
dst_preproc_stack.set_image(preproc_image, frame_index=frame_index, slice_index=0, channel_index=0) # TODO: use frame_index, slice_index and channel_index from feeder
|
||||||
frame_index += 1
|
frame_index += 1
|
||||||
|
|
Loading…
Reference in New Issue