EccentricityDescriptor.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 EccentricityDescriptor implements RegionDescriptor {
00007         public Object measure(RegionMask vmask) {
00008                 short[] mask = new short[vmask.getWidth() * vmask.getHeight()];
00009                 for (int x = 0; x < vmask.getWidth(); x++)
00010                         for (int y = 0; y < vmask.getHeight(); y++)
00011                                 if (vmask.isSet(x, y, 0))
00012                                         mask[x + y * vmask.getWidth()] = 1;
00013                 return measure(mask, vmask.getWidth(), vmask.getHeight());
00014         }
00015 
00016         public double measure(short[] pixels, int width, int height) {
00017 
00018                 double m_0_0 = 0, m_1_0 = 0, m_0_1 = 0;
00019 
00020                 for (int x = 0; x < width; x++) {
00021                         for (int y = 0; y < height; y++) {
00022                                 int index = x + y * width;
00023                                 if (pixels[index] != 0) {
00024                                         m_0_0 += 1;
00025                                         m_1_0 += x;
00026                                         m_0_1 += y;
00027                                 }
00028                         }
00029                 }
00030 
00031                 double x_c = m_1_0 / m_0_0;
00032                 double y_c = m_0_1 / m_0_0;
00033                 double m_0_2 = 0, m_2_0 = 0, m_1_1 = 0;
00034                 for (int x = 0; x < width; x++) {
00035                         for (int y = 0; y < height; y++) {
00036                                 int index = x + y * width;
00037                                 if (pixels[index] != 0) {
00038                                         m_1_1 += (x - x_c) * (y - y_c);
00039                                         m_2_0 += (x - x_c) * (x - x_c);
00040                                         m_0_2 += (y - y_c) * (y - y_c);
00041                                 }
00042                         }
00043                 }
00044 
00045                 double factor = m_2_0
00046                                 + m_0_2
00047                                 + Math.sqrt((m_2_0 - m_0_2) * (m_2_0 - m_0_2) + 4 * m_1_1
00048                                                 * m_1_1);
00049                 double dividend = m_2_0
00050                                 + m_0_2
00051                                 - Math.sqrt((m_2_0 - m_0_2) * (m_2_0 - m_0_2) + 4 * m_1_1
00052                                                 * m_1_1);
00053 
00054                 return factor / dividend;
00055         }
00056 
00057         public String getName() {
00058                 return "Eccentricity";
00059         }
00060 
00061         public String getAbout() {
00062                 return "Returns the eccentricity of a single 2D region";
00063         }
00064 
00065         public boolean does3D() {
00066                 return false;
00067         }
00068 
00069         public boolean isNumeric() {
00070                 return true;
00071         }
00072 
00073 }

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