package ac.essex.ooechs.facedetection.util.evaluation;

import ac.essex.ooechs.imaging.commons.ColourChannels;
import ac.essex.ooechs.imaging.commons.PixelLoader;
import ac.essex.ooechs.imaging.commons.segmentation.Segmenter;
import ac.essex.gp.multiclass.BetterDRS;
import ac.essex.gp.multiclass.PCM;

/**
 * <p/>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 * @author Olly Oechsle, University of Essex, Date: 03-Jul-2008
 * @version 1.0
 */
public class SkinSegmenter extends Segmenter {

    PCM pcm1 = new BetterDRS(-417.47030971943695, 285.5315071340451, new int[]{1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});

    PCM pcm0 = new BetterDRS(0.0,913.9642857142858,new int[]{2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,-1,1,-1,-1,-1,1});;
    public int segment(PixelLoader image, int x, int y) {
        return pcm0.getClassFromOutput(image.getChromaticRed(x, y) != 0 ? image.getHue(x, y) / image.getChromaticRed(x, y) : 0) - 1;
    }

    public int segment2(PixelLoader image, int x, int y) {
        double node6 = image.getPerimeter2().getStatistics(image, x, y).getMin() - image.getSatMean();
        double node12 = 0.9435875380497998 > 0 ? image.getHLine1().getMean(image, x, y) : 0;
        double node11 = node12 > 0 ? 0.7834122062738319 : 8.0;
        double node19 = image.getVLine2().getMean(image, x, y) + image.getPerimeter1().getStatistics(image, x, y).getMin();
        double node18 = 2.0364862755708977 != 0 ? node19 / 2.0364862755708977 : 0;
        double node25 = image.get3x3Stats(x, y, ColourChannels.BLUE).getStandardDeviation() != 0 ? image.get3x3Stats(x, y, ColourChannels.RED).getMean() / image.get3x3Stats(x, y, ColourChannels.BLUE).getStandardDeviation() : 0;
        double node23 = 0 > 0 ? node25 : image.getChromaticBlue(x, y);
        double node10 = node11 > 0 ? node18 : node23;
        double node32 = image.getLightnessMean() > 0 ? 0.9350722686745141 : 2.0;
        double node29 = image.getChromaticBlue(x, y) > 0 ? 0 : node32;
        double node39 = image.getPerimeter2().getStatistics(image, x, y).getStandardDeviation() > 0 ? image.getVLine2().getEdgeCount(image, x, y) : 0.422372971372333;
        double node36 = image.getVLine2().getStatistics(image, x, y).getStandardDeviation() > 0 ? image.getHLine1().getStatistics(image, x, y).getStandardDeviation() : node39;
        double node9 = node10 > 0 ? node29 : node36;
        double node4 = image.get3x3Mean(x, y) > 0 ? node6 : node9;
        double node43 = 0 - image.get3x3Stats(x, y, ColourChannels.RED).getMean();
        double node3 = node4 > 0 ? node43 : 0.19612546637002248;
        double node1 = node3 != 0 ? image.getHueMean() / node3 : 0;
        double node47 = image.getSaturation(x, y) > 0 ? image.getHue(x, y) : image.getHLine1().getEdgeCount(image, x, y);
        return pcm1.getClassFromOutput(node1 - node47) - 1;
    }

}
