-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSegmentJ_script.ijm
More file actions
94 lines (79 loc) · 3.88 KB
/
SegmentJ_script.ijm
File metadata and controls
94 lines (79 loc) · 3.88 KB
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
// Select source directory and destination directories.
dir_source = getDirectory("Choose Data Directory");
dir_scans = dir_source + "Scans (original)/";
dir_subscans = dir_source + "Scans (sub)/";
dir_imseq = dir_source + "Image Sequences/";
dir_msdata = dir_source + "Data (microstructure)/";
dir_graindata = dir_source + "Data (grain)/";
dir_stl = dir_source + "STL Files/";
// Get user inputs for date and volume percentage
edgeLength = getNumber("Enter Subsample Edge Length (px):",150);
// Get list of files in selected source directory and set
// batch mode to "true".
list = getFileList(dir_scans);
setBatchMode(true);
// Set up batch iteration loop.
for (i=0; i<list.length; i++) {
// Display current progress with files.
showProgress(i+1, list.length);
// Open file(i) and get some file metadata.
print("Scan Name: " + list[i]);
print("Scan Number: " + i+1 + "/" + list.length + "\n");
open(dir_scans + list[i]);
scanName = substring(getTitle,0,getTitle.length-4);
// Set file pixel dimensions to ensure all scans in batch have the same pixel calibration resolution
run("Properties...", "unit=pixel pixel_width=1 pixel_height=1 voxel_depth=1");
// Get scan size dimension & number of X,Y,Z locations.
getDimensions(width, height, channels, slices, nFrames);
nX = floor(width/edgeLength); nY = floor(height/edgeLength); nZ = floor(slices/edgeLength);
// Loop through all X, Y, and Z locations. Create counter.
count = 1;
for (z = 1; z<=nZ; z++) {
zCoords = newArray((z-1)*edgeLength + 1,z*edgeLength);
for (y = 1; y<=nY; y++) {
yCoord = (y-1)*edgeLength;
for (x = 1; x<=nX; x++) {
xCoord = (x-1)*edgeLength;
// Select subsection and append count;
selectWindow(scanName + ".tif");
run("Specify...","width=" + edgeLength + " height=" + edgeLength + " x=" + xCoord +
" y=" + yCoord + " slice=1");
subscanName = scanName + "_" + IJ.pad(count, 3);
run("Duplicate...", "title=" + subscanName + " duplicate range=" + zCoords[0] + "-" + zCoords[1]);
saveAs("Tiff", dir_subscans + subscanName);
count++;
// Export image sequence.
File.makeDirectory(dir_imseq + subscanName + "/");
run("Image Sequence... ", "select=[" + dir_subscans + subscanName + "] dir=[" + dir_imseq +
subscanName + "/] format=TIFF name=" + subscanName + "_" + " digits=4");
// Perform watershed.
run("Distance Transform Watershed 3D", "distances=[Borgefors (3,4,5)] output=[16 bits] " +
"normalize dynamic=2 connectivity=6");
run("Set Label Map", "colormap=[Golden angle] background=black shuffle");
// Analyze grain regions.
run("Analyze Regions 3D", "voxel_count volume surface_area mean_breadth sphericity " +
"euler_number bounding_box centroid equivalent_ellipsoid ellipsoid_elongations " +
"max._inscribed surface_area_method=[Crofton (13 dirs.)] euler_connectivity=6");
saveAs("Results", dir_graindata + subscanName + "_grainscan" + ".csv");
selectWindow(subscanName + "_grainscan" + ".csv"); run("Close");
// Get morphological microstructure data.
run("Microstructure 3D", "volume surface mean_breadth euler surface_0=[Crofton (13 dirs.)] " +
"mean=[Crofton (13 dirs.)] mean_0=4 euler_0=6");
saveAs("Results", dir_msdata + subscanName + "_msdata" + ".csv");
selectWindow(subscanName + "_msdata" + ".csv"); run("Close");
// Export .STL mesh file.
selectWindow(subscanName + ".tif");
run("3D Viewer");
call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
call("ij3d.ImageJ3DViewer.add", subscanName + ".tif", "White", subscanName +
".tif", "75", "true", "true", "true", "3", "2");
call("ij3d.ImageJ3DViewer.select", subscanName + ".tif");
call("ij3d.ImageJ3DViewer.exportContent", "STL ASCII", dir_stl + subscanName + ".stl");
call("ij3d.ImageJ3DViewer.close");
// Close subsection windows
selectWindow(scanName + ".tif");
close("\\Others");
}
}
}
}