CircularityDescriptor.java

Go to the documentation of this file.
00001 package theba.descriptors;
00002 
00003 import theba.core.RegionDescriptor;
00004 import theba.core.RegionMask;
00005 
00006 public class CircularityDescriptor implements RegionDescriptor {
00007 
00008         public Object measure(RegionMask vmask) {
00009                 short[] mask = new short[vmask.getWidth() * vmask.getHeight()];
00010                 for (int x = 0; x < vmask.getWidth(); x++)
00011                         for (int y = 0; y < vmask.getHeight(); y++)
00012                                 if (vmask.isSet(x, y, 0))
00013                                         mask[x + y * vmask.getWidth()] = 1;
00014                 return measure(mask, vmask.getWidth(), vmask.getHeight());
00015         }
00016 
00017         public double measure(short[] mask, int w, int h) {
00018                 int count = 0;
00019                 int area = 0;
00020                 for (int x = 0; x < w; x++) {
00021                         for (int y = 0; y < h; y++) {
00022                                 int index = x + y * w;
00023                                 if (mask[index] != 0) {
00024                                         area++;
00025                                         if (x < w - 1 && mask[index + 1] == 0) {
00026                                                 count++;
00027                                         } else if (x > 1 && mask[index - 1] == 0) {
00028                                                 count++;
00029                                         } else if (y < h - 1 && mask[index + w] == 0) {
00030                                                 count++;
00031                                         } else if (y > 0 && mask[index - w] == 0) {
00032                                                 count++;
00033                                         }
00034                                 }
00035                         }
00036                 }
00037                 if (area <= 0) {
00038                         System.err.println("zero area: " + count + " " + area);
00039                         return 0;
00040                 }
00041                 // double ret = (4 * Math.PI * area / ((double) count * count));
00042                 double ret = (count * count) / (4 * Math.PI * area);
00043                 return ret;
00044         }
00045 
00046         public String getName() {
00047                 return "Circularity";
00048         }
00049 
00050         public String getAbout() {
00051                 return null;
00052         }
00053 
00054         public boolean does3D() {
00055                 return false;
00056         }
00057 
00058         public boolean isNumeric() {
00059                 return true;
00060         }
00061 }

Generated on Fri Nov 13 08:57:07 2009 for Theba by  doxygen 1.6.1