-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeMontageFromImageSequence.ijm
68 lines (55 loc) · 2.17 KB
/
makeMontageFromImageSequence.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//inputFolder = getArgument();
inputFolder = getDirectory("Choose the folder containing images to process:");
outputFolder = getPath(inputFolder); // get the parental folder path
postfix1 = "-montage";
filenameContains1 = "phase-8bit.tif";
// Shared parameters
nCol = 10;
nRow = 2;
scaleFactor = 0.5;
border_width = 10;
//element_width = 1024;
//figure_width = 65;
//border_width = scaleFactor * element_width * 2 / figure_width;
// specify the starting image number to skip some
startingImage = 1;
incrementStep = 1;
setBatchMode(true);
processFolder(inputFolder, outputFolder, filenameContains1, postfix1);
// If processing multiple folders in a parental folder:
//processFolders(inputFolder, outputFolder);
//make Montage
function processFolder(folder, outputFolder, filenameContains, postfix) {
run("Image Sequence...", "open=["+folder+"] starting="+startingImage+" increment="+incrementStep+" file="+filenameContains+" sort");
// run("Make Montage...", "columns="+nCol+" rows="+nRow+" scale="+scaleFactor);
setForegroundColor(255, 255, 255);
run("Make Montage...", "columns="+nCol+" rows="+nRow+" scale="+scaleFactor+" border="+border_width+" use");
folderParts = split(folder,"/");
outTifName = folderParts[folderParts.length - 1] + postfix + ".tif";
outJpegName = folderParts[folderParts.length - 1] + postfix + ".jpeg";
saveAs("Tiff", outputFolder + outTifName);
saveAs("Jpeg", outputFolder + outJpegName);
run("Close All");
}
function processFolders(inputFolder, outputFolder) {
list = getFileList(inputFolder);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFolder(inputFolder+list[i], outputFolder);
}
}
function getPath(pathFileOrFolder) {
// this one takes full path of the file (input can also be a folder) and returns the parent folder path
temp = split(pathFileOrFolder, File.separator);
if ( File.separator == "/" ) {
// Mac and unix system
pathTemp = File.separator;
for (i=0; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
if ( File.separator == "\\" ) {
// Windows system
pathTemp = temp[0] + File.separator;
for (i=1; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
return pathTemp;
}