YoungBendingEnergy.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 YoungBendingEnergy 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                 ArrayList points = ImageFunctions.borderTrace(pixels, width, height);
00023                 int[] chaincode = ImageFunctions.getChaincode(points);
00024                 double[] s = ImageFunctions.getArcLenghts(chaincode);
00025                 if (s == null)
00026                         return -1; // return error, -1 is an impossible value
00027 
00028                 double bendingEnergy = 0;
00029                 for (int i = 1; i < s.length; i++) {
00030                         bendingEnergy += Math.pow((chaincode[i] - chaincode[i - 1])
00031                                         / (s[i] - s[i - 1]), 2);
00032                 }
00033                 return bendingEnergy / (s.length - 1);
00034         }
00035 
00036         public String getName() {
00037                 return "Young Bending Energy";
00038         }
00039 
00040         public String getAbout() {
00041                 return "Returns the average Young-curvature of a 4-connected 2D region";
00042         }
00043 
00044         public boolean does3D() {
00045                 return false;
00046         }
00047 
00048         public boolean isNumeric() {
00049                 return true;
00050         }
00051 
00052 }

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