package pl.wroc.pwr.image.converter; import pl.wroc.pwr.IOperator; import pl.wroc.pwr.image.ILabImage; import pl.wroc.pwr.image.IXYZImage; import pl.wroc.pwr.image.model.LabImage; public class XYZtoLabConverter implements IOperator< ILabImage > { /** * */ private static final long serialVersionUID = -7429159306670738265L; private IXYZImage inputImage; private ILabImage outputImage; public XYZtoLabConverter( IXYZImage image ) { this.inputImage = image; } public void setImage( IXYZImage image ) { this.inputImage = image; } public ILabImage getResult( ) { return this.outputImage; } public ILabImage apply( ) { this.outputImage = new LabImage( this.inputImage.getSize( ) ); for ( int i = 0; i < this.inputImage.getXChannel( ).getMaxIndex( ); i++ ) { float X = this.inputImage.getXChannel( ).getValue( i ); float Y = this.inputImage.getYChannel( ).getValue( i ); float Z = this.inputImage.getZChannel( ).getValue( i ); /* Hunter-Lab double L = 10 * Math.sqrt( Y ); double a = 17.5 * ( ( ( 1.02 * X ) - Y ) / Math.sqrt( Y ) ); double b = 7 * ( ( Y - ( 0.847 * Z ) ) / Math.sqrt( Y ) );*/ float ref_X = 95.047f; float ref_Y = 100.000f; float ref_Z = 108.883f; float var_X = X / ref_X; //ref_X = 95.047 Observer= 2°, Illuminant= D65 float var_Y = Y / ref_Y; //ref_Y = 100.000 float var_Z = Z / ref_Z; //ref_Z = 108.883 if ( var_X > 0.008856f ) { var_X = (float)Math.pow( var_X, ( 1.0f / 3.0f ) ); } else { var_X = ( 7.787f * var_X ) + ( 16.0f / 116.0f ); } if ( var_Y > 0.008856f ) { var_Y = (float)Math.pow( var_Y, ( 1.0f / 3.0f ) ); } else { var_Y = ( 7.787f * var_Y ) + ( 16.0f / 116.0f ); } if ( var_Z > 0.008856f ) { var_Z = (float)Math.pow( var_Z, ( 1.0f / 3.0f ) ); } else { var_Z = ( 7.787f * var_Z ) + ( 16.0f / 116.0f ); } float L = ( 116.0f * var_Y ) - 16.0f; float a = 500.0f * ( var_X - var_Y ); float b = 200.0f * ( var_Y - var_Z ); this.outputImage.getLChannel( ).setValue( i, L ); this.outputImage.getaChannel( ).setValue( i, a ); this.outputImage.getbChannel( ).setValue( i, b ); } return this.getResult( ); } }