package pl.wroc.pwr.imagechannel.moment; import pl.wroc.pwr.basic.IDoubleOperator; import pl.wroc.pwr.imagechannel.IImageChannel; public class CentralMoment implements IDoubleOperator { /** * */ private static final long serialVersionUID = -3262209310121202780L; private IImageChannel imageChannel; private int p; private int q; public CentralMoment( IImageChannel imageChannel, int p, int q ) { this.imageChannel = imageChannel; this.p = p; this.q = q; } public float applyDouble( ) { float moment00 = new Moment( this.imageChannel, 0, 0 ).applyDouble( ); float moment10 = new Moment( this.imageChannel, 1, 0 ).applyDouble( ); float moment01 = new Moment( this.imageChannel, 0, 1 ).applyDouble( ); float centroidX = moment10 / moment00; float centroidY = moment01 / moment00; float value = 0; for ( int x = 0; x < this.imageChannel.getXSize( ); x++ ) { for ( int y = 0; y < this.imageChannel.getYSize( ); y++ ) { value += Math.pow( x - centroidX, this.p ) * Math.pow( y - centroidY, this.q ) * this.imageChannel.getValue( x, y ); } } return value; } public Float apply( ) { return new Float( this.applyDouble( ) ); } }