managed to compute the image mean value

This commit is contained in:
Guillaume Raffy 2019-04-24 12:32:16 +02:00
parent 1c4e9f2597
commit cf68f8900c
1 changed files with 31 additions and 7 deletions

View File

@ -7,7 +7,8 @@
# the 'greeting' output parameter, based on its type.
from ij import IJ # pylint: disable=import-error
from ij import ImagePlus # pylint: disable=import-error
from ij.process import ImageStatistics
from ij.plugin import ImageCalculator
# greeting = "Hello, " + name + "!"
@ -176,13 +177,20 @@ class ImageCatalog(object):
def get_image_median_value(src_image):
return 0
'''
:param ImageProcessor src_image:
'''
# https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html
stats = ImageStatistics.getStatistics(src_image, ImageStatistics.MEDIAN, None)
print(stats)
print(stats.pixelCount)
return stats.median
def test_get_image_median_value():
image_file_path = '/Users/graffy/ownCloud/ipr/lipase/raw-images/res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0/img_000000000_DM300_327-353_fluo_000.tif'
image = IJ.openImage(image_file_path)
median_value = get_image_median_value(image)
median_value = get_image_median_value(image.getProcessor())
print('median value : %d' % median_value)
# double median( cv::Mat channel )
@ -213,12 +221,28 @@ def test_get_image_median_value():
def find_depth_index(src_image, white_sequence):
''' finds in the image sequence white_sequence the image that correlates the best to src_image
:param IJ.ImagePlus src_image:
:param IJ.ImageProcessor src_image:
:param Sequence white_sequence:
'''
src_median_value = get_image_median_value(src_image)
normalized_src = src_image.convertToFloat()
normalized_src.multiply(1.0 / src_median_value)
for z_index in range(white_sequence.num_slices):
white_image_file_path = white_sequence.get_image_file_path(channel_index=0, frame_index=0, z_index=z_index)
white_image = IJ.openImage(white_image_file_path)
white_median_value = get_image_median_value(white_image.getProcessor())
# white_to_src_factor = 1.0 / float(white_median_value)
normalized_white = white_image.getProcessor().convertToFloat()
normalized_white.multiply(1.0 / float(white_median_value))
imp1 = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif")
print(imp1)
imp2 = IJ.openImage("http://imagej.nih.gov/ij/images/bridge.gif")
print(imp2)
ic = ImageCalculator()
imp3 = ic.run("sub create float", imp1, imp2)
imp3.show()
# imp2mat = ImagePlusMatConverter()
# white_mat = imp2mat.toMat(white_image.getProcessor())
# white_mat = imread(white_image_file_path)
@ -235,7 +259,7 @@ def process_sequence(sequence):
src_image_file_path = sequence.get_image_file_path(channel_index=0, frame_index=0, z_index=0)
src_image = IJ.openImage(src_image_file_path)
# src_image = IJ.openImage(src_image_file_path)
find_depth_index(src_image, white_seq)
find_depth_index(src_image.getProcessor(), white_seq)
def run_script():
@ -261,5 +285,5 @@ def run_script():
# If a Jython script is run, the variable __name__ contains the string '__main__'.
# If a script is loaded as module, __name__ has a different value.
if __name__ in ['__builtin__', '__main__']:
# run_script()
test_get_image_median_value()
run_script()
# test_get_image_median_value()