Skip to content

Commit

Permalink
Call BigStitcher via command line
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Jan 2, 2024
1 parent 572bd19 commit 65916f9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
44 changes: 42 additions & 2 deletions mesospim_stitcher/big_stitcher_bridge.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
def run_big_stitcher():
return
import subprocess
from pathlib import Path

XML_PATH = (
"D:/TiledDataset/2.5x_tile/"
"2.5x_tile_igor_rightonly_Mag2.5x_ch488_ch561_ch647_bdv3.xml"
)
TILE_CONFIG_PATH = (
"D:/TiledDataset/"
"2.5x_tile/"
"2.5x_tile_igor_rightonly_Mag2.5x"
"_ch488_ch561_ch647_bdv_tile_config.txt"
)


def run_big_stitcher(
imageJ_path: Path, xml_path: Path, tile_config_path: Path
):
stitch_macro_path = Path(__file__).resolve().parent / "stitch_macro.ijm"
command = (
f"{imageJ_path} --ij2"
f" --headless -macro {stitch_macro_path} "
f'"{xml_path} {tile_config_path}"'
)

result = subprocess.run(
command, capture_output=True, text=True, check=True
)

return result


if __name__ == "__main__":
result = run_big_stitcher(
Path("C:/Users/Igor/Documents/Fiji.app/ImageJ-win64.exe"),
Path(XML_PATH),
Path(TILE_CONFIG_PATH),
)

with open("big_stitcher_output.txt", "w") as f:
f.write(result.stdout)
f.write(result.stderr)
13 changes: 10 additions & 3 deletions mesospim_stitcher/stitch_macro.ijm
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
args = getArgument()
args = split(args, " ")
xmlPath = args[0]
args = getArgument();
args = split(args, " ");
xmlPath = args[0];
tilePath = args[1]

print("Stitching " + xmlPath);
print("Loading TileConfiguration from " + tilePath)
run("Load TileConfiguration from File...",
"browse=" + xmlPath +
" select=" + xmlPath +
" tileconfiguration=" + tilePath +
" use_pixel_units keep_metadata_rotation");

print("Calculating pairwise shifts");
run("Calculate pairwise shifts ...",
"select=" + xmlPath +
" process_angle=[All angles] process_channel=[All channels] process_illumination=[All illuminations]" +
" process_tile=[All tiles] process_timepoint=[All Timepoints]" +
" method=[Phase Correlation] channels=[Average Channels]" +
" downsample_in_x=4 downsample_in_y=4 downsample_in_z=4");

print("Optimizing globally and applying shifts")
run("Optimize globally and apply shifts ...",
"select=" + xmlPath +
" process_angle=[All angles] process_channel=[All channels] process_illumination=[All illuminations]" +
" process_tile=[All tiles] process_timepoint=[All Timepoints] relative=2.500 absolute=3.500" +
" global_optimization_strategy=[Two-Round using Metadata to align unconnected Tiles and iterative dropping of bad links]" +
" fix_group_0-0,");

print("Done");
eval("script", "System.exit(0);");

0 comments on commit 65916f9

Please sign in to comment.