77import hk .microos .tools .ImageTool ;
88
99public class MyImage {
10- private int id ;
1110 private String path ;
1211 private BufferedImage bi ;
13- public int w , h ;
12+ private int w = - 1 , h = - 1 ;
1413 private ArrayList <Ellipse > elpses = new ArrayList <>();
15- private ArrayList <Ellipse > elpsesStatic = new ArrayList <>() ;
16- public MyImage ( File f , int id ) {
17- this . id = id ;
14+ private ArrayList <Ellipse > elpsesStatic = null ;
15+
16+ public MyImage ( File f ) {
1817 this .path = f .getAbsolutePath ();
19- this .bi = ImageTool .openImage (f );
20- this .w = bi .getWidth ();
21- this .h = bi .getHeight ();
18+ // this.bi = ImageTool.openImage(f);
19+ // this.w = bi.getWidth();
20+ // this.h = bi.getHeight();
21+ }
22+
23+ public int w () {
24+ if (w == -1 )
25+ w = getImage ().getWidth ();
26+ return w ;
27+ }
28+
29+ public int h () {
30+ if (h == -1 )
31+ h = getImage ().getHeight ();
32+
33+ return h ;
2234 }
2335
2436 public void setElpsFromString (String s ) {
2537 // load annotation from string with a specific format
2638 }
2739
2840 public BufferedImage getImage () {
29- return bi ;
41+
42+ return bi == null ? ImageTool .openImage (new File (path )) : bi ;
3043 }
3144
3245 public void addElps (Ellipse e ) {
@@ -36,44 +49,61 @@ public void addElps(Ellipse e) {
3649 public ArrayList <Ellipse > getElpses () {
3750 return elpses ;
3851 }
39- public ArrayList <Ellipse > getEllipseStatic (){
52+
53+ public ArrayList <Ellipse > getEllipseStatic () {
4054 return elpsesStatic ;
4155 }
42- public ArrayList <String > getElpsesStrings (){
56+
57+ public ArrayList <String > getElpsesStrings () {
4358 ArrayList <String > strs = new ArrayList <>();
44- for (Ellipse e : elpses ){
59+ for (Ellipse e : elpses ) {
4560 strs .add (e .toRowFormatString ());
4661 }
4762 return strs ;
4863 }
49- public ArrayList <String > getStaticElpsesStrings (){
64+
65+ public ArrayList <String > getStaticElpsesStrings () {
66+ if (elpsesStatic == null ) {
67+ return null ;
68+ }
5069 ArrayList <String > strs = new ArrayList <>();
51- for (Ellipse e : elpsesStatic ){
70+ for (Ellipse e : elpsesStatic ) {
5271 strs .add (e .toRowFormatString ());
5372 }
5473 return strs ;
5574 }
56- public ArrayList <String > getAllElpsesStrings (){
75+
76+ public ArrayList <String > getAllElpsesStrings () {
5777 ArrayList <String > strs = new ArrayList <>();
58- for (Ellipse e : elpses ){
78+ for (Ellipse e : elpses ) {
5979 strs .add (e .toRowFormatString ());
6080 }
61- for (Ellipse e : elpsesStatic ){
62- strs .add (e .toRowFormatString ());
81+ if (elpsesStatic != null ) {
82+ for (Ellipse e : elpsesStatic ) {
83+ strs .add (e .toRowFormatString ());
84+ }
6385 }
86+
6487 return strs ;
6588 }
66-
89+
90+ public String getPath () {
91+ return this .path ;
92+ }
93+
6794 @ Override
6895 public boolean equals (Object obj ) {
69- MyImage img = (MyImage )obj ;
70- return img .path .equals (this .path ) && img . id == this . id ;
96+ MyImage img = (MyImage ) obj ;
97+ return img .path .equals (this .path );
7198 }
72- public String getMarkNumString (){
73- return String .format ("%d+%d" , elpsesStatic .size (), elpses .size ());
99+
100+ public String getMarkNumString () {
101+ int elpsesStaticSize = (elpsesStatic == null ) ? 0 : elpsesStatic .size ();
102+ return String .format ("%d+%d" , elpsesStaticSize , elpses .size ());
74103 }
75- public void setElpsesStatic (ArrayList <Ellipse > elps ){
104+
105+ public void setElpsesStatic (ArrayList <Ellipse > elps ) {
76106 this .elpsesStatic = elps ;
77107 }
78-
108+
79109}
0 commit comments