public static StainVector makeOrthogonalStainVector(String name, StainVector s1, StainVector s2, boolean isResidual) { return new StainVector(name, cross3(s1.getArray(), s2.getArray()), isResidual); }
public static float[] colorDeconvolveRGBArray(int[] buf, double[] stain1, double[] stain2, double[] stain3, int channel, float[] output) { if (output == null || output.length != buf.length) output = new float[buf.length]; if (stain3 == null) stain3 = StainVector.cross3(stain1, stain2); double[][] stainMat = new double[][]{stain1, stain2, stain3}; ColorDeconvMatrix3x3 mat3x3 = new ColorDeconvMatrix3x3(stainMat); double[][] matInv = mat3x3.inverse(); double[] stain1Inv = matInv[0]; double[] stain2Inv = matInv[1]; double[] stain3Inv = matInv[2]; // Apply color deconvolution double[] od_lut = ColorDeconvolutionHelper.makeODLUT(255, 256); for (int i = 0; i < buf.length; i++) { int c = buf[i]; // Extract RGB values & convert to optical densities using a lookup table double r = od_lut[(c & 0xff0000) >> 16]; double g = od_lut[(c & 0xff00) >> 8]; double b = od_lut[c & 0xff]; // Apply deconvolution & store the results output[i] = (float)(r * stain1Inv[channel] + g * stain2Inv[channel] + b * stain3Inv[channel]); } return output; }