-
Notifications
You must be signed in to change notification settings - Fork 0
/
CropCells.ijm
103 lines (80 loc) · 2.83 KB
/
CropCells.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
// ==========================================================================
// Matheus Viana - [email protected] - 01.19.2018
// ==========================================================================
//
// This macro is used to create single cells z-stacks similar to the one available
// in the example dataset.
//
// BEFORE USING THIS MACRO:
// ------------------------
// 1. Use the macro GenFramesMaxProjs.ijm to generate the z-stack MaxProjs.tiff
// 2. Use the z-stack MaxProjs.tiff to drawn ROIs around the cells that you want
// to crop
// 3. Save the ROIs as RoiSet.zip
//
// USING THIS MACRO:
// ------------------------
// 1. Click run to execute the macro
// 2. Select the size of the single cell images you want to create. The default
// value should be fine for images of mitochondria of yeast cells. You may want
// to increase this value if your cells are bigger (mammalian cells).
// 3. Select the folder that contains the original z-stacks, the file RoiSet.zip
// and the file MaxProjs.tiff
// 4. A subfolder called "cells" will be create and should be used as input for
// MitoGraph
// ==========================================================================
// Defining the size in pixels of the single cell z-stacks
_xy = getNumber("Single cell image size in pixels", 200);
_RootFolder = getDirectory("Choose a Directory");
// Creating a directory where the files are saved
File.makeDirectory(_RootFolder + "cells");
setBatchMode(true);
run("ROI Manager...");
roiManager("Reset");
roiManager("Open",_RootFolder + "RoiSet.zip");
open("MaxProjs.tif");
MAXP = getImageID;
// For each ROI (cell)
for (roi = 0; roi < roiManager("count"); roi++) {
roiManager("Select",roi);
_FileName = getInfo("slice.label");
_FileName = replace(_FileName,".tif","@");
_FileName = split(_FileName,"@");
_FileName = _FileName[0];
open(_FileName + ".tif");
ORIGINAL = getImageID;
run("Restore Selection");
newImage("CELL","16-bit Black",_xy,_xy,nSlices);
CELL = getImageID;
// Estimating the noise distribution around the ROI
max_ai = 0;
for (s = 1; s <= nSlices; s++) {
selectImage(MAXP);
selectImage(ORIGINAL);
setSlice(s);
run("Restore Selection");
run("Make Band...", "band=5");
getStatistics(area, mean, min, max, std);
run("Restore Selection");
run("Copy");
selectImage(CELL);
setSlice(s);
run("Select None");
run("Add...", "value=" + mean + " slice");
run("Add Specified Noise...", "slice standard=" + 0.5*std);
run("Paste");
getStatistics(area, mean, min, max, std);
if (mean>max_ai) {
max_ai = mean;
slice_max_ai = s;
}
}
run("Select None");
resetMinAndMax();
save(_RootFolder + "cells/" + _FileName + "_" + IJ.pad(roi,3) + ".tif");
selectImage(CELL); close();
selectImage(ORIGINAL); close();
}
selectImage(MAXP); close();
setBatchMode(false);
print("Cell croppping is complete.");