v1.01 : added the "Ipr/Lipase/Compute Globules Area" plugin

fixes #2
This commit is contained in:
Guillaume Raffy 2020-03-27 16:49:21 +01:00
parent 97af360b7b
commit e3ab3b6140
4 changed files with 86 additions and 3 deletions

View File

@ -5,7 +5,7 @@ FIJI_EXE_PATH=$(FIJI_ROOT_PATH)/ImageJ-linux64
RAW_IMAGES_ROOT_PATH:=$(shell echo ~/work/lipase/raw-images)
LIB_SRC_FILES=$(shell find ./src/lipase -name "*.py")
PLUGINS_SRC_FILES=$(shell find ./src/ij-plugins -name "*.py")
LIPASE_VERSION=1.00
LIPASE_VERSION=1.01
BUILD_ROOT_PATH=$(shell pwd)/build
PACKAGE_FILE_PATH=$(shell pwd)/lipase-$(LIPASE_VERSION).zip
@ -96,6 +96,18 @@ test0001: install
echo "test's return code : $$ERROR_CODE" ; \
exit $$ERROR_CODE
.PHONY: test_globules_area
test_globules_area: install
# on macosx : /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run './test0001.py'
# /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run './tests/test0001.py' "lipase_src_root_path='$(pwd)',raw_images_root_path='/Users/graffy/ownCloud/ipr/lipase/raw-images'"
echo 2 > '/tmp/test_result.txt' ; \
$(FIJI_EXE_PATH) --ij2 --headless --run './src/ij-plugins/Ipr/Lipase/Compute_Globules_Area.py' "INPUT_STACK='$RAW_IMAGES_ROOT_PATH/res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0/img_000000000_DM300_nofilter_vis_000.tif', INPUT_BACKGROUND='$RAW_IMAGES_ROOT_PATH/res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0/img_000000000_DM300_nofilter_vis_000.tif', PARTICLE_THRESHOLD='2000'" ; \
ERROR_CODE=$$? ; \
echo "Fiji 's return code : $$ERROR_CODE" ; \
ERROR_CODE=$$(cat '/tmp/test_result.txt') ; \
echo "test's return code : $$ERROR_CODE" ; \
exit $$ERROR_CODE
.PHONY: test
test: test0001

View File

@ -0,0 +1,59 @@
#@ ImagePlus (label="the input image stack") INPUT_STACK
#@ ImagePlus (label="the background image") INPUT_BACKGROUND
#@ Integer (label="particle threshold (in gray levels)", value=2000, min=0, max=32768, style="slider") PARTICLE_THRESHOLD
#@output ImagePlus OUTPUT_PLOT
"""This script is supposed to be launched from fiji's jython interpreter
"""
# # note: fiji's jython doesn't support encoding keyword
import sys
print('python version %s' % sys.version) # prints python version
from lipase.settings import UserSettings
# from lipase import Lipase, ImageLogger
from lipase.imageengine import IImageEngine, PixelType, StackImageFeeder
from lipase.imagej.ijimageengine import IJImageEngine
from lipase.lipase import UserProvidedBackground, GlobulesAreaEstimator
# from ij import IJ # pylint: disable=import-error
# from ij.gui import GenericDialog, DialogListener # pylint: disable=import-error
# from java.awt.event import ItemListener # pylint: disable=import-error
import ij.gui
from jarray import zeros, array
def run_script():
global INPUT_STACK # pylint:disable=global-variable-not-assigned
global INPUT_BACKGROUND # pylint:disable=global-variable-not-assigned
global PARTICLE_THRESHOLD # pylint:disable=global-variable-not-assigned
global OUTPUT_PLOT # pylint:disable=global-variable-not-assigned
IImageEngine.set_instance(IJImageEngine())
src_hyperstack = IImageEngine.get_instance().create_hyperstack(width=1, height=1, num_channels=1, num_slices=1, num_frames=1, pixel_type=PixelType.U8)
src_hyperstack.hyperstack = INPUT_STACK # pylint: disable=undefined-variable
src_background = IImageEngine.get_instance().create_image(width=1, height=1, pixel_type=PixelType.U8)
src_background.ij_image = INPUT_BACKGROUND # pylint: disable=undefined-variable
background_estimator = UserProvidedBackground(background_image=src_background)
processor = GlobulesAreaEstimator(background_estimator=background_estimator, particle_threshold=PARTICLE_THRESHOLD) # pylint: disable=undefined-variable
results = processor.detect_particles(src_hyperstack)
# save_hdf5_file('results.h5', results)
# results file could be checked with "h5dump --xml ./lipase.git/results.h5"
x = array(results['frame index'].elements, 'f')
y = array(results['globules_area_ratio'].elements, 'f')
plot = ij.gui.Plot('my_title', 'frame', 'globules area ratio', x, y)
plot.show()
OUTPUT_PLOT = plot
# note : when launched from fiji, __name__ doesn't have the value "__main__", as when launched from python
run_script()

View File

@ -148,6 +148,18 @@ class IBackgroundEstimator(ABC):
"""
pass
class UserProvidedBackground(IBackgroundEstimator):
def __init__(self, background_image):
"""
:param IImage background_image: the image chosen as background (it is supposed to not contain any particle, only static objects (traps, lens spots, etc.))
"""
IBackgroundEstimator.__init__(self)
self.background_image = background_image
def estimate_background(self, visible_traps_sequence):
return self.background_image
class EmptyFrameBackgroundEstimator(IBackgroundEstimator):
def __init__(self, empty_frame_index):
@ -184,7 +196,7 @@ class GlobulesAreaEstimator(object):
# particles_stack = ie.create_hyperstack(width=background_image.width, height=background_image.height, num_slices=1, num_frames=visible_traps_sequence.num_frames(), num_channels=1, pixel_type=PixelType.F32)
results = Group('')
globules_area = DataSet('globuls_area_ratio', (visible_traps_sequence.num_frames(), ), ElementType.F32)
globules_area = DataSet('globules_area_ratio', (visible_traps_sequence.num_frames(), ), ElementType.F32)
frame_indices = DataSet('frame index', (visible_traps_sequence.num_frames(), ), ElementType.U32)
results.add_dataset(globules_area)
results.add_dataset(frame_indices)

View File

@ -103,7 +103,7 @@ class TestLipase(unittest.TestCase):
results = processor.detect_particles(visible_traps_sequence)
save_hdf5_file('results.h5', results)
# results file could be checked with "h5dump --xml ./lipase.git/results.h5"
first_frame_measured_ratio = results['globuls_area_ratio'][(0,)]
first_frame_measured_ratio = results['globules_area_ratio'][(0,)]
first_frame_expected_ratio = 0.008
self.assertAlmostEqual(first_frame_measured_ratio, first_frame_expected_ratio, delta=0.01)