/** * */ package model.color; import util.Matrix; /** * Converts an RGB Image into other color spaces. * * In particular, convert from RGB to color opponent space * of +R/-G, +B/-Y, BL/WH (non opponent channel) * @author John H. Krantz, Ph.D. * */ public class ColorComputer { private Matrix matrix = new Matrix(); public double [][][] fromRGBtoColorOpponent(double [][][] rgbImage){ double converted [][][] = null; converted = fromConesToColorOpp( fromTriStimToCones( fromRGBtoTriStim(rgbImage))); return converted; } /** * Converts and RGB image to a 1931 CIE tristimulus (XYZ) * set of values * @param double [][][] origImage the RGB image * @return double [][][] the array of Tristimulus values */ public double [][][] fromRGBtoTriStim(double [][][] origImage){ double triStim [][][] = null; triStim = new double[origImage.length][origImage[0].length][3]; for (int x = 0; x < origImage.length; x ++){ for (int y = 0; y < origImage[0].length; y ++){ triStim[x][y] = matrix.mMult(ColorConst.RGB_TRISTIM, origImage[x][y]); } } return triStim; } /** * Converts and image in 1931 CIE tristimulus (XYZ) * set of values to cone activation values * @param double [][][] origImage the trisimulus image * @return double [][][] the array of cones values */ public double [][][] fromTriStimToCones(double [][][] triStim){ double cones [][][] = null; cones = new double[triStim.length][triStim[0].length][3]; for (int x = 0; x < triStim.length; x ++){ for (int y = 0; y < triStim[0].length; y ++){ cones[x][y] = matrix.mMult(ColorConst.TRISTIM_CONES, triStim[x][y]); } } return cones; } /** * Converts and image cone activation values * to color opponent channel activities * @param double [][][] origImage the trisimulus image * @return double [][][] the array of cones values */ public double [][][] fromConesToColorOpp(double [][][] cones){ double colorOpp [][][] = null; colorOpp = new double[cones.length][cones[0].length][3]; for (int x = 0; x < cones.length; x ++){ for (int y = 0; y < cones[0].length; y ++){ colorOpp[x][y] = matrix.mMult(ColorConst.CONES_COLOR_OPP, cones[x][y]); } } return colorOpp; } }