Beispiel #1
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")
Beispiel #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")
Beispiel #3
0
    showBihistRows(m2,
                   nbins,
                   nbins,
                   nrows=10,
                   ncols=20,
                   startidx=0,
                   figtitle="",
                   luminance_scale_mode=1,
                   vmin=-1.,
                   vmax=1.,
                   transpose_img=False)


def print_usage_and_exit():
    print "Usage : displaybihist.py bihists.pmat"
    print "  will graphically display the bivariate histograms in the pmat."
    sys.exit()


############
### main ###
############

if len(sys.argv) < 2:
    print_usage_and_exit()

pmatfname = sys.argv[1]
m = load_pmat_as_array(pmatfname)

display_bihists(m)
Beispiel #4
0
            if i==j:
                bihist.fill(1.)
            else:
                bihist[:,:] = bihist-outer(hists[i],hists[j])
                
    showBihistRows(m2, nbins, nbins,
                     nrows = 10, ncols = 20,
                     startidx = 0,
                     figtitle="",
                     luminance_scale_mode=1,
                     vmin = -1., vmax = 1.,
                     transpose_img=False)

def print_usage_and_exit():
    print "Usage : displaybihist.py bihists.pmat"
    print "  will graphically display the bivariate histograms in the pmat."
    sys.exit()


############
### main ###
############

if len(sys.argv)<2:
    print_usage_and_exit()

pmatfname = sys.argv[1]
m = load_pmat_as_array(pmatfname)

display_bihists(m)