/
BMIT_convert_HIS_to_TIFF_sequences.ijm
104 lines (84 loc) · 3.37 KB
/
BMIT_convert_HIS_to_TIFF_sequences.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//This macro converts CT scans saved in HIS format to sequences of TIFF files (sorted into numbered folders, each of which contains flat, dark, and tomo subdirectories.
//This macro assumes that the HIS files have been produced form BMIT's on-the-fly image program.
//Author: Toby Bond (2018)
//
//Helper functions
//
// return a string with the input integer padded to three digits
function pad3(num) {
lead = "";
if (num < 100) {
lead = "0";
}
if (num < 10) {
lead = "00";
}
text = lead+num;
return text;
}
//return the number of filenames contained in the array "Files" which end with the string "SubString"
function numFilesEndingWith(Files, SubString) {
numMatches = 0;
for (i=0; i<lengthOf(Files); i++) {
if(endsWith(Files[i], SubString)) {
numMatches++;
}
}
return numMatches;
}
//return the number of filenames contained in the array "Files" which begin with the string "SubString"
function numFilesStartingWith(Files, SubString) {
numMatches = 0;
for (i=0; i<lengthOf(Files); i++) {
if(startsWith(Files[i], SubString)) {
numMatches++;
}
}
return numMatches;
}
//
//Main body of macro
//
//Prompt user for directory containing series of HIS files
RootDir = getDirectory("Choose directory containing HIS files ");
FileList = getFileList(RootDir);
setOption("display labels", true);
FileCount=lengthOf(FileList);
numDatasets = numFilesStartingWith(FileList, "Image");
//Create directory structure
for (i=0; i<numDatasets; i++) {
File.makeDirectory(RootDir+pad3(i));
File.makeDirectory(RootDir+pad3(i)+"\\dark");
File.makeDirectory(RootDir+pad3(i)+"\\flat");
File.makeDirectory(RootDir+pad3(i)+"\\tomo");
}
//Cycle through all numbered scans and convert HIS files into TIFF sequences (populating each numbered scan's dark, flat, and tomo directories).
for (i=0; i<numDatasets; i++) {
//Convert darks to sequence(s) (any file starting with "Dark" and ending in ".his")
for (j=0; j<FileCount; j++) {
if (startsWith(FileList[j], "Dark") && endsWith(FileList[j], i+".his")) {
run("Bio-Formats Importer", "open=["+RootDir+FileList[j]+"] autoscale color_mode=Default concatenate_series rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_list=1-100000");
run("Image Sequence... ", "format=TIFF name="+substring(FileList[j], 0, 11)+" save=["+RootDir+pad3(i)+"\\dark]");
close();
}
}
//Convert flats to sequence(s) (any file starting with "Flat" and ending in ".his")
for (j=0; j<FileCount; j++) {
if (startsWith(FileList[j], "Flat") && endsWith(FileList[j], i+".his")) {
run("Bio-Formats Importer", "open=["+RootDir+FileList[j]+"] autoscale color_mode=Default concatenate_series rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_list=1-100000");
run("Image Sequence... ", "format=TIFF name="+substring(FileList[j], 0, 11)+" save=["+RootDir+pad3(i)+"\\flat]");
close();
}
}
//Convert projections to sequence (any file starting with "Image" and ending in ".his")
for (j=0; j<FileCount; j++) {
if (startsWith(FileList[j], "Image") && endsWith(FileList[j], i+".his")) {
run("Bio-Formats Importer", "open=["+RootDir+FileList[j]+"] autoscale color_mode=Default concatenate_series rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_list=1-100000");
run("Image Sequence... ", "format=TIFF name="+substring(FileList[j], 0, 6)+" save=["+RootDir+pad3(i)+"\\tomo]");
close();
}
}
}
//
//End of macro
//