-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBenchmarkMax.java
63 lines (48 loc) · 1.6 KB
/
BenchmarkMax.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
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;
import ijaux.PixLib;
import ijaux.datatype.Pair;
import ijaux.hypergeom.PixelCube;
import ijaux.hypergeom.index.BaseIndex;
import ijaux.iter.IndexedIterator;
public class BenchmarkMax implements PlugIn {
private PixLib plib=new PixLib();
@Override
public void run(String arg) {
// Opens the M51 galaxy example
String name = "http://rsb.info.nih.gov/ij/images/m51.tif";
ImagePlus imp = IJ.openImage(name);
imp.show();
long time1=System.currentTimeMillis();
// converts the ImagePlus to a PixelCube
PixelCube<Number,BaseIndex> pc=plib.cubeFrom(imp, PixLib.BASE_INDEXING);
int idx=pc.index();
Pair<Number,Integer> max= (Pair<Number, Integer>)Pair.of(pc.element(idx),idx);
//iterates over the image and finds the 1st global maximum
long time2=System.currentTimeMillis();
for (IndexedIterator<?> iter= pc.iterator();iter.hasNext(); iter.next()) {
final Number c=pc.element(idx);
if (c.floatValue()>max.first.floatValue())
max=(Pair<Number, Integer>)Pair.of(c,idx);
idx= iter.index();
}
BaseIndex bi=pc.getIndex();
//calculates the image coordinates
bi.setIndex(max.second);
long time3=System.currentTimeMillis();
System.out.println(max);
int[] coords=bi.getCoordinates();
IJ.makePoint(coords[0], coords[1]);
System.out.println(bi);
System.out.println("initiation time: "+ (time2-time1)+" ms\n loop duration " + (time3-time2) +" ms" );
}
/**
* @param args
*/
public static void main(String[] args) {
new ImageJ();
new BenchmarkMax().run(null);
}
}