import numpy

def ColorConvolution ( I, W ):
    '''
    Reconstructs a color image from the stain matrix "W" and the stain intensity 
    images generated by ColorDeconvolution.
    *Inputs:
        I (rgbimage) - an RGB image of type unsigned char.
        W (matrix) - a 3x3 matrix containing the color vectors in columns. 
                     For two stain images the third column is zero and will be 
                     complemented using cross-product. Minumum two nonzero 
                     columns required.
    *Outputs:
        RGB (rgbimage) - a reconstructed RGB image with values ranging from 
                         [0, 255], suitable for display.
    *Related functions:
        ComplementStainMatrix, OpticalDensityFwd, OpticalDensityInv, ColorDeconvolution 
    '''

    #transform 3D input stain image to 2D stain matrix format
    m = I.shape[0]
    n = I.shape[1]
    I = numpy.reshape(I, (m*n,3))

    #transform input stains to optical density values and convolve, tfm back to stain
    I = I.astype(dtype=numpy.float32)
    ODfwd = OpticalDensityFwd(I)
    ODdeconv = numpy.dot(ODfwd, numpy.transpose(W))
    ODinv = OpticalDensityInv(ODdeconv)

    #reshape output, transform type
    RGB = numpy.reshape(ODinv, (m,n,3))
    RGB[RGB > 255] = 255
    RGB = RGB.astype(numpy.uint8)
    
    return(RGB)

Create ColorConvolution.py