package pl.wroc.pwr.imagechannel.basic; import pl.wroc.pwr.IOperator; import pl.wroc.pwr.imagechannel.IImageChannel; import pl.wroc.pwr.imagechannel.factory.ImageChannelFactory; public class ThresholdChannel implements IOperator< IImageChannel > { private IImageChannel inputChannel; private float lowerValue; private float upperValue; private IImageChannel threshold; private boolean inPlace; public ThresholdChannel( IImageChannel channel, IImageChannel threshold ) { this(channel, threshold, 0, 1, false); } public ThresholdChannel( IImageChannel channel, IImageChannel threshold, boolean inPlace ) { this(channel, threshold, 0, 1, inPlace); } public ThresholdChannel( IImageChannel channel, IImageChannel threshold, float lowerValue, float upperValue, boolean inPlace ) { this.inputChannel = channel; this.threshold = threshold; this.lowerValue = lowerValue; this.upperValue = upperValue; this.inPlace = inPlace; System.out.println("ThresholdChannel on " + this.inputChannel + " with threshold " + this.threshold + //$NON-NLS-1$ //$NON-NLS-2$ ", lowerValue " + this.lowerValue + ", upperValue " + this.upperValue); //$NON-NLS-1$ //$NON-NLS-2$ } public IImageChannel apply( ) { IImageChannel outputChannel = this.inPlace ? this.inputChannel : new ImageChannelFactory(this.inputChannel).apply(); final int maxIndex = this.inputChannel.getMaxIndex(); for ( int i = 0; i < maxIndex; i++ ) { outputChannel.setValue( i, this.inputChannel.getValue(i) <= this.threshold.getValue(i) ? this.lowerValue : this.upperValue ); } return outputChannel; } }