forked from JaneliaSciComp/ColorMIP_Mask_Search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlice_Label_Search.java
101 lines (80 loc) · 2.18 KB
/
Slice_Label_Search.java
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
import ij.*;
import ij.io.*;
import ij.plugin.filter.*;
import ij.plugin.PlugIn;
import ij.process.*;
import ij.gui.*;
import java.math.*;
import java.io.*;
import java.util.Arrays;
import java.net.*;
import ij.Macro.*;
import java.awt.*;
//import ij.macro.*;
import ij.gui.GenericDialog.*;
import java.util.*;
import java.lang.*;
public class Slice_Label_Search implements PlugInFilter
{
ImageProcessor ip1;
ImagePlus imp,newimp;
String Label,SearchWord;
public int setup(String arg, ImagePlus imp) {
this.imp = imp;
return DOES_ALL;
}
// private boolean showDialog() {
// return true;
// }
public void run(ImageProcessor ip1){
imp = WindowManager.getCurrentImage();
// String dir=IJ.getDirectory("Choose folder for stacks");
GenericDialog gd = new GenericDialog("Slice Label Search");
gd.addStringField("Search word; ", "", 20);
gd.showDialog();
if(gd.wasCanceled()){
return;
}
SearchWord =gd.getNextString();
ImageStack st1 = imp.getStack();
int width = imp.getWidth();
int height = imp.getHeight();
int slicenumber = imp.getStackSize();
IJ.register (Slice_Label_Search.class);
if (IJ.versionLessThan("1.32c")){
IJ.showMessage("Error", "Please Update ImageJ.");
return;
}
int[] wList = WindowManager.getIDList();
if (wList==null) {
IJ.error("No images are open.");
return;
}
ImageStack dcStack = new ImageStack (width,height);
if (slicenumber > 1) {
for(int SliceScan=1; SliceScan<=slicenumber; SliceScan++){
IJ.showProgress((double)SliceScan / (double)slicenumber);
Label = st1.getSliceLabel(SliceScan);
//IJ.log("Label; "+Label+" SearchWord; "+SearchWord);
int Check= Label != null ? (Label.indexOf(SearchWord)) : -1;
if(Check!=-1){
ip1 = st1.getProcessor(SliceScan); //Mask
dcStack.addSlice(Label, ip1);
}
}
} else {
int Check= imp.getTitle().indexOf(SearchWord);
if(Check!=-1){
ip1 = imp.getProcessor();
dcStack.addSlice(Label, ip1);
}
}
int posislice2=dcStack.size();
if (posislice2 > 0) {
newimp = new ImagePlus(posislice2+" Search_results of "+SearchWord, dcStack);
newimp.show();
} else {
IJ.error("No results found.");
}
}
}