@@ -0,0 +1,1240 @@
+import numpy%0A%0Adef ComplementStainMatrix( W ):%0A    '''%0A    Used to fill out empty columns of a stain matrix for use with %0A    ColorDeconvolution. Replaces right-most column with normalized cross-product%0A    of first two columns.%0A    *Inputs:%0A        W (matrix) - a 3x3 stain calibration matrix with stain color vectors in columns.%0A    *Outputs:%0A        Out(matrix) - a 3x3 complemented stain calibration matrix with a third %0A                      orthogonal column.%0A    *Related functions:%0A        ColorDeconvolution%0A    '''%0A    %0A    #copy input to output for initialization%0A    Complemented = W%0A%0A    #calculatoe directed cross-product of first two columns%0A    if ((W%5B0,0%5D**2 + W%5B0,1%5D**2) %3E 1):%0A        Complemented%5B0,2%5D = 0%0A    else:%0A        Complemented%5B0,2%5D = (1 - (W%5B0,0%5D**2 + W%5B0,1%5D**2))**0.5%0A%0A    if ((W%5B1,0%5D**2 + W%5B1,1%5D**2) %3E 1):%0A        Complemented%5B1,2%5D = 0%0A    else:%0A        Complemented%5B1,2%5D = (1 - (W%5B1,0%5D**2 + W%5B1,1%5D**2))**0.5%0A    %0A    if ((W%5B2,0%5D**2 + W%5B2,1%5D**2) %3E 1):%0A        Complemented%5B2,2%5D = 0%0A    else:%0A        Complemented%5B2,2%5D = (1 - (W%5B2,0%5D**2 + W%5B2,1%5D**2))**0.5%0A    %0A    #normalize new vector to unit-norm%0A    Complemented%5B:,2%5D = Complemented%5B:,2%5D / numpy.linalg.norm(Complemented%5B:,2%5D)%0A    %0A    return(Complemented)%0A

Create ComplementStainMatrix.py