added the computation of the measure of correlation between a fluo image and a white, with the goal of finding the white image amongst the different depths that match the best a given fluo image
This commit is contained in:
parent
cf68f8900c
commit
874755ad2f
203
lipase.py
203
lipase.py
|
@ -176,104 +176,141 @@ class ImageCatalog(object):
|
|||
# self.sequences[ micro_manager_metadata_file_path ] = Sequence(self, micro_manager_metadata_file_path)
|
||||
|
||||
|
||||
def get_image_median_value(src_image):
|
||||
'''
|
||||
: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
|
||||
class IImageProcessingDebugger(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def on_image(self, image, image_id):
|
||||
'''
|
||||
:param ImagePlus image:
|
||||
:param str image_id:
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
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.getProcessor())
|
||||
print('median value : %d' % median_value)
|
||||
class NullDebugger(IImageProcessingDebugger):
|
||||
|
||||
# double median( cv::Mat channel )
|
||||
# {
|
||||
# double m = (channel.rows*channel.cols) / 2;
|
||||
# int bin = 0;
|
||||
# double med = -1.0;
|
||||
def __init__(self):
|
||||
IImageProcessingDebugger.__init__(self)
|
||||
|
||||
# int histSize = 256;
|
||||
# float range[] = { 0, 256 };
|
||||
# const float* histRange = { range };
|
||||
# bool uniform = true;
|
||||
# bool accumulate = false;
|
||||
# cv::Mat hist;
|
||||
# cv::calcHist( &channel, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate );
|
||||
|
||||
# for ( int i = 0; i < histSize && med < 0.0; ++i )
|
||||
# {
|
||||
# bin += cvRound( hist.at< float >( i ) );
|
||||
# if ( bin > m && med < 0.0 )
|
||||
# med = i;
|
||||
# }
|
||||
|
||||
# return med;
|
||||
# }
|
||||
def on_image(self, image, image_id):
|
||||
pass
|
||||
|
||||
|
||||
def find_depth_index(src_image, white_sequence):
|
||||
''' finds in the image sequence white_sequence the image that correlates the best to src_image
|
||||
class ImageLogger(IImageProcessingDebugger):
|
||||
|
||||
: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))
|
||||
def __init__(self):
|
||||
IImageProcessingDebugger.__init__(self)
|
||||
|
||||
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)
|
||||
print(white_image)
|
||||
|
||||
break
|
||||
def on_image(self, image, image_id):
|
||||
image.show()
|
||||
|
||||
|
||||
def process_sequence(sequence):
|
||||
'''
|
||||
:param Sequence sequence:
|
||||
'''
|
||||
white_seq = sequence.get_white()
|
||||
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.getProcessor(), white_seq)
|
||||
class Lipase(object):
|
||||
|
||||
def __init__(self, debugger=NullDebugger()):
|
||||
'''
|
||||
:param IImageProcessingDebugger im_proc_debugger:
|
||||
'''
|
||||
self.debugger = debugger
|
||||
raw_images_root = '/Users/graffy/ownCloud/ipr/lipase/raw-images'
|
||||
self.catalog = ImageCatalog(raw_images_root)
|
||||
print(self.catalog)
|
||||
# catalog.sequences['GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0'].open_in_imagej()
|
||||
# catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2'].open_in_imagej()
|
||||
# catalog.sequences['DARK_40X_60min_1 im pae min_1/Pos0'].open_in_imagej()
|
||||
# catalog.sequences['white_24112018_1/Pos0'].open_in_imagej()
|
||||
|
||||
def get_image_median_value(self, src_image):
|
||||
'''
|
||||
:param ImagePlus src_image:
|
||||
'''
|
||||
# https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html
|
||||
stats = ImageStatistics.getStatistics(src_image.getProcessor(), ImageStatistics.MEDIAN, None)
|
||||
# print(stats)
|
||||
# print(stats.pixelCount)
|
||||
return stats.median
|
||||
|
||||
def get_image_mean_value(self, src_image):
|
||||
'''
|
||||
:param ImagePlus src_image:
|
||||
'''
|
||||
# https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html
|
||||
stats = ImageStatistics.getStatistics(src_image.getProcessor(), ImageStatistics.MEAN, None)
|
||||
# print(stats)
|
||||
# print(stats.pixelCount)
|
||||
return stats.mean
|
||||
|
||||
|
||||
def test_get_image_median_value(self):
|
||||
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 = self.get_image_median_value(image)
|
||||
print('median value : %d' % median_value)
|
||||
|
||||
def find_depth_index(self, src_image, white_sequence):
|
||||
''' finds in the image sequence white_sequence the image that correlates the best to src_image
|
||||
|
||||
:param ImagePlus src_image:
|
||||
:param Sequence white_sequence:
|
||||
'''
|
||||
# self.debugger.on_image(src_image, 'src_image')
|
||||
|
||||
white_sequence.open_in_imagej()
|
||||
|
||||
|
||||
print('image type : ', src_image.getType())
|
||||
src_median_value = self.get_image_median_value(src_image)
|
||||
normalized_src = src_image.getProcessor().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)
|
||||
# self.debugger.on_image(white_image, 'white_image')
|
||||
white_median_value = self.get_image_median_value(white_image)
|
||||
# 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 = ImagePlus() # IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif")
|
||||
imp1.setProcessor(normalized_src)
|
||||
# print(imp1)
|
||||
imp2 = ImagePlus() # IJ.openImage("http://imagej.nih.gov/ij/images/bridge.gif")
|
||||
imp2.setProcessor(normalized_white)
|
||||
# print(imp2)
|
||||
ic = ImageCalculator()
|
||||
imp3 = ic.run("sub create float", imp1, imp2)
|
||||
# self.debugger.on_image(imp3, 'diff')
|
||||
|
||||
# imp2mat = ImagePlusMatConverter()
|
||||
# white_mat = imp2mat.toMat(white_image.getProcessor())
|
||||
# white_mat = imread(white_image_file_path)
|
||||
# print(white_image)
|
||||
sqdiff_image = ic.run("mul create float", imp3, imp3)
|
||||
mean_sqdiff = self.get_image_mean_value(sqdiff_image)
|
||||
print('difference : ', mean_sqdiff)
|
||||
|
||||
def process_sequence(self, sequence_id):
|
||||
'''
|
||||
:param str sequence_id:
|
||||
'''
|
||||
sequence = self.catalog.sequences[sequence_id]
|
||||
sequence.open_in_imagej()
|
||||
white_seq = sequence.get_white()
|
||||
channel_index = sequence.get_channel_index('DM300_327-353_fluo')
|
||||
src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=0, z_index=0)
|
||||
src_image = IJ.openImage(src_image_file_path)
|
||||
# src_image = IJ.openImage(src_image_file_path)
|
||||
self.find_depth_index(src_image, white_seq)
|
||||
|
||||
|
||||
def run_script():
|
||||
raw_images_root = '/Users/graffy/ownCloud/ipr/lipase/raw-images'
|
||||
catalog = ImageCatalog(raw_images_root)
|
||||
print(catalog)
|
||||
# catalog.sequences['GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0'].open_in_imagej()
|
||||
# catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2'].open_in_imagej()
|
||||
# catalog.sequences['DARK_40X_60min_1 im pae min_1/Pos0'].open_in_imagej()
|
||||
# catalog.sequences['white_24112018_1/Pos0'].open_in_imagej()
|
||||
process_sequence(catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2'])
|
||||
lipase = Lipase(debugger=ImageLogger())
|
||||
lipase.process_sequence('res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2')
|
||||
|
||||
if False:
|
||||
sequence = catalog.sequences['GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0']
|
||||
sequence = lipase.catalog.sequences['GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0']
|
||||
src_image_file_path = sequence.get_image_file_path(channel_index=sequence.get_channel_index('DM300_327-353_fluo'), frame_index=3)
|
||||
src_image = IJ.openImage(src_image_file_path) # pylint: disable=unused-variable
|
||||
|
||||
|
|
Loading…
Reference in New Issue