Skip to content
Snippets Groups Projects
Commit 5ff1b3ed authored by Hugo CHAUVET's avatar Hugo CHAUVET :bicyclist:
Browse files

Allow single image processing

parent 589f99ab
No related branches found
No related tags found
No related merge requests found
......@@ -149,7 +149,9 @@ def load_image_tiles_stack(images_dir):
# Test if the format is only PosXXX
directoryPos = os.path.join(os.path.abspath(d), 'Pos*')
filesPos = glob.glob(directoryPos)
regex_cpt_roi = None
# Test if the format is from MDAQ with only Default folrder in (when multipos is untick)
directoryDefault = os.path.join(os.path.abspath(d), 'Default')
if len(filesSE) > 0:
format = 'SE'
......@@ -172,6 +174,12 @@ def load_image_tiles_stack(images_dir):
regex_cpt_roi = None
name_pattern = 'Pos'
if os.path.isdir(directoryDefault):
format = 'DEFAULT'
files = ['Default']
regex_cpt_roi = None
name_pattern = 'Default'
# Save the base directory
base_dir = os.path.abspath(d)
......@@ -217,8 +225,12 @@ def load_image_tiles_stack(images_dir):
if format == 'POS':
IJ.log('Load multi-position format from MACQ')
hstack, good_names = load_mm_images(base_dir, roi=None, tile=False, pos=True, return_filenames=True)
metadata = load_metadata(os.path.join(base_dir, good_names[0].split(os.path.sep)[0], 'metadata.txt'))
if format == 'DEFAULT':
IJ.log('Load single position format from MACQ')
hstack, good_names = load_mm_images(base_dir, roi=None, tile=False, pos=False, return_filenames=True)
metadata = load_metadata(os.path.join(base_dir, good_names[0].split(os.path.sep)[0], 'metadata.txt'))
hstack.setTitle("Data")
return hstack, metadata, base_dir, selected_roi, good_names
......@@ -287,6 +299,7 @@ def process_white(implus_white, implus_darkofwhite, zofwhite, roi=None):
xmax = xmin + xmax
ymax = ymin + ymax
else:
print('No crop of white')
xmin = ymin = 0
xmax = implus_white.width
ymax = implus_white.height
......@@ -309,6 +322,7 @@ def process_white(implus_white, implus_darkofwhite, zofwhite, roi=None):
xmax = xmin + xmax
ymax = ymin + ymax
else:
print('No crop of dark of white')
xmin = ymin = 0
xmax = implus_darkofwhite.width
ymax = implus_darkofwhite.height
......@@ -400,10 +414,12 @@ def process_tiles(implus_tiles_stack, channel, z, implus_white_corr, implus_dark
mmversion = getMMversion(metadata)
roi = getRoi(metadata, mmversion)
if roi is not None and len(roi) == 4 and implus_dark_stack.width > roi[2] and implus_dark_stack.height > roi[3]:
print('I crop the dark')
xmin, ymin, xmax, ymax = roi
xmax = xmin + xmax
ymax = ymin + ymax
else:
print('No crop of the dark')
xmin = ymin = 0
xmax = implus_dark_stack.width
ymax = implus_dark_stack.height
......@@ -434,17 +450,15 @@ def process_tiles(implus_tiles_stack, channel, z, implus_white_corr, implus_dark
if data.numDimensions() == 5:
inter = Intervals.createMinMax(0, 0, channel, z-1, 0,
xLen-1, yLen-1, channel, z-1, Ntiles-1)
# Data are x,y,channel, (t or z)
# Data are x,y,channel,t
if data.numDimensions() == 4:
if Ntiles > 1:
# x, y, channel, t
inter = Intervals.createMinMax(0, 0, channel, 0,
xLen-1, yLen-1, channel, Ntiles-1)
else:
# x, y, channel, z
inter = Intervals.createMinMax(0, 0, channel, z-1,
xLen-1, yLen-1, channel, z-1)
# Date are x,y,channel
if data.numDimensions() == 3:
inter = Intervals.createMinMax(0, 0, channel,
xLen-1, yLen-1, channel)
if inter is not None:
data = ops.transform().crop(data, inter)
......@@ -519,6 +533,7 @@ def run_processing(channel, zimg, zwhite, run_basic=True, optimizeXY=True, savep
IJ.run("Image Sequence... ", "format=TIFF name=tile_ start=1 save=["+procfolder+"]")
# Save the tile position file for the stitching
if tilesposfile is not None:
with open(procfolder+'/TileConfiguration.txt', 'w') as f:
f.write(tilesposfile)
......@@ -600,6 +615,9 @@ def run_gui(default_values=None):
if default_values is None:
default_values = {}
default_values['optimXY'] = False
if tilesposfile is None:
default_values['Basic'] = False
else:
default_values['Basic'] = True
default_values['dir'] = rootdir+'/IJ_roi%s_telemosMosaic' % (selectedroi)
default_values['zimg'] = 0
......@@ -896,7 +914,10 @@ if __name__ in ['__builtin__','__main__']:
# Make a list of tiles names
tilesondisk = set(os.path.dirname(t) for t in file_names)
if len(tilesondisk) > 1:
tilesposfile = extract_tile_positions(metadata, selectedroi, tilesondisk)
else:
tilesposfile = None
if fdark is not None:
darks = load_images(fdark, roi=roi)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment