package structures; import java.awt.Dimension; import java.util.LinkedList; import utils.labeling; public class labels { int width = 0; int height = 0; int nlabels = 0; int labels[] = null; LinkedList list = null; /*the first slot is empty*/ public int get_nlabels () { return nlabels; } public int[] get_image_label () { return labels; } public LinkedList get_label_list () { return list; } public void clean () { /*cleaning the region of that label in the image*/ for(int i = 0; i < width*height; i++) { if (!list.get(labels[i]).active) { labels[i] = 0; } } /*removing the label*/ for (int i = 0; i < nlabels; i++) { if (!list.get(i).active) { list.remove(i--); nlabels = list.size(); } } } public labels (int regions[], int width, int height) { this.width = width; this.height = height; Dimension d = new Dimension(); d.setSize(width, height); labeling alg = new labeling(); labels = alg.compactLabeling (regions, d, true); nlabels = alg.getMaxLabel() + 1; list = new LinkedList(); for (int i = 0; i < nlabels; i++) { struct_label l = new struct_label(); l.id = i; l.xmin = l.ymin = Integer.MAX_VALUE; l.xmax = l.ymax = Integer.MIN_VALUE; l.barx = l.bary = l.surf = 0; l.active = true; l.weight = 0.0; list.add(l); } for(int i = 0; i < width*height; i++) { int x = i % width; int y = i / width; int l = labels[i]; if (l != 0) { /*black (0) is assumed as background*/ list.get(l).xmin = Math.min (list.get(l).xmin, x); list.get(l).xmax = Math.max (list.get(l).xmax, x); list.get(l).ymin = Math.min (list.get(l).ymin, y); list.get(l).ymax = Math.max (list.get(l).ymax, y); list.get(l).barx += x; list.get(l).bary += y; list.get(l).regions = 1; list.get(l).surf++; } } } }