AvgYoungCurvature.java

Go to the documentation of this file.
00001 package theba.descriptors;
00002 
00003 import java.util.ArrayList;
00004 
00005 import theba.core.ImageFunctions;
00006 import theba.core.RegionDescriptor;
00007 import theba.core.RegionMask;
00008 
00009 
00010 public class AvgYoungCurvature implements RegionDescriptor {
00011 
00012         public Object measure(RegionMask vmask) {
00013                 short[] mask = new short[vmask.getWidth() * vmask.getHeight()];
00014                 for (int x = 0; x < vmask.getWidth(); x++)
00015                         for (int y = 0; y < vmask.getHeight(); y++)
00016                                 if (vmask.isSet(x, y, 0))
00017                                         mask[x + y * vmask.getWidth()] = 1;
00018                 return measure(mask, vmask.getWidth(), vmask.getHeight());
00019         }
00020 
00021         public double measure(short[] pixels, int width, int height) {
00022                 
00023                 if (pixels == null){
00024                         System.err.println("Got no pixels!");
00025                         return -1;
00026                 }
00027                 ArrayList points = ImageFunctions.borderTrace(pixels, width, height);
00028                 int[] chaincode = ImageFunctions.getChaincode(points);
00029                 double[] s = ImageFunctions.getArcLenghts(chaincode);
00030 
00031                 double curvatureSum = 0;
00032                 
00033                 assert(s.length > 0);
00034                 
00035                 for (int i = 1; i < s.length; i++) {
00036                         curvatureSum += Math.abs((chaincode[i] - chaincode[i - 1])
00037                                         / (s[i] - s[i - 1]));
00038                 }
00039                 return curvatureSum / (s.length - 1);
00040         }
00041 
00042         public String getName() {
00043                 return "Average Young-curvature";
00044         }
00045 
00046         public String getAbout() {
00047                 return "Returns the average Young-curvature of a 4-connected 2D region";
00048         }
00049 
00050         public boolean does3D() {
00051                 return false;
00052         }
00053 
00054         public boolean isNumeric() {
00055                 return true;
00056         }
00057 
00058 }

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