Exemplo n.º 1
0
def whiteninggray(images,dc=True):
    """
    This function automatically whites gray images (Image only, data range 0-255, precalculated filter).
    Images is a 3d-ndarray with dtype=float32, with dimension ordering:
        Number_Of_Data, YSize, XSize
    Return 3d-ndarray with dtype=float32, with dimension ordering:
        Number_Of_Data, YSize-6, XSize-6
    """
    global _WHITE_COE
    _l.ASSERTTYPE(images)
    if len(images.shape)!=3: raise Exception, "3d-ndarray needed."

    #Remove DC Coefficient
    if dc:
        if images.shape[0]==1:
            tmp=images
        else:
            tmp=_l.empty(images.shape)
            _l.removeDC(images.reshape(images.shape[0],images.shape[1]*images.shape[2]),tmp.reshape(images.shape[0],images.shape[1]*images.shape[2]))
    else:
        tmp=images

    #Convolution to get result
    out=_l.empty((images.shape[0],1,images.shape[1]-6,images.shape[2]-6))
    _l.convolution4D(tmp.reshape(images.shape[0],images.shape[1],images.shape[2],1),_WHITE_COE,out)
    return out.reshape(images.shape[0],images.shape[1]-6,images.shape[2]-6)
Exemplo n.º 2
0
def whiteningcielab(image):
    """
    This function does whitening on a CIEL*A*B* colorspace color image.
    It uses predefined filter to do convolution on image.
    
    Image is a 3d-ndarray with dtype=float32, with dimension ordering:
        YSize, XSize, [L,A,B]
    Returns 3d-ndarray with dtype=float32, with dimension ordering:
        YSize-2, XSize-2, [w_L,w_A,w_B]
    """
    global _WHITE_CIELAB_COE
    _l.ASSERTTYPE(image)
    out=_l.empty((1,3,image.shape[0]-2,image.shape[1]-2))
    ireshape=image.reshape((1,image.shape[0],image.shape[1],image.shape[2]))
    _l.convolution4D(ireshape,_WHITE_CIELAB_COE,out)
    return numpy.array(out.reshape((3,image.shape[0]-2,image.shape[1]-2)).transpose((1,2,0)),'f')