示例#1
0
def show_rows_as_images(matfile,
                        imgheight,
                        imgwidth,
                        nrows=10,
                        ncols=10,
                        figtitle=""):
    """Will open a .pmat .dmat .amat or .vmat file and consider the beginning of each row a imgheight x imgwidth imagette.
    These images will be interactively displayed in a nrows x ncols grid of imagettes."""
    data = None
    if figtitle == "":
        figtitle = matfile
    if matfile.endswith(".pmat"):
        # Use pure python implementation of pmat (faster loading)
        from plearn.vmat.PMat import PMat
        data = PMat(matfile)
    else:
        # Use of VMat through the Python-bridge
        from plearn.pyext import AutoVMatrix
        data = AutoVMatrix(filename=matfile)
    showRowsAsImages(data,
                     img_height=imgheight,
                     img_width=imgwidth,
                     nrows=nrows,
                     ncols=ncols,
                     figtitle=figtitle)
示例#2
0
def computeAndShowFilters(datapmatfile,
                          img_height,
                          img_width,
                          filtertype='PCA',
                          lambd=1e-6,
                          nu=0,
                          centered=True,
                          displaytranspose=False):
    """
    Input is considered to be the first img_height x img_width columns of datapmatfile.
    centered indicates whether we compte centered covariance (default) or uncentered covariance.
    Covariance matrix will get lambd*I added to its diagonal, and its off-diagonal terms multiplied by (1-nu).    
    Filtertype can be 'PCA' or 'denoising' or 'denoising_eig'.

    Original version of linear denoising with zeroing noise (with probability of zeroing equal to nu)
    is obtained for centered=False and lambda=0 
    """
    data = load_pmat_as_array(datapmatfile)
    inputs = data[:, 0:img_height * img_width]
    C = mycov(inputs, centered)
    if (filtertype == "PCA"):
        filters = computePCAFiltersFromCovariance(C, lambd, nu)
    elif (filtertype == "denoising"):
        filters = computeDenoisingFiltersFromCovariance(C, lambd, nu)
    elif (filtertype == "denoising_eig"):
        filters = computeDenoisingEigenFiltersFromCovariance(C, lambd, nu)
    else:
        raise ValueError("Invalid filtertype " + filtertype)
    if displaytranspose:
        filters = filters.T
    showRowsAsImages(filters, img_height, img_width, figtitle="Filters")
示例#3
0
def show_rows_as_images(matfile, imgheight, imgwidth, nrows=10, ncols=10, figtitle=""):
    """Will open a .pmat .dmat .amat or .vmat file and consider the beginning of each row a imgheight x imgwidth imagette.
    These images will be interactively displayed in a nrows x ncols grid of imagettes."""
    data = None
    if figtitle=="":
        figtitle = matfile 
    if matfile.endswith(".pmat"):
        # Use pure python implementation of pmat (faster loading)
        from plearn.vmat.PMat import PMat
        data = PMat(matfile)
    else:
        # Use of VMat through the Python-bridge
        from plearn.pyext import AutoVMatrix
        data = AutoVMatrix(filename=matfile)
    showRowsAsImages(data, img_height=imgheight, img_width=imgwidth, nrows=nrows, ncols=ncols, figtitle=figtitle)
示例#4
0
def computeAndShowFilters(datapmatfile, img_height, img_width, filtertype='PCA', lambd=1e-6, nu=0, centered=True, displaytranspose=False):
    """
    Input is considered to be the first img_height x img_width columns of datapmatfile.
    centered indicates whether we compte centered covariance (default) or uncentered covariance.
    Covariance matrix will get lambd*I added to its diagonal, and its off-diagonal terms multiplied by (1-nu).    
    Filtertype can be 'PCA' or 'denoising' or 'denoising_eig'.

    Original version of linear denoising with zeroing noise (with probability of zeroing equal to nu)
    is obtained for centered=False and lambda=0 
    """
    data = load_pmat_as_array(datapmatfile)
    inputs = data[:,0:img_height*img_width]
    C = mycov(inputs, centered)
    if(filtertype=="PCA"):
        filters = computePCAFiltersFromCovariance(C, lambd, nu)
    elif(filtertype=="denoising"):
        filters = computeDenoisingFiltersFromCovariance(C, lambd, nu)
    elif(filtertype=="denoising_eig"):
        filters = computeDenoisingEigenFiltersFromCovariance(C, lambd, nu)
    else:
        raise ValueError("Invalid filtertype "+filtertype)
    if displaytranspose:
        filters = filters.T
    showRowsAsImages(filters, img_height, img_width, figtitle="Filters")