├── .gitattributes ├── .gitignore ├── 2006 ECCV LSA ├── README.txt ├── helper_functions │ ├── DataProjection.m │ ├── cheegerpartition.m │ ├── cnormalize.m │ ├── evaluatenormalcut.m │ ├── gramsmithorth.m │ ├── lsa.m │ ├── missclass.m │ ├── missclassGroups.m │ ├── modelselection.m │ ├── spectralcluster.m │ ├── spectralclusternormalcut.m │ ├── spectralclusternormalcut_recursive.m │ ├── subspaceaffinity.m │ └── subspaceangle.m └── lsa_test.m ├── 2008 CVPR 2010 PAMI ALC ├── README.txt ├── datasets │ ├── 1R2RC.mat │ ├── arm.mat │ ├── cars10.mat │ └── oc1R2RC.mat ├── find_best_segmentation.m ├── helpers │ ├── coding_length.m │ ├── coding_seg.m │ ├── compare_labels.m │ ├── distinct_labels.m │ ├── relabel_samples.m │ ├── repair_corrupted_data.m │ ├── repair_incomplete_data.m │ └── total_coding_length.m ├── load_sequence.m ├── plot_error.m ├── process_sequence.m ├── runALC.m └── try_sequence.m ├── 2009 CVPR 2013 PAMI SSC ├── BuildAdjacency.m ├── DataProjection.m ├── SSC.m ├── SpectralClustering.m ├── admmLasso_mat_func.m ├── admmOutlier_mat_func.m ├── bestMap.m ├── computeLambda_mat.m ├── errorCoef.m ├── errorLinSys.m ├── hungarian.m ├── matrixNormalize.m ├── readme.pdf ├── readme.rtf ├── run_SSC_Faces.m ├── run_SSC_MS.m └── thrC.m ├── 2009 IJCV SCC ├── DataProjection.m ├── K_flats.m ├── computing_average_L2_error.m ├── computing_centers_and_bases.m ├── computing_percentage_of_misclassified_points.m ├── computing_point_to_flat_distances.m ├── computing_polar_curvatures.m ├── do_plot_data.m ├── lscc.m ├── missclass.m ├── processing_affinities.m ├── readme.txt ├── run_SCC_Faces.m ├── run_SCC_MS.m ├── sampling_columns.m ├── scc.m └── svd_thin_US_rot.m ├── 2010 ICML 2013 PAMI LRR ├── Hungarian.m ├── compacc.m ├── loadmatfile.m ├── lrr_face_seg.m ├── lrr_motion_seg.m ├── lrra.m ├── missclassGroups.m └── solve_lrr.m ├── 2011 CVPR 2014 PRL LRSC ├── BuildAdjacency.m ├── DataProjection.m ├── Misclassification.m ├── SpectralClustering.m ├── cnormalize.m ├── lrsc.m ├── lrsc_noiseless.m ├── lrsc_noisy.m ├── lrsc_outliersexact.m ├── lrsc_outliersrelax.m ├── missclassGroups.m ├── mregularize.m ├── polythreshAP.m ├── polythreshCF.m ├── runlrsc.m └── thrC.m ├── 2012 ECCV LSR ├── LSR_FS │ ├── Data │ │ └── YaleB.mat │ ├── Experiment_FS.m │ ├── LSR │ │ ├── LSR1.m │ │ └── LSR2.m │ ├── PCA.m │ ├── SubspaceSegmentation.m │ ├── clu_ncut.m │ ├── compacc.m │ └── read me.txt └── LSR_MS │ ├── Experiment_MS.m │ ├── LSR │ ├── LSR1.m │ └── LSR2.m │ ├── PCA.m │ ├── SubspaceSegmentation.m │ ├── clu_ncut.m │ ├── compacc.m │ └── read me.txt ├── 2014 CVPR BD ├── main.m └── ssgd.m ├── 2014 CVPR SMR ├── PCA.m ├── bestMap.m ├── clu_ncut.m ├── compacc.m ├── compacc_ce.m ├── data │ ├── YaleB │ │ └── yaleB10.mat │ ├── hopkins155 │ │ └── total.txt │ └── usps │ │ └── usps_part.mat ├── demo_face_smr.m ├── demo_mnist_smr.m ├── demo_motion_smr.m ├── demo_usps_smr.m ├── get_nn_graph.m ├── hungarian.m ├── readme.txt └── smr.m ├── 2015 CVPR MGR ├── BuildAdjacency.m ├── Misclassification.m ├── Mltg.m ├── OutlierDetection.m ├── PCA.m ├── Readme.txt ├── SpectralClustering.m ├── avoidze.m ├── clu_ncut.m ├── compacc.m ├── finalresulXn.m ├── findcovj.m ├── gamij.m ├── maincode.m ├── missclassGroups.m ├── solvematrix.m ├── updattweig.m └── weightsumgaupdf.m ├── 2015 CVPR S3C ├── ADMM_StrSSC.m ├── BuildAdjacency.m ├── DataProjection.m ├── Misclassification.m ├── SpectralClustering.m ├── StrSSC.m ├── compacc.m ├── computeLambda_mat.m ├── errorCoef.m ├── errorLinSys.m ├── kmeans.m ├── matrixNormalize.m ├── missclassGroups.m ├── readme.txt ├── run_StrSSC_Faces.m └── thrC.m ├── 2015 ICCV RSIM ├── ComputeNcutValue.m ├── ErrorRate.m ├── Hopkins155_SIM.m ├── Hopkins_missing_outliers.m ├── RSIM.m ├── RSIM_Incomplete.m ├── grouse.m ├── missclassGroups.m └── readme.txt ├── 2016 CVPR SSCOMP ├── EYaleB │ └── ExtendedYaleB.mat ├── MNIST │ └── SCofDigits.m ├── OMP_mat_func.m ├── SpectralClustering.m ├── bestMap.m ├── cnormalize.m ├── cnormalize_inplace.m ├── dimReduction_PCA.m ├── evalAccuracy.m ├── evalConn.m ├── evalSSR_error.m ├── evalSSR_perc.m ├── genSubspace.m ├── hungarian.m ├── loadMNISTImages.m ├── loadMNISTLabels.m ├── readme.txt ├── run_EYaleB.m ├── run_MNIST.m ├── run_Synthetic.m ├── scatnet-0.2 │ ├── .gitignore │ ├── LICENSE-2.0.txt │ ├── README.md │ ├── addpath_scatnet.m │ ├── classification │ │ ├── affine_param_search.m │ │ ├── affine_test.m │ │ ├── affine_train.m │ │ ├── classif_err.m │ │ ├── classif_mean_err_rate.m │ │ ├── classif_recog.m │ │ ├── create_partition.m │ │ ├── create_src.m │ │ ├── duration_feature.m │ │ ├── feature_wrapper.m │ │ ├── fmd_src.m │ │ ├── next_fold.m │ │ ├── prepare_database.m │ │ ├── svm_adaptive_param_search.m │ │ ├── svm_calc_kernel.m │ │ ├── svm_extract_w.m │ │ ├── svm_param_search.m │ │ ├── svm_test.m │ │ └── svm_train.m │ ├── convolution │ │ ├── conv_sub_1d.m │ │ ├── conv_sub_2d.m │ │ ├── extract_block.m │ │ ├── pad_signal.m │ │ ├── pad_size.m │ │ ├── sub_conv_1d_along_third_dim_simple.m │ │ └── unpad_signal.m │ ├── core │ │ ├── inverse_wavelet_1d.m │ │ ├── modulus_layer.m │ │ ├── scat.m │ │ ├── scat_freq.m │ │ ├── spec_freq_average.m │ │ ├── wavelet_1d.m │ │ ├── wavelet_2d.m │ │ ├── wavelet_2d_pyramid.m │ │ ├── wavelet_3d.m │ │ ├── wavelet_3d_pyramid.m │ │ ├── wavelet_factory_1d.m │ │ ├── wavelet_factory_2d.m │ │ ├── wavelet_factory_2d_pyramid.m │ │ ├── wavelet_factory_3d.m │ │ ├── wavelet_factory_3d_pyramid.m │ │ ├── wavelet_layer_1d.m │ │ ├── wavelet_layer_2d.m │ │ ├── wavelet_layer_2d_pyramid.m │ │ ├── wavelet_layer_3d.m │ │ └── wavelet_layer_3d_pyramid.m │ ├── demo │ │ ├── audio_demo1.m │ │ ├── audio_demo2.m │ │ ├── convolution │ │ │ └── demo_conv_sub_1d.m │ │ ├── core │ │ │ ├── demo_scat_2d_unitary.m │ │ │ ├── demo_scat_3d_pyramid_rotation_invariance.m │ │ │ ├── demo_scat_3d_rotation_invariance.m │ │ │ ├── demo_wavelet_2d.m │ │ │ ├── demo_wavelet_factory_2d.m │ │ │ └── demo_wavelet_layer_2d.m │ │ ├── display │ │ │ ├── demo_display_filters_2d.m │ │ │ ├── demo_image_scat.m │ │ │ ├── demo_plot_littlewood_paley_1d.m │ │ │ └── demo_plot_meta.m │ │ ├── filters │ │ │ ├── demo_bank_filters.m │ │ │ └── demo_individual_filter.m │ │ └── scatutils │ │ │ ├── demo_format_scat.m │ │ │ └── demo_log_scat.m │ ├── display │ │ ├── display_filter_2d.m │ │ ├── display_filter_bank_2d.m │ │ ├── display_littlewood_paley_2d.m │ │ ├── display_multifractal.m │ │ ├── display_slice.m │ │ ├── display_with_layer_order.m │ │ ├── image_complex.m │ │ ├── image_scat.m │ │ ├── image_scat_layer.m │ │ ├── image_scat_layer_order.m │ │ ├── meta2str.m │ │ ├── plot_diracnorm_scat.m │ │ ├── plot_littlewood_paley_1d.m │ │ ├── plot_lognorm_scat2_1d.m │ │ ├── plot_meta.m │ │ ├── plot_meta_layer.m │ │ ├── plot_spect_scat.m │ │ ├── scatter_meta.m │ │ ├── scattergram.m │ │ ├── scattergram_layer.m │ │ └── str2imfast.m │ ├── doc │ │ ├── arch │ │ │ ├── arch.pdf │ │ │ └── arch.tex │ │ ├── common │ │ │ └── mcode.sty │ │ ├── gaussian_filters.pdf │ │ └── impl │ │ │ ├── impl.pdf │ │ │ └── impl.tex │ ├── filters │ │ ├── T_to_J.m │ │ ├── default_filter_options.m │ │ ├── dual_filter_bank.m │ │ ├── dyadic_freq_1d.m │ │ ├── filter_bank.m │ │ ├── filter_freq.m │ │ ├── gabor_2d.m │ │ ├── gaussian_2d.m │ │ ├── haar_filter_bank_2d_pyramid.m │ │ ├── littlewood_paley.m │ │ ├── morlet_2d_noDC.m │ │ ├── morlet_2d_pyramid.m │ │ ├── morlet_filter_bank_1d.m │ │ ├── morlet_filter_bank_2d.m │ │ ├── morlet_filter_bank_2d_pyramid.m │ │ ├── morlet_freq_1d.m │ │ ├── optimize_filter.m │ │ ├── periodize_filter.m │ │ ├── realize_filter.m │ │ ├── rotation_matrix_2d.m │ │ ├── selesnick │ │ │ ├── FSfarras.m │ │ │ ├── afb.m │ │ │ ├── cshift.m │ │ │ ├── dualfilt1.m │ │ │ ├── dualtree.m │ │ │ ├── idualtree.m │ │ │ ├── selesnick_bis.m │ │ │ └── sfb.m │ │ ├── selesnick_filter_bank_1d.m │ │ ├── shannon_filter_bank_2d.m │ │ ├── spline_filter_bank_1d.m │ │ └── truncate_filter.m │ ├── papers │ │ ├── DSS │ │ │ ├── DSS_Figure1.m │ │ │ ├── DSS_Figure2.m │ │ │ ├── DSS_Figure3.m │ │ │ ├── DSS_Figure5.m │ │ │ ├── DSS_Figure6.m │ │ │ ├── DSS_Figure7.m │ │ │ ├── DSS_Table1.m │ │ │ ├── DSS_Table2_GTZAN_m1.m │ │ │ ├── DSS_Table2_GTZAN_m2.m │ │ │ ├── DSS_Table2_GTZAN_m2_freq.m │ │ │ ├── DSS_Table2_GTZAN_m2_freq_multQ1.m │ │ │ ├── DSS_Table2_GTZAN_m2_freq_multQ1_multT.m │ │ │ ├── DSS_Table2_GTZAN_m3.m │ │ │ ├── DSS_Table2_GTZAN_mfcc_23ms.m │ │ │ ├── DSS_Table2_GTZAN_mfcc_370ms.m │ │ │ ├── DSS_Table2_TIMIT_m1.m │ │ │ ├── DSS_Table2_TIMIT_m2.m │ │ │ ├── DSS_Table2_TIMIT_m2_freq.m │ │ │ ├── DSS_Table2_TIMIT_m2_freq_multQ1.m │ │ │ ├── DSS_Table2_TIMIT_m2_freq_multQ1_multT.m │ │ │ ├── DSS_Table2_TIMIT_m3.m │ │ │ ├── DSS_Table2_TIMIT_mfcc_32ms.m │ │ │ ├── DSS_Table2_TIMIT_mfcc_512ms.m │ │ │ ├── chord_signal.wav │ │ │ ├── dilation.wav │ │ │ ├── gtzan_src.m │ │ │ ├── kodaly.wav │ │ │ ├── mod_signal.wav │ │ │ ├── phone_partition.m │ │ │ ├── phone_src.m │ │ │ ├── questions.wav │ │ │ └── renorm_1st_phi.m │ │ ├── GIS │ │ │ ├── GIS_Figure3_1.m │ │ │ ├── GIS_Figure3_2.m │ │ │ ├── GIS_Figure4_1.m │ │ │ ├── GIS_Figure4_2.m │ │ │ └── multi_J_scatter.m │ │ ├── IPASM │ │ │ ├── .generate_figures.m.swn │ │ │ ├── .generate_figures.m.swo │ │ │ ├── MRWsimu.m │ │ │ ├── example_facile.m │ │ │ ├── fGnsimu.m │ │ │ ├── first_order_reshape.m │ │ │ ├── generate_figures.m │ │ │ ├── mfracts.tgz │ │ │ ├── plot_full_transfer.m │ │ │ ├── plot_stat_transfer.m │ │ │ ├── scat_renorm_1d.m │ │ │ ├── scat_renorm_1d_scatnet.m │ │ │ ├── sec_order_reshape.m │ │ │ ├── stblrnd.m │ │ │ ├── update_avg_coeffs.m │ │ │ ├── wavelet_factory_1dave.m │ │ │ └── wavelet_layer_1dave.m │ │ ├── ISCV │ │ │ ├── D107.gif │ │ │ ├── ISCV_Figure1.m │ │ │ ├── ISCV_Figure4.m │ │ │ ├── ISCV_Figure5.m │ │ │ ├── ISCV_Figure7.m │ │ │ ├── ISCV_Figure9.m │ │ │ ├── add_circular_mask.m │ │ │ ├── crop.m │ │ │ ├── dualwavelets.m │ │ │ ├── equalize_first_order_scattering.m │ │ │ ├── legacy_reshape_filters.m │ │ │ ├── littlewood_paley_ISCV.m │ │ │ ├── readidx.m │ │ │ ├── recover_meta.m │ │ │ ├── retrieve_mnist_data.m │ │ │ ├── scat_display.m │ │ │ ├── show_two_spectra_dlux.m │ │ │ └── show_two_spectra_dlux_ps.m │ │ ├── RSDS │ │ │ ├── cellfun_monitor.m │ │ │ ├── cellsrc2db.m │ │ │ ├── figure_1.m │ │ │ ├── figure_4.m │ │ │ ├── kthtips_src.m │ │ │ ├── rsds_classif.m │ │ │ ├── srcfun.m │ │ │ ├── table_1.m │ │ │ ├── table_2.m │ │ │ ├── uiuc_src.m │ │ │ └── umd_src.m │ │ └── paper-list.txt │ ├── reconstruction │ │ ├── griffin_lim.m │ │ ├── inverse_scat.m │ │ └── richardson_lucy.m │ ├── scatutils │ │ ├── aggregate_scat.m │ │ ├── average_scat.m │ │ ├── concatenate_freq.m │ │ ├── diracnorm_scat.m │ │ ├── flatten_scat.m │ │ ├── format_scat.m │ │ ├── generate_path.m │ │ ├── hanning_standalone.m │ │ ├── log_scat.m │ │ ├── map_meta.m │ │ ├── max_scat.m │ │ ├── mean_renorm_scat.m │ │ ├── orientation_avg_scat.m │ │ ├── rdivide_scat.m │ │ ├── remove_margin.m │ │ ├── renorm_low_pass_layer_1d.m │ │ ├── renorm_parent_2d.m │ │ ├── renorm_parent_3d.m │ │ ├── renorm_scat.m │ │ ├── renorm_wavelet_layer_factory_1d.m │ │ ├── reorder_scat.m │ │ ├── scat_energy.m │ │ ├── scat_mask.m │ │ ├── scatfun.m │ │ ├── scatfun_layer.m │ │ ├── separate_freq.m │ │ ├── standardize.m │ │ └── standardize_wavelet_layer_1d.m │ └── utils │ │ ├── check_options_white_list.m │ │ ├── data_read.m │ │ ├── downsample_noninteger.m │ │ ├── fill_struct.m │ │ ├── fun_multiscale.m │ │ ├── func_output.m │ │ ├── getoptions.m │ │ ├── git_hash.m │ │ ├── imreadBW.m │ │ ├── imresize_notoolbox.m │ │ ├── imwriteBW.m │ │ ├── mandrill.m │ │ ├── rgb2yuv.m │ │ ├── rgb_fun.m │ │ ├── scale_ds.m │ │ ├── sphere_read.m │ │ ├── sub_options.m │ │ ├── uiuc_example.jpg │ │ ├── uiuc_sample.m │ │ ├── upsample.m │ │ └── yuv_fun.m └── vararginParser.m ├── 2017 CVPR NVR3 ├── NVR3.m ├── binaryalphadigs_processed.mat ├── cccircprod.m ├── clu_ncut.m ├── codes │ ├── KSC_Acc.m │ ├── README │ ├── accuracy.m │ ├── gen_nn_distance.m │ ├── hungarian.m │ ├── k_means.m │ ├── nmi.m │ ├── nystrom.m │ ├── nystrom_no_orth.m │ ├── sc.m │ ├── script_kmeans.m │ ├── script_nystrom.m │ ├── script_nystrom_no_orth.m │ ├── script_sc.m │ ├── script_sc_selftune.m │ └── spectral_clustering.m ├── digit_NVR3.mat ├── procdata.m └── run_face_nvr3.m ├── README.md ├── ReadResults.m └── Transform.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /2006 ECCV LSA/README.txt: -------------------------------------------------------------------------------- 1 | ======================= 2 | Local Subspace Analysis 3 | ======================= 4 | Version: May 24th, 2010 5 | 6 | This package contains a Matlab implementation of the Local Subspace Analysis algorithm introduced in the paper 7 | 8 | J. Yan and M. Pollefeys 9 | A general framework for motion segmentation: Independent, articulated, rigid, non-rigid, degenerate and non-degenerate 10 | European Conference on Computer Vision, pages 94-106, 2006 11 | 12 | The main file of the implementation is lsa.m. The file lsa_test.m prepares and applies the algorithm to a simple subspace clustering problem. 13 | 14 | Copyright 2010 VisionLab http://vision.jhu.edu 15 | 16 | 17 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/DataProjection.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the D x N data matrix with columns indicating 3 | % different data points and project the D dimensional data into a r 4 | % dimensional subspace using PCA. 5 | % X: D x N matrix of N data points 6 | % r: dimension of the PCA projection, if r = 0, then no projection 7 | % Xp: r x N matrix of N projectred data points 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Xp = DataProjection(X,r) 14 | 15 | if (nargin < 2) 16 | r = 0; 17 | end 18 | 19 | if (r == 0) 20 | Xp = X; 21 | else 22 | [U,~,~] = svd(X,0); 23 | Xp = U(:,1:r)' * X; 24 | end 25 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/cheegerpartition.m: -------------------------------------------------------------------------------- 1 | %evaluates the cheeger constant for a given partition 2 | function h=cheegerpartition(group,simMat); 3 | d=sum(simMat,2); %grade of each node (sum of distances on the row) 4 | [IcutA,IcutB]=meshgrid(group-1,2-group); %bool that indicates if a group is connected to A and/or B 5 | IcutAB=and(IcutA,IcutB); %indeces of nodes of A connected to B 6 | cutAB=sum(simMat(find(IcutAB))); %sum of arcs from A to B 7 | 8 | %compute the cheeger constant for this partition 9 | h=cutAB/min(sum(d(find(group==1))),sum(d(find(group==2)))); -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/cnormalize.m: -------------------------------------------------------------------------------- 1 | function [xn,normx] = cnormalize(x) 2 | [K,N] = size(x); 3 | normx = sqrt(sum(conj(x).*x,1)); 4 | xn = x ./ (ones(K,1)*normx); 5 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/evaluatenormalcut.m: -------------------------------------------------------------------------------- 1 | %evaluates the normal cut function 2 | % group is a vector of zeros and ones that indicates the two partitions 3 | % simMat is the similarity matrix 4 | function cost=evaluatenormalcut(group,simMat); 5 | 6 | d=sum(simMat,2); %grade of each node (sum of distances on the row) 7 | assocA=sum(d(find(group==0))); %association of cluster A 8 | assocB=sum(d(find(group==1))); %association of cluster B 9 | [IcutA,IcutB]=meshgrid(group,1-group); %bool that indicates if a group is connected to A and/or B 10 | IcutAB=and(IcutA,IcutB); %indeces of nodes of A connected to B 11 | IcutBA=not(or(IcutA,IcutB)); %indeces of nodes of B connected to A 12 | cutAB=sum(simMat(find(IcutAB))); %sum of arcs from A to B 13 | cutBA=sum(simMat(find(IcutBA))); %sum of arcs from B to A 14 | cost=cutAB/assocA+cutBA/assocB; %normal cut cost function 15 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/gramsmithorth.m: -------------------------------------------------------------------------------- 1 | %function y=gramsmithorth(x) 2 | % Returns Y the Gram-Smith orthogonalization of the colums of X 3 | % Y and X have the same dimensions 4 | function y=gramsmithorth(x) 5 | [K,D]=size(x); 6 | 7 | I=eye(K); 8 | 9 | y=x(:,1)/norm(x(:,1)); 10 | for(i=2:D) 11 | newcol=(I-y*y')*x(:,i); 12 | newcol=newcol/norm(newcol); 13 | y=[y newcol]; 14 | end 15 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/missclass.m: -------------------------------------------------------------------------------- 1 | function [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 2 | 3 | % [miss,index] = missclass(Segmentation,npoints,ngroups) 4 | % 5 | % Computes the number of missclassified points in the vector Segmentation. 6 | % 7 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 8 | % the label for each group, ranging from 1 to n 9 | 10 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 11 | % points in each group. 12 | 13 | % ngroups: number of groups 14 | 15 | Permutations = perms(1:ngroups); 16 | if(size(Segmentation,2)==1) 17 | Segmentation=Segmentation'; 18 | end 19 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 20 | for k=1:size(Segmentation,1) 21 | for j=1:size(Permutations,1) 22 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 23 | end 24 | end 25 | 26 | [miss,temp] = min(miss,[],1); 27 | index = Permutations(temp,:); -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/missclassGroups.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 3 | % Computes the number of missclassified points in the vector Segmentation. 4 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 5 | % the label for each group, ranging from 1 to n 6 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 7 | % points in each group. 8 | % ngroups: number of groups 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2010 11 | %-------------------------------------------------------------------------- 12 | 13 | 14 | function [miss,index] = missclassGroups(Segmentation,RefSegmentation,ngroups) 15 | if(size(RefSegmentation,2)==1) 16 | RefSegmentation=RefSegmentation'; 17 | end 18 | if(size(Segmentation,2)==1) 19 | Segmentation=Segmentation'; 20 | end 21 | Permutations = perms(1:ngroups); 22 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 23 | for k=1:size(Segmentation,1) 24 | for j=1:size(Permutations,1) 25 | miss(j,k) = sum(abs(Segmentation(k,:)-Permutations(j,RefSegmentation))>0.1); 26 | end 27 | end 28 | 29 | [miss,temp] = min(miss,[],1); 30 | index = Permutations(temp,:); 31 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/modelselection.m: -------------------------------------------------------------------------------- 1 | function matrank=modelselection(sv,k) 2 | for(r=1:length(sv)-1) 3 | allr(r)=sv(r+1)^2/sum(sv(1:r).^2)+k*r; 4 | end 5 | [minr,matrank]=min(allr); 6 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/spectralcluster.m: -------------------------------------------------------------------------------- 1 | % affmat is the affinity matrix A 2 | % k is the number of largest eigenvectors in matrix L 3 | % num_class is the number of classes 4 | 5 | %diagmat is the diagonal matrix D^(-0.5) 6 | % Lmat is the matrix L 7 | %X and Y ar matrices formed from eigenvectors of L 8 | % IDX is the clustering results 9 | % errorsum is the distance from kmeans 10 | 11 | function [diagMat,LMat,X,Y,IDX,errorsum]= spectralcluster(affMat,k,num_class) 12 | 13 | numDT=size(affMat,2); 14 | 15 | diagMat= diag((sum(affMat,2)).^(-1./2)); 16 | LMat=diagMat*affMat*diagMat; 17 | 18 | [v,d]=eigs(LMat,k); 19 | 20 | X=v(:,1:k); 21 | normX=(sum(X.^2,2)).^(1./2); 22 | Y=zeros(size(X)); 23 | for index=1:numDT 24 | Y(index,:)=X(index,:)./normX(index,1); 25 | end 26 | 27 | [IDX,C,sumd] = kmeans(Y,num_class,'EmptyAction','drop','Replicates',10); 28 | %[C,IDX] = kmeans(Y,num_class); 29 | 30 | errorsum=1;%sum(sum(sumd)); -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/spectralclusternormalcut.m: -------------------------------------------------------------------------------- 1 | function [group,cheeger]=spectralclusternormalcut(simMat) 2 | %number of thresholds to try 3 | l=1500; 4 | 5 | d=sum(simMat,2); 6 | D=diag(d); 7 | D2=diag(sqrt(d)); 8 | [U,S,V]=svd(D2*(D-simMat)*D2); 9 | x=U(:,end-1); 10 | th=linspace(min(x),max(x),l+2); 11 | th=th(2:end-1); 12 | cutcosts=zeros(l,1); 13 | cheegers=zeros(l,1); 14 | for(i=1:l) 15 | cutcosts(i)=evaluatenormalcut(x>th(i),simMat); 16 | end 17 | [mincost,minindex]=min(cutcosts); 18 | group=(x>th(minindex))+1; 19 | cheeger=cheegerpartition(group,simMat); 20 | -------------------------------------------------------------------------------- /2006 ECCV LSA/helper_functions/spectralclusternormalcut_recursive.m: -------------------------------------------------------------------------------- 1 | %function group=spectralclusternormalcut_recursive(n,simMat) 2 | %n final number of cluster 3 | %simMat similarity matrix 4 | function group=spectralclusternormalcut_recursive(n,simMat) 5 | %trivial case with 1 cluster 6 | if(n==1) 7 | group=ones(size(simMat,1),1); 8 | end 9 | %initial bipartition with spectral clustering 10 | group=spectralclusternormalcut(simMat); 11 | 12 | %call spectral clustering recursively 13 | for(i=2:n-1) 14 | mincheeger=Inf; %init 15 | %try to split each cluster 16 | for(j=1:i) 17 | clusterindeces=find(group==j); 18 | [groupcluster,clustercheeger]=spectralclusternormalcut(simMat(clusterindeces,clusterindeces)); 19 | %if the cheeger constant is less than in the previous clusters 20 | if(clustercheeger(90 degrees) 13 | % 0.7854 ----->(45 degrees) 14 | 15 | [U,S,V]=svd(base1'*base2,'econ'); 16 | costheta=flipud(svd(base2'*base1)); 17 | theta=acos(min(1,costheta)); -------------------------------------------------------------------------------- /2008 CVPR 2010 PAMI ALC/datasets/1R2RC.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2008 CVPR 2010 PAMI ALC/datasets/1R2RC.mat -------------------------------------------------------------------------------- /2008 CVPR 2010 PAMI ALC/datasets/arm.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2008 CVPR 2010 PAMI ALC/datasets/arm.mat -------------------------------------------------------------------------------- /2008 CVPR 2010 PAMI ALC/datasets/cars10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2008 CVPR 2010 PAMI ALC/datasets/cars10.mat -------------------------------------------------------------------------------- /2008 CVPR 2010 PAMI ALC/datasets/oc1R2RC.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2008 CVPR 2010 PAMI ALC/datasets/oc1R2RC.mat -------------------------------------------------------------------------------- /2008 CVPR 2010 PAMI ALC/helpers/total_coding_length.m: -------------------------------------------------------------------------------- 1 | function codingLength = total_coding_length(data, labels, epsilon, affine) 2 | 3 | % total_coding_length 4 | % 5 | % compute the total number of bits needed to code a set of data vectors 6 | % given a grouping, and an error tolerance. 7 | % 8 | % Inputs: 9 | % data - a matrix where each column is a data vector. 10 | % labels - a list of integer labels that partitions the data into groups 11 | % epsilon - the error tolerance 12 | % affine - if true, compute using the affine coding length function. 13 | % otherwise use the linear coding length function 14 | % 15 | % Outputs: 16 | % codingLength - the total number of bits needed to code this set of data 17 | % 18 | % Dependencies: 19 | % coding_length 20 | % 21 | % Sep. '07 Shankar Rao -- srrao@uiuc.edu 22 | 23 | % Copyright 2007, University of Illinois. All rights reserved. 24 | 25 | codingLength = 0; 26 | groupCount = max(labels); 27 | sampleCount = length(labels); 28 | % Make sure outlier indices are counted too 29 | % modified 10-24-07 30 | setOfIndices = unique(labels); 31 | for groupIndex = setOfIndices(:)', 32 | codingLength = codingLength + coding_length(data(:, labels == groupIndex), epsilon^2, sampleCount, affine); 33 | end -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/BuildAdjacency.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes a NxN coefficient matrix and returns a NxN adjacency 3 | % matrix by choosing the K strongest connections in the similarity graph 4 | % CMat: NxN coefficient matrix 5 | % K: number of strongest edges to keep; if K=0 use all the exiting edges 6 | % CKSym: NxN symmetric adjacency matrix 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | 12 | function [CKSym,CAbs] = BuildAdjacency(CMat,K) 13 | 14 | if (nargin < 2) 15 | K = 0; 16 | end 17 | 18 | N = size(CMat,1); 19 | CAbs = abs(CMat); 20 | 21 | [Srt,Ind] = sort( CAbs,1,'descend' ); 22 | 23 | if (K == 0) 24 | for i = 1:N 25 | CAbs(:,i) = CAbs(:,i) ./ (CAbs(Ind(1,i),i)+eps); 26 | end 27 | else 28 | for i = 1:N 29 | for j = 1:K 30 | CAbs(Ind(j,i),i) = CAbs(Ind(j,i),i) ./ (CAbs(Ind(1,i),i)+eps); 31 | end 32 | end 33 | end 34 | 35 | CKSym = CAbs + CAbs'; -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/DataProjection.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the D x N data matrix with columns indicating 3 | % different data points and project the D dimensional data into a r 4 | % dimensional subspace using PCA. 5 | % X: D x N matrix of N data points 6 | % r: dimension of the PCA projection, if r = 0, then no projection 7 | % Xp: r x N matrix of N projectred data points 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Xp = DataProjection(X,r) 14 | 15 | if (nargin < 2) 16 | r = 0; 17 | end 18 | 19 | if (r == 0) 20 | Xp = X; 21 | else 22 | [U,~,~] = svd(X,0); 23 | Xp = U(:,1:r)' * X; 24 | end 25 | -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/SSC.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This is the function to call the sparse optimization program, to call the 3 | % spectral clustering algorithm and to compute the clustering error. 4 | % r = projection dimension, if r = 0, then no projection 5 | % affine = use the affine constraint if true 6 | % s = clustering ground-truth 7 | % missrate = clustering error 8 | % CMat = coefficient matrix obtained by SSC 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2012 11 | %-------------------------------------------------------------------------- 12 | 13 | function [missrate,CMat] = SSC(X,r,affine,alpha,outlier,rho,s) 14 | 15 | if (nargin < 6) 16 | rho = 1; 17 | end 18 | if (nargin < 5) 19 | outlier = false; 20 | end 21 | if (nargin < 4) 22 | alpha = 20; 23 | end 24 | if (nargin < 3) 25 | affine = false; 26 | end 27 | if (nargin < 2) 28 | r = 0; 29 | end 30 | 31 | n = max(s); 32 | Xp = DataProjection(X,r); 33 | 34 | if (~outlier) 35 | CMat = admmLasso_mat_func(Xp,affine,alpha); 36 | C = CMat; 37 | else 38 | CMat = admmOutlier_mat_func(Xp,affine,alpha); 39 | N = size(Xp,2); 40 | C = CMat(1:N,:); 41 | end 42 | 43 | CKSym = BuildAdjacency(thrC(C,rho)); 44 | grps = SpectralClustering(CKSym,n); 45 | grps = bestMap(s,grps); 46 | missrate = sum(s(:) ~= grps(:)) / length(s); -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/SpectralClustering.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes an adjacency matrix of a graph and computes the 3 | % clustering of the nodes using the spectral clustering algorithm of 4 | % Ng, Jordan and Weiss. 5 | % CMat: NxN adjacency matrix 6 | % n: number of groups for clustering 7 | % groups: N-dimensional vector containing the memberships of the N points 8 | % to the n groups obtained by spectral clustering 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2012 11 | % Modified @ Chong You, 2015 12 | %-------------------------------------------------------------------------- 13 | 14 | function [groups, kerNS] = SpectralClustering(CKSym,n) 15 | 16 | warning off; 17 | N = size(CKSym,1); 18 | MAXiter = 1000; % Maximum number of iterations for KMeans 19 | REPlic = 20; % Number of replications for KMeans 20 | 21 | % Normalized spectral clustering according to Ng & Jordan & Weiss 22 | % using Normalized Symmetric Laplacian L = I - D^{-1/2} W D^{-1/2} 23 | 24 | DN = diag( 1./sqrt(sum(CKSym)+eps) ); 25 | LapN = speye(N) - DN * CKSym * DN; 26 | [~,~,vN] = svd(LapN); 27 | kerN = vN(:,N-n+1:N); 28 | normN = sum(kerN .^2, 2) .^.5; 29 | kerNS = bsxfun(@rdivide, kerN, normN + eps); 30 | groups = kmeans(kerNS,n,'maxiter',MAXiter,'replicates',REPlic,'EmptyAction','singleton'); -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/bestMap.m: -------------------------------------------------------------------------------- 1 | function [newL2] = bestMap(L1,L2) 2 | %bestmap: permute labels of L2 to match L1 as good as possible 3 | % [newL2] = bestMap(L1,L2); 4 | % 5 | % version 2.0 --May/2007 6 | % version 1.0 --November/2003 7 | % 8 | % Written by Deng Cai (dengcai AT gmail.com) 9 | 10 | 11 | %=========== 12 | 13 | L1 = L1(:); 14 | L2 = L2(:); 15 | if size(L1) ~= size(L2) 16 | error('size(L1) must == size(L2)'); 17 | end 18 | 19 | Label1 = unique(L1); 20 | nClass1 = length(Label1); 21 | Label2 = unique(L2); 22 | nClass2 = length(Label2); 23 | 24 | nClass = max(nClass1,nClass2); 25 | G = zeros(nClass); 26 | for i=1:nClass1 27 | for j=1:nClass2 28 | G(i,j) = length(find(L1 == Label1(i) & L2 == Label2(j))); 29 | end 30 | end 31 | 32 | [c,t] = hungarian(-G); 33 | newL2 = zeros(size(L2)); 34 | for i=1:nClass2 35 | newL2(L2 == Label2(i)) = Label1(c(i)); 36 | end 37 | -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/computeLambda_mat.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes a DxN matrix of N data points in a D-dimensional 3 | % space and returns the regularization constant of the L1 norm 4 | % Y: DxN data matrix 5 | % lambda: regularization parameter for lambda*||C||_1 + 0.5 ||Y-YC||_F^2 6 | %-------------------------------------------------------------------------- 7 | % Copyright @ Ehsan Elhamifar, 2012 8 | %-------------------------------------------------------------------------- 9 | 10 | function lambda = computeLambda_mat(Y,P) 11 | 12 | if (nargin < 2) 13 | P = Y; 14 | end 15 | 16 | N = size(Y,2); 17 | T = P' * Y; 18 | T(1:N,:) = T(1:N,:) - diag(diag(T(1:N,:))); 19 | T = abs(T); 20 | lambda = min(max(T,[],1)); 21 | -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/errorCoef.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function computes the maximum error between elements of two 3 | % coefficient matrices 4 | % C: NxN coefficient matrix 5 | % Z: NxN coefficient matrix 6 | % err: infinite norm error between vectorized C and Z 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | function err = errorCoef(Z,C) 12 | 13 | err = max(max( abs(Z-C) )); 14 | %err = norm(Z-C,'fro'); -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/errorLinSys.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function computes the maximum L2-norm error among the columns of the 3 | % residual of a linear system 4 | % Y: DxN data matrix of N data point in a D-dimensional space 5 | % Z: NxN sparse coefficient matrix 6 | % err: maximum L2-norm of the columns of Y-YZ 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | function err = errorLinSys(P,Z) 12 | 13 | [R,N] = size(Z); 14 | if (R > N) 15 | E = P(:,N+1:end) * Z(N+1:end,:); 16 | Y = P(:,1:N); 17 | Y0 = Y - E; 18 | C = Z(1:N,:); 19 | else 20 | Y = P; 21 | Y0 = P; 22 | C = Z; 23 | end 24 | 25 | [Yn,n] = matrixNormalize(Y0); 26 | M = repmat(n,size(Y,1),1); 27 | S = Yn - Y * C ./ M; 28 | err = sqrt( max( sum( S.^2,1 ) ) ); -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/matrixNormalize.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function normalizes the columns of a given matrix 3 | % Y: DxN data matrix 4 | % Yn: DxN data matrix whose columns have unit Euclidean norm 5 | % n: N-dimensional vector of the norms of the columns of Y 6 | %-------------------------------------------------------------------------- 7 | % Copyright @ Ehsan Elhamifar, 2012 8 | %-------------------------------------------------------------------------- 9 | 10 | function [Yn,n] = matrixNormalize(Y) 11 | 12 | for i = 1:size(Y,2) 13 | n(i) = norm(Y(:,i)); 14 | Yn(:,i) = Y(:,i) ./ n(i); 15 | end -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/readme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2009 CVPR 2013 PAMI SSC/readme.pdf -------------------------------------------------------------------------------- /2009 CVPR 2013 PAMI SSC/thrC.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % Copyright @ Ehsan Elhamifar, 2012 3 | %-------------------------------------------------------------------------- 4 | 5 | function Cp = thrC(C,ro) 6 | 7 | if (nargin < 2) 8 | ro = 1; 9 | end 10 | 11 | if (ro < 1) 12 | N = size(C,2); 13 | Cp = zeros(N,N); 14 | [S,Ind] = sort(abs(C),1,'descend'); 15 | for i = 1:N 16 | cL1 = sum(S(:,i)); 17 | stop = false; 18 | cSum = 0; t = 0; 19 | while (~stop) 20 | t = t + 1; 21 | cSum = cSum + S(t,i); 22 | if ( cSum >= ro*cL1 ) 23 | stop = true; 24 | Cp(Ind(1:t,i),i) = C(Ind(1:t,i),i); 25 | end 26 | end 27 | end 28 | else 29 | Cp = C; 30 | end -------------------------------------------------------------------------------- /2009 IJCV SCC/DataProjection.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the D x N data matrix with columns indicating 3 | % different data points and project the D dimensional data into a r 4 | % dimensional subspace using PCA. 5 | % X: D x N matrix of N data points 6 | % r: dimension of the PCA projection, if r = 0, then no projection 7 | % Xp: r x N matrix of N projectred data points 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Xp = DataProjection(X,r) 14 | 15 | if (nargin < 2) 16 | r = 0; 17 | end 18 | 19 | if (r == 0) 20 | Xp = X; 21 | else 22 | [U,~,~] = svd(X,0); 23 | Xp = U(:,1:r)' * X; 24 | end 25 | -------------------------------------------------------------------------------- /2009 IJCV SCC/computing_average_L2_error.m: -------------------------------------------------------------------------------- 1 | function mse = computing_average_L2_error(data, dim, idx, ctr, dir) 2 | 3 | N = size(data,1); 4 | 5 | K = max(idx); 6 | 7 | if length(dim) < K 8 | dim = dim(end)*ones(K,1); 9 | end 10 | 11 | if nargin<4 12 | [ctr,dir] = computing_centers_and_bases(data,idx,dim); 13 | end 14 | 15 | mse = 0; 16 | for k = 1:K 17 | cls_k = data((idx==k),:); 18 | n_k = size(cls_k,1); 19 | if n_k > dim(k) 20 | cls_k = cls_k - repmat(ctr{k,1},n_k,1); 21 | mse = mse + sum(sum(cls_k.^2,2) - sum((cls_k*dir{k,1}').^2,2)); 22 | end 23 | end 24 | 25 | mse = sqrt(mse/N); -------------------------------------------------------------------------------- /2009 IJCV SCC/computing_centers_and_bases.m: -------------------------------------------------------------------------------- 1 | function [ctr,dir,dims]= computing_centers_and_bases(data,inds,dims) 2 | 3 | %D = size(data,2); 4 | 5 | K = max(inds); 6 | 7 | if length(dims) == 1 && K>1 8 | dims = dims*ones(K,1); 9 | end 10 | 11 | % intialization 12 | ctr = cell(K,1); 13 | dir = cell(K,1); 14 | 15 | for k = 1:K 16 | 17 | cls_k = data((inds==k),:); 18 | n_k = size(cls_k,1); 19 | 20 | if n_k >= dims(k)+1 21 | 22 | ctr{k,1} = mean(cls_k,1); 23 | cls_k = cls_k - repmat(ctr{k,1},n_k,1); 24 | [uk,sk,vk] = svd(cls_k,0); 25 | 26 | dir{k,1} = vk(:,1:dims(k))'; 27 | 28 | end 29 | 30 | end -------------------------------------------------------------------------------- /2009 IJCV SCC/computing_percentage_of_misclassified_points.m: -------------------------------------------------------------------------------- 1 | function p = computing_percentage_of_misclassified_points(indices,trueLabels) 2 | 3 | [sortedLabels, inds_sort] = sort(trueLabels, 'ascend'); 4 | indices = indices(inds_sort); 5 | 6 | N = numel(trueLabels); 7 | K = sortedLabels(end); 8 | 9 | %if K == 1; p = 0; return; 10 | 11 | planeSizes = zeros(K,1); 12 | i = 1; ini = 1; 13 | for k = 1:K-1, 14 | while sortedLabels(i) == k; i = i+1; end; 15 | planeSizes(k) = i - ini; 16 | ini = i; 17 | end 18 | planeSizes(K) = N+1 - ini; 19 | 20 | num = zeros(K,K); 21 | for k = 1:K 22 | for j = 1:K 23 | num(k,j) = sum(indices(sum(planeSizes(1:k-1))+1:sum(planeSizes(1:k)))==j); 24 | end 25 | end 26 | 27 | p = 1-maximum_number_of_correctly_classified_points(num)/sum(planeSizes); 28 | 29 | %% 30 | 31 | function n = maximum_number_of_correctly_classified_points(num) 32 | 33 | K = size(num,1); 34 | 35 | if K > 2 36 | n = zeros(K,1); 37 | for j = 1:K 38 | n(j) = num(1,j)+maximum_number_of_correctly_classified_points(num(2:end,[1:j-1 j+1:K])); 39 | end 40 | n = max(n); 41 | else 42 | n = max(num(1,1)+num(2,2), num(1,2)+num(2,1)); 43 | end -------------------------------------------------------------------------------- /2009 IJCV SCC/computing_point_to_flat_distances.m: -------------------------------------------------------------------------------- 1 | function distancePoints2Flats = computing_point_to_flat_distances(X,centers,bases) 2 | 3 | [N,D] = size(X); 4 | K = length(centers); 5 | 6 | distancePoints2Flats = Inf(N, K); 7 | for k = 1:K 8 | 9 | if ~isempty(centers{k}) && ~isempty(bases{k}) 10 | 11 | X_centered = X - repmat(centers{k},N,1); 12 | distancePoints2Flats(:,k) = ... 13 | sum(X_centered.^2,2) - sum((X_centered*bases{k}').^2,2); 14 | %sum(((X - repmat(centers{k},N,1))*(eye(D) - bases{k}'*bases{k})).^2,2); 15 | end 16 | 17 | end -------------------------------------------------------------------------------- /2009 IJCV SCC/missclass.m: -------------------------------------------------------------------------------- 1 | function [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 2 | 3 | % [miss,index] = missclass(Segmentation,npoints,ngroups) 4 | % 5 | % Computes the number of missclassified points in the vector Segmentation. 6 | % 7 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 8 | % the label for each group, ranging from 1 to n 9 | 10 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 11 | % points in each group. 12 | 13 | % ngroups: number of groups 14 | 15 | Permutations = perms(1:ngroups); 16 | if(size(Segmentation,2)==1) 17 | Segmentation=Segmentation'; 18 | end 19 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 20 | for k=1:size(Segmentation,1) 21 | for j=1:size(Permutations,1) 22 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 23 | end 24 | end 25 | 26 | [miss,temp] = min(miss,[],1); 27 | index = Permutations(temp,:); -------------------------------------------------------------------------------- /2009 IJCV SCC/readme.txt: -------------------------------------------------------------------------------- 1 | This toolbox contains the Matlab implementation of the Spectral Curvature Clustering algorithm 2 | (by Guangliang Chen and Gilad Lerman, IJCV 2009). 3 | 4 | The main files are scc.m and lscc.m (the rest are supporting files). 5 | The former (scc) can be applied to segment general affine subspaces (including linear subspaces), 6 | while the latter (lscc) is restricted to linear subspaces. 7 | 8 | The simplest way to use them is as follows: 9 | 10 | [sampleLabels, averageL2Error] = scc(X,d,K); 11 | [sampleLabels, averageL2Error] = lscc(X,d,K). 12 | 13 | where, 14 | 15 | X: N-by-D data matrix 16 | d: intrinsic dimension 17 | K: number of clusters 18 | 19 | sampleLabels: cluster labels of the data points 20 | averageL2Error: averaged L2 error of the detected clusters. 21 | 22 | For more detailed description, as well as choices of optional parameters, 23 | please type in the Matlab command window 24 | 25 | help scc 26 | 27 | If you have any questions please email Guangliang Chen at glchen@math.duke.edu 28 | or Gilad Lerman at lerman@umn.edu. -------------------------------------------------------------------------------- /2009 IJCV SCC/run_SCC_Faces.m: -------------------------------------------------------------------------------- 1 | clear, close,clc; 2 | 3 | load 'YaleBCrop025.mat'; 4 | 5 | nSet = [2 3 4 5 6 7 8 9 10]; 6 | for i = 1:length(nSet) 7 | n = nSet(i); 8 | idx = Ind{n}; 9 | disp(['Clustering ' num2str(n) ' faces!']); 10 | for trial = 1:1:100 11 | disp([' The ' num2str(trial) 'th trial!']); 12 | for j = 1: size(idx,1) 13 | X = []; 14 | for p = 1:n 15 | X = [X Y(:,:,idx(j,p))]; 16 | end 17 | [D,N] = size(X); 18 | 19 | X = X'; 20 | 21 | k = 3; % scc 3;lssc 4, dimension of subspaces 22 | [sampleLabels, averageL2Error] = scc(X,k,n); 23 | %[sampleLabels, averageL2Error] = lscc(X,k,n); 24 | 25 | 26 | % compute misclassification rate 27 | missrate=missclass(sampleLabels,s{n},n)/length(s{n}); 28 | disp(['Missclassification error: ' num2str(missrate*100) '%']);% averageL2Error 29 | 30 | missrateTot{trial,n}(j) = missrate; 31 | end 32 | avgmissrate(trial,n) = mean(missrateTot{trial,n}); 33 | medmissrate(trial,n) = median(missrateTot{trial,n}); 34 | end 35 | allavgmissrate(n) = mean(avgmissrate(:,n)); 36 | allmedmissrate(n) = median(medmissrate(:,n)); 37 | save SCC_Faces.mat missrateTot avgmissrate medmissrate 38 | end 39 | save SCC_Faces.mat missrateTot avgmissrate medmissrate allavgmissrate allmedmissrate -------------------------------------------------------------------------------- /2009 IJCV SCC/sampling_columns.m: -------------------------------------------------------------------------------- 1 | function inds = sampling_columns(sampleLabels,K,opts) 2 | 3 | %K = max(sampleLabels); % number of clusters 4 | %inliers = find(sampleLabels>0); % remove outliers 5 | 6 | c_ave = opts.c/K; 7 | 8 | inds = zeros(opts.n-1,opts.c); 9 | for k = 1:K 10 | 11 | % indices of points in cluster k and its size 12 | inds_k = find(sampleLabels == k); 13 | n_k = length(inds_k); 14 | 15 | if n_k < opts.n-1 % not enough points in cluster k 16 | inds_k = find(sampleLabels>0); 17 | end 18 | 19 | % sample c_ave columns from cluster k 20 | for col = ((k-1)*c_ave+1):(k*c_ave) 21 | inds(:,col) = randsample(inds_k,opts.n-1); 22 | end 23 | 24 | end 25 | 26 | % for col = (K*c_ave+1):opts.c 27 | % inds(:,col) = randsample(inliers,opts.n-1); 28 | % end -------------------------------------------------------------------------------- /2010 ICML 2013 PAMI LRR/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx,gnd) 2 | %inputs: 3 | % idx -- the clustering results 4 | % gnd -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | if size(idx,2)>1 8 | idx = idx'; 9 | end 10 | if size(gnd,2)>1 11 | gnd = gnd'; 12 | end 13 | 14 | uids = unique(idx); 15 | nbc = length(uids); 16 | n = length(idx); 17 | %% generate the cost matrix 18 | C = zeros(nbc); 19 | for i=1:nbc 20 | uid = uids(i); 21 | inds = abs(idx-uid)<0.1; 22 | for j=1:nbc 23 | ypred = zeros(n,1); 24 | ypred(inds) = j; 25 | C(i,j) = 1 - sum(abs(gnd-ypred)<0.1)/n; 26 | end 27 | end 28 | %% run the Hugarian algorithm 29 | M = Hungarian(C); 30 | ypred = zeros(n,1); 31 | for i=1:nbc 32 | inds = abs(idx-i)<0.1; 33 | ypred(inds) = find(M(i,:)); 34 | end 35 | acc = sum(abs(ypred-gnd)<0.1)/n; -------------------------------------------------------------------------------- /2010 ICML 2013 PAMI LRR/loadmatfile.m: -------------------------------------------------------------------------------- 1 | function [data] = loadmatfile(path) 2 | %LOADMATFILE Summary of this function goes here 3 | % Detailed explanation goes here 4 | data = load(path); 5 | data = data.obj; -------------------------------------------------------------------------------- /2010 ICML 2013 PAMI LRR/lrr_face_seg.m: -------------------------------------------------------------------------------- 1 | function [] = lrr_face_seg() 2 | data = loadmatfile('yaleb10.mat'); 3 | X = data.X; 4 | gnd = data.cids; 5 | K = max(gnd); 6 | tic; 7 | %run lrr 8 | Z = solve_lrr(X,0.18); 9 | 10 | %post processing 11 | [U,S,V] = svd(Z,'econ'); 12 | S = diag(S); 13 | r = sum(S>1e-4*S(1)); 14 | U = U(:,1:r);S = S(1:r); 15 | U = U*diag(sqrt(S)); 16 | U = normr(U); 17 | L = (U*U').^4; 18 | 19 | % spectral clustering 20 | D = diag(1./sqrt(sum(L,2))); 21 | L = D*L*D; 22 | [U,S,V] = svd(L); 23 | V = U(:,1:K); 24 | V = D*V; 25 | 26 | n = size(V,1); 27 | M = zeros(K,K,20); 28 | rand('state',123456789); 29 | for i=1:size(M,3) 30 | inds = false(n,1); 31 | while sum(inds)0.1); 26 | end 27 | end 28 | 29 | [miss,temp] = min(miss,[],1); 30 | index = Permutations(temp,:); 31 | -------------------------------------------------------------------------------- /2010 ICML 2013 PAMI LRR/solve_lrr.m: -------------------------------------------------------------------------------- 1 | function [Z,E] = solve_lrr(X,lambda) 2 | Q = orth(X'); 3 | A = X*Q; 4 | [Z,E] = lrra(X,A,lambda); 5 | Z = Q*Z; -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/BuildAdjacency.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes a NxN coefficient matrix and returns a NxN adjacency 3 | % matrix by choosing the K strongest connections in the similarity graph 4 | % CMat: NxN coefficient matrix 5 | % K: number of strongest edges to keep; if K=0 use all the exiting edges 6 | % CKSym: NxN symmetric adjacency matrix 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | 12 | function [CKSym,CAbs] = BuildAdjacency(CMat,K) 13 | 14 | if (nargin < 2) 15 | K = 0; 16 | end 17 | 18 | N = size(CMat,1); 19 | CAbs = abs(CMat); 20 | 21 | [Srt,Ind] = sort( CAbs,1,'descend' ); 22 | 23 | if (K == 0) 24 | for i = 1:N 25 | CAbs(:,i) = CAbs(:,i) ./ (CAbs(Ind(1,i),i)+eps); 26 | end 27 | else 28 | for i = 1:N 29 | for j = 1:K 30 | CAbs(Ind(j,i),i) = CAbs(Ind(j,i),i) ./ (CAbs(Ind(1,i),i)+eps); 31 | end 32 | end 33 | end 34 | 35 | CKSym = CAbs + CAbs'; -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/DataProjection.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the D x N data matrix with columns indicating 3 | % different data points and project the D dimensional data into a r 4 | % dimensional subspace using PCA. 5 | % X: D x N matrix of N data points 6 | % r: dimension of the PCA projection, if r = 0, then no projection 7 | % Xp: r x N matrix of N projectred data points 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Xp = DataProjection(X,r) 14 | 15 | if (nargin < 2) 16 | r = 0; 17 | end 18 | 19 | if (r == 0) 20 | Xp = X; 21 | else 22 | [U,~,~] = svd(X,0); 23 | Xp = U(:,1:r)' * X; 24 | end 25 | -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/Misclassification.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the groups resulted from spectral clutsering and the 3 | % ground truth to compute the misclassification rate. 4 | % groups: [grp1,grp2,grp3] for three different forms of Spectral Clustering 5 | % s: ground truth vector 6 | % Missrate: 3x1 vector with misclassification rates of three forms of 7 | % spectral clustering 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Missrate = Misclassification(groups,s) 14 | 15 | n = max(s); 16 | for i = 1:size(groups,2) 17 | Missrate(i,1) = missclassGroups( groups(:,i),s,n ) ./ length(s); 18 | end -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/SpectralClustering.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes an adjacency matrix of a graph and computes the 3 | % clustering of the nodes using the spectral clustering algorithm of 4 | % Ng, Jordan and Weiss. 5 | % CMat: NxN adjacency matrix 6 | % n: number of groups for clustering 7 | % groups: N-dimensional vector containing the memberships of the N points 8 | % to the n groups obtained by spectral clustering 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2012 11 | %-------------------------------------------------------------------------- 12 | 13 | function groups = SpectralClustering(CKSym,n) 14 | 15 | warning off; 16 | N = size(CKSym,1); 17 | MAXiter = 1000; % Maximum number of iterations for KMeans 18 | REPlic = 20; % Number of replications for KMeans 19 | 20 | % Normalized spectral clustering according to Ng & Jordan & Weiss 21 | % using Normalized Symmetric Laplacian L = I - D^{-1/2} W D^{-1/2} 22 | 23 | DN = diag( 1./sqrt(sum(CKSym)+eps) ); 24 | LapN = speye(N) - DN * CKSym * DN; 25 | [uN,sN,vN] = svd(LapN); 26 | kerN = vN(:,N-n+1:N); 27 | for i = 1:N 28 | kerNS(i,:) = kerN(i,:) ./ norm(kerN(i,:)+eps); 29 | end 30 | groups = kmeans(kerNS,n,'maxiter',MAXiter,'replicates',REPlic,'EmptyAction','singleton'); -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/cnormalize.m: -------------------------------------------------------------------------------- 1 | function [xn,normx] = cnormalize(x) 2 | [K,N] = size(x); 3 | normx = sqrt(sum(conj(x).*x,1)); 4 | xn = x ./ (ones(K,1)*normx); 5 | -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/lrsc.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This is the function to call the sparse optimization program, to call the 3 | % spectral clustering algorithm and to compute the clustering error. 4 | % r = projection dimension, if r = 0, then no projection 5 | % affine = use the affine constraint if true 6 | % s = clustering ground-truth 7 | % missrate = clustering error 8 | % CMat = coefficient matrix obtained by SSC 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Jun Xu, 2012 11 | %-------------------------------------------------------------------------- 12 | 13 | function [LRSC_missrate,C] = lrsc(X,tau,r,outlier,rho,s) 14 | 15 | if (nargin < 5) 16 | rho = 1; 17 | end 18 | if (nargin < 4) 19 | outlier = false; 20 | end 21 | if (nargin < 3) 22 | r = 0; 23 | end 24 | if (nargin < 2) 25 | tau = 100/norm(D)^2; 26 | alpha = 0.5*tau; 27 | end 28 | 29 | n = max(s); 30 | Xp = DataProjection(X,r); 31 | 32 | if (~outlier) 33 | %Cp = lrsc_noiseless(Xp,tau); 34 | [A,Cp] = lrsc_noisy(Xp,tau); 35 | else 36 | [Cp,A,E] = lrsc_outliersrelax(Xp,tau,alpha,gamma); 37 | end 38 | 39 | C = BuildAdjacency(thrC(Cp,rho)); 40 | groups = SpectralClustering(C,n); 41 | %compute misclassification rate 42 | LRSC_missrate = Misclassification(groups,s); -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/lrsc_noiseless.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % C = lrsc(A,tau) 3 | % Low Rank Subspace Clustering algorithm for noiseless data lying in a 4 | % union of subspaces 5 | % 6 | % C = argmin |C|_* + tau/2 * |A - AC|_F^2 s.t. C = C' 7 | % 8 | % A: clean data matrix whose columns are points in a union of subspaces 9 | % tau: scalar parameter 10 | %-------------------------------------------------------------------------- 11 | % Copyright @ Rene Vidal, November 2012 12 | %-------------------------------------------------------------------------- 13 | 14 | function C = lrsc_noiseless(A,tau) 15 | 16 | if nargin < 2 17 | tau = 100/norm(A)^2; 18 | end 19 | 20 | [~,S,V] = svd(A,0); 21 | lambda = diag(S); 22 | r = max(sum(lambda > 1/sqrt(tau)),1); 23 | C = V(:,1:r) * (eye(r) - diag(1./(lambda(1:r).^2)/tau)) * V(:,1:r)'; 24 | 25 | -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/lrsc_noisy.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % [C,A] = lrsc_noisy(D,tau,alpha,useSampledPolynoimial) 3 | % Low Rank Subspace Clustering algorithm for noisy data lying in a 4 | % union of subspaces 5 | % 6 | % (C,A) = argmin |C|_* + tau/2*|A - AC|_F^2 + alpha/2*|D - A|_F^2 s.t. C = C' 7 | % 8 | % C = affinity matrix 9 | % A = clean data matrix whose columns are points in a union of subspaces 10 | % D = noisy data matrix whose columns are points in a union of subspaces 11 | % tau = scalar parameter 12 | % alpha = scalar parameter 13 | % useSampledPolynomial = when a 4th argument is passed, the code used 14 | % a discretization of the polynomial thresholding 15 | % function 16 | %-------------------------------------------------------------------------- 17 | % Copyright @ Rene Vidal, November 2012 18 | % Edited by Paolo Favaro, December 2012 19 | %-------------------------------------------------------------------------- 20 | 21 | function [A,C] = lrsc_noisy(D,tau,alpha,~) 22 | 23 | if nargin < 3 24 | alpha = 0.5*tau; 25 | end 26 | if nargin < 2 27 | tau = 100/norm(D)^2; 28 | alpha = 0.5*tau; 29 | end 30 | 31 | if nargin<=3 32 | [A,C] = polythreshCF(D,tau,alpha); 33 | else 34 | [A,C] = polythreshAP(D,tau,alpha); 35 | end -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/missclassGroups.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 3 | % Computes the number of missclassified points in the vector Segmentation. 4 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 5 | % the label for each group, ranging from 1 to n 6 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 7 | % points in each group. 8 | % ngroups: number of groups 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2012 11 | %-------------------------------------------------------------------------- 12 | 13 | 14 | function [miss,index] = missclassGroups(Segmentation,RefSegmentation,ngroups) 15 | 16 | Permutations = perms(1:ngroups); 17 | if(size(Segmentation,2)==1) 18 | Segmentation=Segmentation'; 19 | end 20 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 21 | for k=1:size(Segmentation,1) 22 | for j=1:size(Permutations,1) 23 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 24 | end 25 | end 26 | 27 | [miss,temp] = min(miss,[],1); 28 | index = Permutations(temp,:); 29 | -------------------------------------------------------------------------------- /2011 CVPR 2014 PRL LRSC/thrC.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % Copyright @ Ehsan Elhamifar, 2012 3 | %-------------------------------------------------------------------------- 4 | 5 | function Cp = thrC(C,ro) 6 | 7 | if (nargin < 2) 8 | ro = 1; 9 | end 10 | 11 | if (ro < 1) 12 | N = size(C,2); 13 | Cp = zeros(N,N); 14 | [S,Ind] = sort(abs(C),1,'descend'); 15 | for i = 1:N 16 | cL1 = sum(S(:,i)); 17 | stop = false; 18 | cSum = 0; t = 0; 19 | while (~stop) 20 | t = t + 1; 21 | cSum = cSum + S(t,i); 22 | if ( cSum >= ro*cL1 ) 23 | stop = true; 24 | Cp(Ind(1:t,i),i) = C(Ind(1:t,i),i); 25 | end 26 | end 27 | end 28 | else 29 | Cp = C; 30 | end -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/Data/YaleB.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2012 ECCV LSR/LSR_FS/Data/YaleB.mat -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/LSR/LSR1.m: -------------------------------------------------------------------------------- 1 | function Z = LSR1( X , lambda ) 2 | 3 | %-------------------------------------------------------------------------- 4 | % Copyright @ Can-Yi Lu, 2012 5 | %-------------------------------------------------------------------------- 6 | 7 | % Input 8 | % X Data matrix, dim * num 9 | % lambda parameter, lambda>0 10 | 11 | 12 | % Output the solution to the following problem: 13 | % min ||X-XZ||_F^2+lambda||Z||_F^2 14 | % s.t. diag(Z)=0 15 | 16 | % Z num * num 17 | 18 | if nargin < 2 19 | lambda = 0.001 ; 20 | end 21 | [dim,num] = size(X) ; 22 | 23 | 24 | % for i = 1 : num 25 | % X(:,i) = X(:,i) / norm(X(:,i)) ; 26 | % end 27 | 28 | 29 | I = eye(num) ; 30 | invX = I / (X'*X+lambda*I) ; 31 | Z = zeros( num , num ) ; 32 | for i = 1 : num 33 | Z(:,i) = invX(:,i) / invX(i,i) ; 34 | Z(i,i) = 0 ; 35 | end 36 | Z = -1 * Z ; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/LSR/LSR2.m: -------------------------------------------------------------------------------- 1 | function Z = LSR2( X , lambda ) 2 | 3 | %-------------------------------------------------------------------------- 4 | % Copyright @ Can-Yi Lu, 2012 5 | %-------------------------------------------------------------------------- 6 | 7 | % Input 8 | % X Data matrix, dim * num 9 | % lambda parameter, lambda>0 10 | 11 | 12 | % Output the solution to the following problem: 13 | % min ||X-XZ||_F^2+lambda||Z||_F^2 14 | 15 | % Z num * num 16 | 17 | 18 | if nargin < 2 19 | lambda = 0.004 ; 20 | end 21 | [dim,num] = size(X) ; 22 | 23 | 24 | % for i = 1 : num 25 | % X(:,i) = X(:,i) / norm(X(:,i)) ; 26 | % end 27 | 28 | 29 | I = lambda * eye(num) ; 30 | Z = (X'*X+I) \ X' * X ; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/SubspaceSegmentation.m: -------------------------------------------------------------------------------- 1 | function acc = SubspaceSegmentation( SegmentatiomMethod , X , gnd , para ) 2 | 3 | switch SegmentatiomMethod 4 | 5 | case 'LSR1' 6 | L = LSR1( X , para ) ; 7 | 8 | case 'LSR2' 9 | L = LSR2( X , para ) ; 10 | end 11 | 12 | 13 | for i = 1 : size(L,2) 14 | L(:,i) = L(:,i) / max(abs(L(:,i))) ; 15 | end 16 | 17 | nCluster = length( unique( gnd ) ) ; 18 | Z = ( abs(L) + abs(L') ) / 2 ; 19 | idx = clu_ncut(Z,nCluster) ; 20 | acc = compacc(idx,gnd) ; 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | % for i = 1 : size(L,2) 45 | % Z(:,i) = Z(:,i) / max(max(Z)) ; 46 | % end 47 | % % Z(Z>0.01) = 1 ; 48 | % imshow(1-Z) 49 | 50 | 51 | 52 | % figure 53 | % for i = 1 : size(L,2) 54 | % L(:,i) = L(:,i) / max(L(:,i)) ; 55 | % end 56 | % imshow(1-L) 57 | 58 | 59 | -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/clu_ncut.m: -------------------------------------------------------------------------------- 1 | function [idx] = clu_ncut(L,K) 2 | % this routine groups the data X into K subspaces by NCut 3 | % inputs: 4 | % L -- an N*N affinity matrix, N is the number of data points 5 | % K -- the number of subpaces (i.e., clusters) 6 | L = (L + L')/2; 7 | D = diag(1./sqrt(sum(L,2))); 8 | L = D*L*D; 9 | [U,S,V] = svd(L); 10 | 11 | V = U(:,1:K); 12 | V = D*V; 13 | 14 | idx = kmeans(V,K,'emptyaction','singleton','replicates',10,'display','off'); 15 | idx = idx'; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx1,idx0) 2 | %inputs: 3 | % idx1 -- the clustering results 4 | % idx0 -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | uids = unique(idx1); 8 | idx = idx1; 9 | for i=1:length(uids) 10 | uid = uids(i); 11 | inds = abs(idx1-uid)<0.1; 12 | vids = idx0(inds); 13 | uvids = unique(vids); 14 | vf = 0; 15 | for j=1:length(uvids) 16 | vfj = sum(abs(vids-uvids(j))<0.1); 17 | if vfj>vf; 18 | vid = uvids(j); 19 | vf = vfj; 20 | end 21 | end 22 | idx(inds) = vid; 23 | end 24 | acc = sum(abs(idx-idx0)<0.1)/length(idx0); -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_FS/read me.txt: -------------------------------------------------------------------------------- 1 | Copyright @Can-Yi Lu, 2012 2 | 3 | This code is about the Least Squares Regression (LSR) method for subspace segmentation for our work: 4 | Can-Yi Lu, Hai Min, Zhong-Qiu Zhao, Lin Zhu, De-Shuang Huang and Shuicheng Yan. Robust and Efficient Subspace Segmentation via Least Squares Regression, European Conference on Computer Vision (ECCV), 2012. 5 | 6 | The code is provided for research purposes only. 7 | 8 | For face clustering on the Extended Yale B database, run Experiment_YaleB.m directly! 9 | 10 | Please contact Can-Yi Lu (canyilu@gmail.com) for questions about the code. 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/LSR/LSR1.m: -------------------------------------------------------------------------------- 1 | function Coeff = LSR1( X , lambda ) 2 | 3 | %-------------------------------------------------------------------------- 4 | % Copyright @ Can-Yi Lu, 2012 5 | %-------------------------------------------------------------------------- 6 | 7 | % Input 8 | % X Data matrix, dim * num 9 | % lambda parameter, lambda>0 10 | 11 | 12 | % Output the solution to the following problem: 13 | % min ||X-XZ||_F^2+lambda||Z||_F^2 14 | % s.t. diag(Z)=0 15 | 16 | % Z num * num 17 | 18 | if nargin < 2 19 | lambda = 0.001 ; 20 | end 21 | [dim,num] = size(X) ; 22 | 23 | 24 | % for i = 1 : num 25 | % X(:,i) = X(:,i) / norm(X(:,i)) ; 26 | % end 27 | 28 | 29 | I = eye(num) ; 30 | invX = I / (X'*X+lambda*I) ; 31 | Coeff = zeros( num , num ) ; 32 | for i = 1 : num 33 | Coeff(:,i) = invX(:,i) / invX(i,i) ; 34 | Coeff(i,i) = 0 ; 35 | end 36 | Coeff = -1 * Coeff ; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/LSR/LSR2.m: -------------------------------------------------------------------------------- 1 | function Z = LSR2( X , lambda ) 2 | 3 | %-------------------------------------------------------------------------- 4 | % Copyright @ Can-Yi Lu, 2012 5 | %-------------------------------------------------------------------------- 6 | 7 | % Input 8 | % X Data matrix, dim * num 9 | % lambda parameter, lambda>0 10 | 11 | 12 | % Output the solution to the following problem: 13 | % min ||X-XZ||_F^2+lambda||Z||_F^2 14 | 15 | % Z num * num 16 | 17 | 18 | if nargin < 2 19 | lambda = 0.004 ; 20 | end 21 | [dim,num] = size(X) ; 22 | 23 | 24 | % for i = 1 : num 25 | % X(:,i) = X(:,i) / norm(X(:,i)) ; 26 | % end 27 | 28 | 29 | I = lambda * eye(num) ; 30 | Z = (X'*X+I) \ X' * X ; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/SubspaceSegmentation.m: -------------------------------------------------------------------------------- 1 | function acc = SubspaceSegmentation( SegmentatiomMethod , X , gnd , para ) 2 | 3 | switch SegmentatiomMethod 4 | 5 | case 'LSR1' 6 | L = LSR1( X , para ) ; 7 | 8 | case 'LSR2' 9 | L = LSR2( X , para ) ; 10 | end 11 | 12 | nCluster = length( unique( gnd ) ) ; 13 | Z = ( abs(L) + abs(L') ) / 2 ; 14 | idx = clu_ncut(Z,nCluster) ; 15 | acc = compacc(idx,gnd) ; 16 | -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/clu_ncut.m: -------------------------------------------------------------------------------- 1 | function [idx] = clu_ncut(L,K) 2 | % this routine groups the data X into K subspaces by NCut 3 | % inputs: 4 | % L -- an N*N affinity matrix, N is the number of data points 5 | % K -- the number of subpaces (i.e., clusters) 6 | L = (L + L')/2; 7 | D = diag(1./sqrt(sum(L,2))); 8 | L = D*L*D; 9 | [U,S,V] = svd(L); 10 | 11 | V = U(:,1:K); 12 | V = D*V; 13 | 14 | idx = kmeans(V,K,'emptyaction','singleton','replicates',10,'display','off'); 15 | idx = idx'; -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx1,idx0) 2 | %inputs: 3 | % idx1 -- the clustering results 4 | % idx0 -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | uids = unique(idx1); 8 | idx = idx1; 9 | for i=1:length(uids) 10 | uid = uids(i); 11 | inds = abs(idx1-uid)<0.1; 12 | vids = idx0(inds); 13 | uvids = unique(vids); 14 | vf = 0; 15 | for j=1:length(uvids) 16 | vfj = sum(abs(vids-uvids(j))<0.1); 17 | if vfj>vf; 18 | vid = uvids(j); 19 | vf = vfj; 20 | end 21 | end 22 | idx(inds) = vid; 23 | end 24 | acc = sum(abs(idx-idx0)<0.1)/length(idx0); -------------------------------------------------------------------------------- /2012 ECCV LSR/LSR_MS/read me.txt: -------------------------------------------------------------------------------- 1 | Copyright @Can-Yi Lu, 2012 2 | 3 | This code is about the Least Squares Regression (LSR) method for subspace segmentation for our work: 4 | Can-Yi Lu, Hai Min, Zhong-Qiu Zhao, Lin Zhu, De-Shuang Huang and Shuicheng Yan. Robust and Efficient Subspace Segmentation via Least Squares Regression, European Conference on Computer Vision (ECCV), 2012. 5 | 6 | The code is provided for research purposes only. 7 | 8 | For motion segmentation on the Hopkins 155 database, one should first download the motion data from http://www.vision.jhu.edu/data/hopkins155/, and release the data in the .\Data subfolder. Then run Experiment_MS.m directly! 9 | 10 | Please contact Can-Yi Lu (canyilu@gmail.com) for questions about the code. 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /2014 CVPR SMR/bestMap.m: -------------------------------------------------------------------------------- 1 | function [newL2, c] = bestMap(L1,L2) 2 | %bestmap: permute labels of L2 match L1 as good as possible 3 | % [newL2] = bestMap(L1,L2); 4 | 5 | %=========== 6 | L1 = L1(:); 7 | L2 = L2(:); 8 | if size(L1) ~= size(L2) 9 | error('size(L1) must == size(L2)'); 10 | end 11 | L1 = L1 - min(L1) + 1; % min (L1) <- 1; 12 | L2 = L2 - min(L2) + 1; % min (L2) <- 1; 13 | %=========== make bipartition graph ============ 14 | nClass = max(max(L1), max(L2)); 15 | G = zeros(nClass); 16 | for i=1:nClass 17 | for j=1:nClass 18 | G(i,j) = length(find(L1 == i & L2 == j)); 19 | end 20 | end 21 | %=========== assign with hungarian method ====== 22 | [c,t] = hungarian(-G); 23 | newL2 = zeros(nClass,1); 24 | for i=1:nClass 25 | newL2(L2 == i) = c(i); 26 | end -------------------------------------------------------------------------------- /2014 CVPR SMR/clu_ncut.m: -------------------------------------------------------------------------------- 1 | function [idx,DistC,U,S] = clu_ncut(W,K) 2 | % this routine groups the data X into K subspaces by NCut 3 | % inputs: 4 | % W -- an N*N affinity matrix, N is the number of data points 5 | % K -- the number of subpaces (i.e., clusters) 6 | 7 | n = size(W,1); 8 | W(1:n+1:end) = 0; 9 | W = (W + W')/2; 10 | D = diag(1./(sqrt(sum(W,2))+eps)); 11 | LMat = eye(size(W))-D*W*D; 12 | opts.tol = 1e-8; 13 | opts.maxit = 30000; 14 | [V,S]=eigs(LMat,K,'sr',opts); 15 | 16 | U = V(:,1:K); 17 | U = D*U; 18 | 19 | [idx,~,~,DistC] = kmeans(U,K,'emptyaction','singleton','replicates',100,'display','off'); 20 | idx = idx'; 21 | -------------------------------------------------------------------------------- /2014 CVPR SMR/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx1,idx0) 2 | %inputs: 3 | % idx1 -- the clustering results 4 | % idx0 -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | uids = unique(idx1); 8 | idx = idx1; 9 | for i=1:length(uids) 10 | uid = uids(i); 11 | inds = abs(idx1-uid)<0.1; 12 | vids = idx0(inds); 13 | uvids = unique(vids); 14 | vf = 0; 15 | for j=1:length(uvids) 16 | vfj = sum(abs(vids-uvids(j))<0.1); 17 | if vfj>vf; 18 | vid = uvids(j); 19 | vf = vfj; 20 | end 21 | end 22 | idx(inds) = vid; 23 | end 24 | acc = sum(abs(idx-idx0)<0.1)/length(idx0); -------------------------------------------------------------------------------- /2014 CVPR SMR/compacc_ce.m: -------------------------------------------------------------------------------- 1 | function [err,idx_wrong] = compacc_ce(idx,gnd) 2 | 3 | % This function computes clustering error (CE) 4 | 5 | gnd = compress_labels(gnd); 6 | idx = compress_labels(idx); 7 | 8 | [res_lgc, temp] = bestMap(gnd,idx); 9 | if size(res_lgc,1)~=size(gnd,1) 10 | gnd = gnd'; 11 | end 12 | idx_wrong = find(gnd ~= res_lgc); 13 | acc = 1-length(idx_wrong)/length(gnd); 14 | 15 | err = 1-acc; 16 | 17 | 18 | function [gnd_dst,igids] = compress_labels(gnd) 19 | 20 | gids = unique(gnd)+1; 21 | igids = zeros(1,max(gids)); 22 | for i=1:length(gids) 23 | igids(gids(i)) = i; 24 | end 25 | 26 | gnd_dst = igids(gnd+1); 27 | -------------------------------------------------------------------------------- /2014 CVPR SMR/data/YaleB/yaleB10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2014 CVPR SMR/data/YaleB/yaleB10.mat -------------------------------------------------------------------------------- /2014 CVPR SMR/data/usps/usps_part.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2014 CVPR SMR/data/usps/usps_part.mat -------------------------------------------------------------------------------- /2014 CVPR SMR/demo_usps_smr.m: -------------------------------------------------------------------------------- 1 | warning off all 2 | data_dir = './data/usps'; 3 | addpath(genpath(data_dir)); 4 | load usps_part.mat 5 | exp_name = 'HandwrittenDigit'; 6 | data = fea'; 7 | 8 | para.knn = 4; 9 | para.gamma = 5; 10 | para.elpson = 0.001; 11 | para.alpha = 2.^-16; 12 | 13 | para.aff_type = 'J1'; 14 | 15 | W = smr(data,para); 16 | W2 = W; 17 | for ic = 1 : size(W,2) 18 | W2(:,ic) = W(:,ic) / (max(abs(W(:,ic)))+eps) ; 19 | end 20 | [groups] = clu_ncut(W2,max(gnd)); 21 | ce = compacc_ce(groups,gnd) 22 | 23 | -------------------------------------------------------------------------------- /2014 CVPR SMR/get_nn_graph.m: -------------------------------------------------------------------------------- 1 | function [pairs,wcost,numpairs]=get_nn_graph(Xp,knn) 2 | 3 | [~,P] = size(Xp); 4 | neighborPoints =knn; 5 | 6 | distMin = squareform(pdist(Xp')); 7 | 8 | 9 | [minT,midx] = sort(distMin,'ascend'); 10 | neighMat = zeros(P,P); 11 | for pp = 1:P 12 | neighMat(midx(1:neighborPoints,pp),pp) = 1; 13 | neighMat(pp,midx(1:neighborPoints,pp)) = 1; 14 | end 15 | 16 | neighMat = tril(neighMat,-1); 17 | 18 | [nzidx] = find(neighMat>0); 19 | [nzr,nzc] = ind2sub(size(neighMat),nzidx); 20 | pairs = [nzr nzc]'-1; 21 | 22 | numpairs = length(nzidx); 23 | 24 | wcost = ones(length(nzidx),1); 25 | -------------------------------------------------------------------------------- /2014 CVPR SMR/hungarian.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2014 CVPR SMR/hungarian.m -------------------------------------------------------------------------------- /2014 CVPR SMR/readme.txt: -------------------------------------------------------------------------------- 1 | The hopkins155 dataset can be downloaded from http://vision.jhu.edu/data/fetchdata.php?id=1 2 | 3 | The codes implement the SMR algorithm presented in the following paper: 4 | 5 | @inproceedings{CVPR14/HuLFZ, 6 | author = {Han Hu and Zhouchen Lin 7 | Jianjiang Feng and 8 | Jie Zhou}, 9 | title = {Smooth Representation Clustering}, 10 | booktitle = {CVPR}, 11 | year = {2014} 12 | } -------------------------------------------------------------------------------- /2014 CVPR SMR/smr.m: -------------------------------------------------------------------------------- 1 | function [L] = smr(X,para) 2 | %This routine solves the smooth representation problem with fro-norm data term 3 | % 4 | alpha = para.alpha; 5 | gamma = para.gamma; 6 | 7 | [d,n] =size(X); 8 | [pairs,wcost,numpairs]=get_nn_graph(X,para.knn); 9 | 10 | nX = sqrt(sum(X.^2)); 11 | 12 | R = zeros(n,numpairs); 13 | for i=1:numpairs 14 | R(pairs(1,i)+1,i) = wcost(i); 15 | R(pairs(2,i)+1,i) = -wcost(i); 16 | end 17 | 18 | R = R/(para.knn-1); 19 | 20 | xtx = X'*X; 21 | rtr = 0.5*R*R'; 22 | % elpson = 0.01; 23 | A = alpha*xtx; 24 | B = rtr+para.elpson*eye(size(xtx)); 25 | C = -alpha*xtx; 26 | J = lyap(A,B,C); 27 | if strcmp(para.aff_type,'J1') 28 | L =(abs(J)+abs(J'))/2; 29 | elseif strcmp(para.aff_type,'J2') 30 | L=abs(J'*J./(nX'*nX)).^gamma; 31 | elseif strcmp(para.aff_type,'J2_nonorm') 32 | L=abs(J'*J).^gamma; 33 | end 34 | 35 | 36 | -------------------------------------------------------------------------------- /2015 CVPR MGR/BuildAdjacency.m: -------------------------------------------------------------------------------- 1 | %-Here, we thanks for Professor Ehsan Elhamifar 2 | % This function takes a NxN coefficient matrix and returns a NxN adjacency 3 | % matrix by choosing only the K strongest connections in the similarity 4 | % graph 5 | % CMat: NxN coefficient matrix 6 | % K: number of strongest edges to keep; if K=0 use all the coefficients 7 | % CKSym: NxN symmetric adjacency matrix 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2010 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function CKSym = BuildAdjacency(CMat,K) 14 | 15 | N = size(CMat,1); 16 | CAbs = abs(CMat); 17 | for i = 1:N 18 | c = CAbs(:,i); 19 | [PSrt,PInd] = sort(c,'descend'); 20 | CAbs(:,i) = CAbs(:,i) ./ abs( c(PInd(1)) ); 21 | end 22 | 23 | CSym = CAbs + CAbs'; 24 | 25 | if (K ~= 0) 26 | [Srt,Ind] = sort( CSym,1,'descend' ); 27 | CK = zeros(N,N); 28 | for i = 1:N 29 | for j = 1:K 30 | CK( Ind(j,i),i ) = CSym( Ind(j,i),i ) ./ CSym( Ind(1,i),i ); 31 | end 32 | end 33 | CKSym = CK + CK'; 34 | else 35 | CKSym = CSym; 36 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/Misclassification.m: -------------------------------------------------------------------------------- 1 | %-Here, we thanks for Professor Ehsan Elhamifar 2 | % This function takes the groups resulted from spectral clutsering and the 3 | % ground truth to compute the misclassification rate. 4 | % groups: [grp1,grp2,grp3] for three different forms of Spectral Clustering 5 | % s: ground truth vector 6 | % Missrate: 3x1 vector with misclassification rates of three forms of 7 | % spectral clustering 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2010 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Missrate = Misclassification(groups,s) 14 | 15 | n = max(s); 16 | for i = 1:3 17 | Missrate(i,1) = missclassGroups( groups(:,i),s,n ) ./ length(s); 18 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/Mltg.m: -------------------------------------------------------------------------------- 1 | % Calculating the Gaussian density function 2 | function [Pro] = Mltg(x,si) 3 | nsi = size(si,1); 4 | con = 1/sqrt(abs(det(si) + realmin)*(2*pi)^nsi); 5 | Pro = con*exp(-.5*x'*inv(si)*x); 6 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/OutlierDetection.m: -------------------------------------------------------------------------------- 1 | %-Here, we thanks for Professor Ehsan Elhamifar 2 | % This function takes the coefficient matrix resulted from sparse 3 | % representation using \ell_1 minimization. If a point cannot be written as 4 | % a linear combination of other points, it should be an outlier. The 5 | % function detects the indices of outliers and modifies the coefficient 6 | % matrix and the ground-truth accordingly. 7 | % CMat: NxN coefficient matrix 8 | % s: Nx1 ground-truth vector 9 | % CMatC: coefficient matrix after eliminating Nans 10 | % sc: ground-truth after eliminating outliers 11 | % OutlierIndx: indices of outliers in {1,2,...,N} 12 | % Fail: 1 if number of inliers is less than number of groups, 0 otherwise 13 | %-------------------------------------------------------------------------- 14 | % Copyright @ Ehsan Elhamifar, 2010 15 | %-------------------------------------------------------------------------- 16 | 17 | 18 | function [CMatC,sc,OutlierIndx,Fail] = OutlierDetection(CMat,s) 19 | 20 | n = max(s); 21 | N = size(CMat,2); 22 | NanIndx = []; 23 | FailCnt = 0; 24 | Fail = 0; 25 | 26 | for i = 1:N 27 | c = CMat(:,i); 28 | if( sum(isnan(c)) >= 1 ) 29 | NanIndx = [NanIndx ; i]; 30 | FailCnt = FailCnt + 1; 31 | end 32 | end 33 | 34 | sc = s; 35 | sc(NanIndx) = []; 36 | CMatC = CMat; 37 | CMatC(NanIndx,:) = []; 38 | CMatC(:,NanIndx) = []; 39 | OutlierIndx = NanIndx; 40 | 41 | if ( FailCnt > N - n ) 42 | CMatC = []; 43 | sc = []; 44 | Fail = 1; 45 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/Readme.txt: -------------------------------------------------------------------------------- 1 | This MATLAB code is for the clustering method published in the following paper: 2 | Baohua Li, Ying Zhang, Zhouchen Lin, and Huchuan Lu, Subspace Clustering by Mixture of Gaussian Regression, IEEE Conference on Computer Vision and Pattern Recognition (CVPR 2015). 3 | 4 | The main function is maincode.m. 5 | 6 | This is the second version of code. We appreciate any comments/suggestions. Feel free to ask us any questions, please contact us. 7 | 8 | -------------------------------------------------------------------------------- /2015 CVPR MGR/avoidze.m: -------------------------------------------------------------------------------- 1 | % Making the diagonal line of coefficient matrix equals to zeros. 2 | function [Ar] = avoidze(datam) 3 | [nda, mda] = size(datam); 4 | for j = 1 : mda 5 | Da = datam; 6 | datam(:,j) = 0; 7 | Ar(:,:,j) = datam; 8 | datam = Da; 9 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/clu_ncut.m: -------------------------------------------------------------------------------- 1 | function [idx] = clu_ncut(L,K) 2 | % this routine groups the data X into K subspaces by NCut 3 | % inputs: 4 | % L -- an N*N affinity matrix, N is the number of data points 5 | % K -- the number of subpaces (i.e., clusters) 6 | L = abs(L)+abs(L'); 7 | 8 | D = diag(sum(L,2).^(-1./2)); 9 | L = eye(size(L,1)) - D*L*D; 10 | [U,S,V] = svd(L); 11 | 12 | V = U(:,end-K+1:end); 13 | idx = kmeans(V,K,'emptyaction','singleton','replicates',10,'display','off'); 14 | idx = idx'; -------------------------------------------------------------------------------- /2015 CVPR MGR/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx1,idx0) 2 | %inputs: 3 | % idx1 -- the clustering results 4 | % idx0 -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | uids = unique(idx1); 8 | idx = idx1; 9 | for i=1:length(uids) 10 | uid = uids(i); 11 | inds = abs(idx1-uid)<0.1; 12 | vids = idx0(inds); 13 | uvids = unique(vids); 14 | vf = 0; 15 | for j=1:length(uvids) 16 | vfj = sum(abs(vids-uvids(j))<0.1); 17 | if vfj>vf; 18 | vid = uvids(j); 19 | vf = vfj; 20 | end 21 | end 22 | idx(inds) = vid; 23 | end 24 | acc = sum(abs(idx-idx0)<0.1)/length(idx0); -------------------------------------------------------------------------------- /2015 CVPR MGR/finalresulXn.m: -------------------------------------------------------------------------------- 1 | % find the nth column coefficient of matrix 2 | function[finalXn] = finalresulXn(frxdata,K,firwei,Sig,lam,n,X) 3 | xnl = size(frxdata,2); 4 | idlam = 2*lam*eye(xnl); 5 | [fxArgdat] = avoidze(frxdata); 6 | [fpartXn] = solvematrix(frxdata,K,firwei,Sig,n,X); 7 | finalXn = inv(fpartXn*fxArgdat(:,:,n) + idlam)*(fpartXn*frxdata(:,n)); 8 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/findcovj.m: -------------------------------------------------------------------------------- 1 | % find the qth covariance matrix 2 | function[Sigmq] = findcovj(fcodat,Sig,K,X,Weicov,q) 3 | [gamq] = gamij(fcodat,Sig,q,X,K,Weicov); 4 | covc = size(fcodat,2); 5 | Sigmq = 0; 6 | [Arfcodat] = avoidze(fcodat); 7 | for j = 1 : covc 8 | [Prosq] = Mltg(Arfcodat(:,:,j)*X(:,j)-fcodat(:,j),Sig(:,:,q)); 9 | [weisumq] = weightsumgaupdf(Sig,Weicov,Arfcodat(:,:,j)*X(:,j)-fcodat(:,j),K); 10 | Sigfenzi = Prosq*(Arfcodat(:,:,j)*X(:,j)-fcodat(:,j))*(Arfcodat(:,:,j)*X(:,j)-fcodat(:,j))'; 11 | Sigmq = Sigmq + Sigfenzi/weisumq; 12 | end 13 | Sigmq = (1/gamq)*Sigmq + 1E-5.*eye(size(Sigmq)) ; 14 | end% -------------------------------------------------------------------------------- /2015 CVPR MGR/gamij.m: -------------------------------------------------------------------------------- 1 | function [gaml] = gamij(gdat,Sig,l,X,K,Weig) 2 | gaml = 0; 3 | [rgdat, cgdat] = size(gdat); 4 | [Argdat] = avoidze(gdat); 5 | for j = 1 : cgdat 6 | [Prog] = Mltg(Argdat(:,:,j)*X(:,j)-gdat(:,j),Sig(:,:,l)); 7 | [weisumg] = weightsumgaupdf(Sig,Weig,Argdat(:,:,j)*X(:,j)-gdat(:,j),K); 8 | gaml = gaml + Prog/weisumg; 9 | end 10 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/missclassGroups.m: -------------------------------------------------------------------------------- 1 | %-Here, we thanks for Professor Ehsan Elhamifar 2 | % [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 3 | % Computes the number of missclassified points in the vector Segmentation. 4 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 5 | % the label for each group, ranging from 1 to n 6 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 7 | % points in each group. 8 | % ngroups: number of groups 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2010 11 | %-------------------------------------------------------------------------- 12 | 13 | 14 | function [miss,index] = missclassGroups(Segmentation,RefSegmentation,ngroups) 15 | 16 | Permutations = perms(1:ngroups); 17 | if(size(Segmentation,2)==1) 18 | Segmentation=Segmentation'; 19 | end 20 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 21 | for k=1:size(Segmentation,1) 22 | for j=1:size(Permutations,1) 23 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 24 | end 25 | end 26 | 27 | [miss,temp] = min(miss,[],1); 28 | index = Permutations(temp,:); 29 | -------------------------------------------------------------------------------- /2015 CVPR MGR/solvematrix.m: -------------------------------------------------------------------------------- 1 | % Finding the nth column of coefficient matrix 2 | function[partXn] = solvematrix(xdata,K,xwei,Sig,n,X) 3 | partXn = 0; 4 | [xArgdat] = avoidze(xdata); 5 | [xweisum] = weightsumgaupdf(Sig,xwei,xArgdat(:,:,n)*X(:,n)-xdata(:,n),K); 6 | xmole = 0; 7 | for j = 1 : K 8 | [xPro] = Mltg(xArgdat(:,:,n)*X(:,n)-xdata(:,n),Sig(:,:,j)); 9 | xmole = xmole + xwei(j)*xPro*xArgdat(:,:,n)'*inv(Sig(:,:,j)); 10 | end 11 | partXn = xmole/xweisum; 12 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/updattweig.m: -------------------------------------------------------------------------------- 1 | % Updating the pth weight 2 | function[newweip] = updattweig(wdatam,owei,p,K,X,Sig) 3 | [pgaml] = gamij(wdatam,Sig,p,X,K,owei); 4 | rwdatc = size(wdatam,2); 5 | newweip = (owei(p)/rwdatc)*pgaml; 6 | end -------------------------------------------------------------------------------- /2015 CVPR MGR/weightsumgaupdf.m: -------------------------------------------------------------------------------- 1 | function[weisum] = weightsumgaupdf( Sig,weig,x,K)% 2 | % The sum of Gaussian components with weights 3 | Sw =0; 4 | for j = 1 :K 5 | [Pro] = Mltg(x,Sig(:,:,j)); 6 | Sw = Sw + Pro*weig(j); 7 | end 8 | weisum = Sw; 9 | end -------------------------------------------------------------------------------- /2015 CVPR S3C/BuildAdjacency.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes a NxN coefficient matrix and returns a NxN adjacency 3 | % matrix by choosing the K strongest connections in the similarity graph 4 | % CMat: NxN coefficient matrix 5 | % K: number of strongest edges to keep; if K=0 use all the exiting edges 6 | % CKSym: NxN symmetric adjacency matrix 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | 12 | function [CKSym,CAbs] = BuildAdjacency(CMat,K) 13 | 14 | if (nargin < 2) 15 | K = 0; 16 | end 17 | 18 | N = size(CMat,1); 19 | CAbs = abs(CMat); 20 | 21 | [Srt,Ind] = sort( CAbs,1,'descend' ); 22 | 23 | if (K == 0) 24 | for i = 1:N 25 | CAbs(:,i) = CAbs(:,i) ./ (CAbs(Ind(1,i),i)+eps); 26 | end 27 | else 28 | for i = 1:N 29 | for j = 1:K 30 | CAbs(Ind(j,i),i) = CAbs(Ind(j,i),i) ./ (CAbs(Ind(1,i),i)+eps); 31 | end 32 | end 33 | end 34 | 35 | CKSym = CAbs + CAbs'; -------------------------------------------------------------------------------- /2015 CVPR S3C/DataProjection.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the D x N data matrix with columns indicating 3 | % different data points and project the D dimensional data into a r 4 | % dimensional subspace using PCA. 5 | % X: D x N matrix of N data points 6 | % r: dimension of the PCA projection, if r = 0, then no projection 7 | % Xp: r x N matrix of N projectred data points 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Xp = DataProjection(X,r) 14 | 15 | if (nargin < 2) 16 | r = 0; 17 | end 18 | 19 | if (r == 0) 20 | Xp = X; 21 | else 22 | [U,~,~] = svd(X,0); 23 | Xp = U(:,1:r)' * X; 24 | end 25 | -------------------------------------------------------------------------------- /2015 CVPR S3C/Misclassification.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes the groups resulted from spectral clutsering and the 3 | % ground truth to compute the misclassification rate. 4 | % groups: [grp1,grp2,grp3] for three different forms of Spectral Clustering 5 | % s: ground truth vector 6 | % Missrate: 3x1 vector with misclassification rates of three forms of 7 | % spectral clustering 8 | %-------------------------------------------------------------------------- 9 | % Copyright @ Ehsan Elhamifar, 2012 10 | %-------------------------------------------------------------------------- 11 | 12 | 13 | function Missrate = Misclassification(groups,s) 14 | 15 | n = max(s); 16 | for i = 1:size(groups,2) 17 | Missrate(i,1) = missclassGroups( groups(:,i),s,n ) ./ length(s); 18 | end -------------------------------------------------------------------------------- /2015 CVPR S3C/StrSSC.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2015 CVPR S3C/StrSSC.m -------------------------------------------------------------------------------- /2015 CVPR S3C/compacc.m: -------------------------------------------------------------------------------- 1 | function [acc] = compacc(idx1,idx0) 2 | %inputs: 3 | % idx1 -- the clustering results 4 | % idx0 -- the groudtruth clustering results 5 | %outputs: 6 | % acc -- segmentation accuracy (or classification accuracy) 7 | uids = unique(idx1); 8 | idx = idx1; 9 | for i=1:length(uids) 10 | uid = uids(i); 11 | inds = abs(idx1-uid)<0.1; 12 | vids = idx0(inds); 13 | uvids = unique(vids); 14 | vf = 0; 15 | for j=1:length(uvids) 16 | vfj = sum(abs(vids-uvids(j))<0.1); 17 | if vfj>vf; 18 | vid = uvids(j); 19 | vf = vfj; 20 | end 21 | end 22 | idx(inds) = vid; 23 | end 24 | acc = sum(abs(idx-idx0)<0.1)/length(idx0); -------------------------------------------------------------------------------- /2015 CVPR S3C/computeLambda_mat.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function takes a DxN matrix of N data points in a D-dimensional 3 | % space and returns the regularization constant of the L1 norm 4 | % Y: DxN data matrix 5 | % lambda: regularization parameter for lambda*||C||_1 + 0.5 ||Y-YC||_F^2 6 | %-------------------------------------------------------------------------- 7 | % Copyright @ Ehsan Elhamifar, 2012 8 | %-------------------------------------------------------------------------- 9 | 10 | function lambda = computeLambda_mat(Y,P) 11 | 12 | if (nargin < 2) 13 | P = Y; 14 | end 15 | 16 | N = size(Y,2); 17 | T = P' * Y; 18 | T(1:N,:) = T(1:N,:) - diag(diag(T(1:N,:))); 19 | T = abs(T); 20 | lambda = min(max(T,[],1)); 21 | -------------------------------------------------------------------------------- /2015 CVPR S3C/errorCoef.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function computes the maximum error between elements of two 3 | % coefficient matrices 4 | % C: NxN coefficient matrix 5 | % Z: NxN coefficient matrix 6 | % err: infinite norm error between vectorized C and Z 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | function err = errorCoef(Z,C) 12 | 13 | err = max(max( abs(Z-C) )); 14 | %err = norm(Z-C,'fro'); -------------------------------------------------------------------------------- /2015 CVPR S3C/errorLinSys.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function computes the maximum L2-norm error among the columns of the 3 | % residual of a linear system 4 | % Y: DxN data matrix of N data point in a D-dimensional space 5 | % Z: NxN sparse coefficient matrix 6 | % err: maximum L2-norm of the columns of Y-YZ 7 | %-------------------------------------------------------------------------- 8 | % Copyright @ Ehsan Elhamifar, 2012 9 | %-------------------------------------------------------------------------- 10 | 11 | function err = errorLinSys(P,Z) 12 | 13 | [R,N] = size(Z); 14 | if (R > N) 15 | E = P(:,N+1:end) * Z(N+1:end,:); 16 | Y = P(:,1:N); 17 | Y0 = Y - E; 18 | C = Z(1:N,:); 19 | else 20 | Y = P; 21 | Y0 = P; 22 | C = Z; 23 | end 24 | 25 | [Yn,n] = matrixNormalize(Y0); 26 | M = repmat(n,size(Y,1),1); 27 | S = Yn - Y * C ./ M; 28 | err = sqrt( max( sum( S.^2,1 ) ) ); -------------------------------------------------------------------------------- /2015 CVPR S3C/matrixNormalize.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % This function normalizes the columns of a given matrix 3 | % Y: DxN data matrix 4 | % Yn: DxN data matrix whose columns have unit Euclidean norm 5 | % n: N-dimensional vector of the norms of the columns of Y 6 | %-------------------------------------------------------------------------- 7 | % Copyright @ Ehsan Elhamifar, 2012 8 | %-------------------------------------------------------------------------- 9 | 10 | function [Yn,n] = matrixNormalize(Y) 11 | 12 | for i = 1:size(Y,2) 13 | n(i) = norm(Y(:,i)); 14 | Yn(:,i) = Y(:,i) ./ n(i); 15 | end -------------------------------------------------------------------------------- /2015 CVPR S3C/missclassGroups.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 3 | % Computes the number of missclassified points in the vector Segmentation. 4 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 5 | % the label for each group, ranging from 1 to n 6 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 7 | % points in each group. 8 | % ngroups: number of groups 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2012 11 | %-------------------------------------------------------------------------- 12 | 13 | 14 | function [miss,index] = missclassGroups(Segmentation,RefSegmentation,ngroups) 15 | 16 | Permutations = perms(1:ngroups); 17 | if(size(Segmentation,2)==1) 18 | Segmentation=Segmentation'; 19 | end 20 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 21 | for k=1:size(Segmentation,1) 22 | for j=1:size(Permutations,1) 23 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 24 | end 25 | end 26 | 27 | [miss,temp] = min(miss,[],1); 28 | index = Permutations(temp,:); 29 | -------------------------------------------------------------------------------- /2015 CVPR S3C/readme.txt: -------------------------------------------------------------------------------- 1 | To run this code: 2 | 3 | 1. Need some codes of 'SSC_ADMM_v1.1'. 4 | 5 | 2. Put the modified version of 'kmean.m', which uses the previous clustering result for initialization, into the statistical toolbox to replace 'kmean.m'. 6 | 7 | Chunguang -------------------------------------------------------------------------------- /2015 CVPR S3C/thrC.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % Copyright @ Ehsan Elhamifar, 2012 3 | %-------------------------------------------------------------------------- 4 | 5 | function Cp = thrC(C,ro) 6 | 7 | if (nargin < 2) 8 | ro = 1; 9 | end 10 | 11 | if (ro < 1) 12 | N = size(C,2); 13 | Cp = zeros(N,N); 14 | [S,Ind] = sort(abs(C),1,'descend'); 15 | for i = 1:N 16 | cL1 = sum(S(:,i)); 17 | stop = false; 18 | cSum = 0; t = 0; 19 | while (~stop) 20 | t = t + 1; 21 | cSum = cSum + S(t,i); 22 | if ( cSum >= ro*cL1 ) 23 | stop = true; 24 | Cp(Ind(1:t,i),i) = C(Ind(1:t,i),i); 25 | end 26 | end 27 | end 28 | else 29 | Cp = C; 30 | end -------------------------------------------------------------------------------- /2015 ICCV RSIM/ComputeNcutValue.m: -------------------------------------------------------------------------------- 1 | function NcutValue = ComputeNcutValue(W,grp) 2 | K = size(grp,2); 3 | NcutValue = 0; 4 | 5 | for ii = 1:K 6 | idx = grp(:,ii)==1; 7 | Wg = W(~idx,idx); 8 | cutA = sum(Wg(:)); 9 | NcutValue = NcutValue+cutA; 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /2015 ICCV RSIM/ErrorRate.m: -------------------------------------------------------------------------------- 1 | function Missrate = ErrorRate(Seg,RefSeg) 2 | 3 | if(max(max(RefSeg))~=1 && max(max(Seg))~=1) %Calculate the error rate using the results of standard spectral clustering method 4 | %Missrate = Misclassification(Seg,RefSeg); 5 | Missrate = missclassGroups( Seg,RefSeg,max(RefSeg) ) ./ length(RefSeg); 6 | elseif(max(max(RefSeg))==1 && max(max(Seg))==1) 7 | [N,n] = size(RefSeg); %number of clusters 8 | SegVec = zeros(N,1); 9 | RefSegVec = zeros(N,1); 10 | for i=1:n 11 | SegVec = SegVec+i*Seg(:,i); 12 | RefSegVec = RefSegVec+i*RefSeg(:,i); 13 | end 14 | %Missrate = Misclassification(SegVec,RefSegVec); 15 | Missrate = missclassGroups( SegVec,RefSegVec,max(RefSegVec) ) ./ length(RefSegVec); 16 | elseif(max(max(RefSeg))==1 && max(max(Seg))~=1) 17 | [N,n] = size(RefSeg); %number of clusters 18 | RefSegVec = zeros(N,1); 19 | for i=1:n 20 | RefSegVec = RefSegVec+i*RefSeg(:,i); 21 | end 22 | %Missrate = Misclassification(Seg,RefSegVec); 23 | Missrate = missclassGroups( Seg,RefSegVec,max(RefSegVec) ) ./ length(RefSegVec); 24 | else 25 | [N,n] = size(Seg); %number of clusters 26 | SegVec = zeros(N,1); 27 | for i=1:n 28 | SegVec = SegVec+i*Seg(:,i); 29 | end 30 | %Missrate = Misclassification(SegVec,RefSeg); 31 | Missrate = missclassGroups( SegVec,RefSeg,max(RefSeg) ) ./ length(RefSeg); 32 | end 33 | -------------------------------------------------------------------------------- /2015 ICCV RSIM/missclassGroups.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % [miss,index] = missclass(Segmentation,RefSegmentation,ngroups) 3 | % Computes the number of missclassified points in the vector Segmentation. 4 | % Segmentation: 1 by sum(npoints) or sum(ngroups) by 1 vector containing 5 | % the label for each group, ranging from 1 to n 6 | % npoints: 1 by ngroups or ngroups by 1 vector containing the number of 7 | % points in each group. 8 | % ngroups: number of groups 9 | %-------------------------------------------------------------------------- 10 | % Copyright @ Ehsan Elhamifar, 2010 11 | %-------------------------------------------------------------------------- 12 | 13 | 14 | function [miss,index] = missclassGroups(Segmentation,RefSegmentation,ngroups) 15 | 16 | Permutations = perms(1:ngroups); 17 | if(size(Segmentation,2)==1) 18 | Segmentation=Segmentation'; 19 | end 20 | miss = zeros(size(Permutations,1),size(Segmentation,1)); 21 | for k=1:size(Segmentation,1) 22 | for j=1:size(Permutations,1) 23 | miss(j,k) = sum(Segmentation(k,:)~=Permutations(j,RefSegmentation)); 24 | Permutations(j,RefSegmentation); 25 | end 26 | end 27 | 28 | [miss,temp] = min(miss,[],1); 29 | index = Permutations(temp,:); 30 | -------------------------------------------------------------------------------- /2015 ICCV RSIM/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2015 ICCV RSIM/readme.txt -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/EYaleB/ExtendedYaleB.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/EYaleB/ExtendedYaleB.mat -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/MNIST/SCofDigits.m: -------------------------------------------------------------------------------- 1 | function [feature] = SCofDigits(data) 2 | % Extract features by scattering transform. 3 | 4 | % Copyright Chong You @ Johns Hopkins University, 2016 5 | % chong.you1987@gmail.com 6 | 7 | N = size(data, 2); 8 | 9 | foptions.J = 3; foptions.L = 8; soptions.M = 2; soptions.oversampling = 0; 10 | [Wop, ~] = wavelet_factory_2d([28 28], foptions, soptions); 11 | for ii = 1:N 12 | if mod(ii, 100) == 0 13 | fprintf( '%d finished\n' , ii) 14 | end 15 | im = reshape(data(:, ii), 28, 28); 16 | sc_digit = scat(im, Wop); 17 | 18 | sc = format_scat(sc_digit); 19 | 20 | if ii == 1 % set parameters and allocate space for ``feature'' 21 | Npath = size(sc, 1); 22 | feature = zeros(Npath*size(sc, 2)*size(sc, 3), N); 23 | end 24 | 25 | feature(:, ii) = sc(:)'; 26 | end 27 | for iF = 1:Npath % normalize each feature image to unit norm 28 | feature(iF:Npath:end, :) = cnormalize( feature(iF:Npath:end, :), Inf ); 29 | end 30 | 31 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/bestMap.m: -------------------------------------------------------------------------------- 1 | function [newL2] = bestMap(L1,L2) 2 | %bestmap: permute labels of L2 to match L1 as good as possible 3 | % [newL2] = bestMap(L1,L2); 4 | % 5 | % version 2.0 --May/2007 6 | % version 1.0 --November/2003 7 | % 8 | % Written by Deng Cai (dengcai AT gmail.com) 9 | 10 | 11 | %=========== 12 | 13 | L1 = L1(:); 14 | L2 = L2(:); 15 | if size(L1) ~= size(L2) 16 | error('size(L1) must == size(L2)'); 17 | end 18 | 19 | Label1 = unique(L1); 20 | nClass1 = length(Label1); 21 | Label2 = unique(L2); 22 | nClass2 = length(Label2); 23 | 24 | nClass = max(nClass1,nClass2); 25 | G = zeros(nClass); 26 | for i=1:nClass1 27 | for j=1:nClass2 28 | G(i,j) = length(find(L1 == Label1(i) & L2 == Label2(j))); 29 | end 30 | end 31 | 32 | [c,t] = hungarian(-G); 33 | newL2 = zeros(size(L2)); 34 | for i=1:nClass2 35 | newL2(L2 == Label2(i)) = Label1(c(i)); 36 | end 37 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/cnormalize.m: -------------------------------------------------------------------------------- 1 | function [Y, Xnorm] = cnormalize(X, p) 2 | %CNORMALIZE normalizes columns. 3 | % 4 | % [Y, XNORM] = cnormalize(X, P) normalizes columns of matrix X to unit 5 | % ell_P norm, and returen the norm values to XNORM and data to Y. 6 | 7 | % Copyright Chong You @ Johns Hopkins University, 2016 8 | % chong.you1987@gmail.com 9 | 10 | if ~exist('p', 'var') 11 | p = 2; 12 | end 13 | 14 | if p == Inf 15 | Xnorm = max(abs(X), [], 1); 16 | else 17 | Xnorm = sum(abs(X) .^p, 1) .^(1/p); 18 | end 19 | Y = bsxfun(@rdivide, X, Xnorm + eps); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/cnormalize_inplace.m: -------------------------------------------------------------------------------- 1 | function [X, Xnorm] = cnormalize_inplace(X, p) 2 | %CNORMALIZE_INPLACE normalizes columns. 3 | % This is a inplace version of CNORMALIZE. 4 | 5 | % Copyright Chong You @ Johns Hopkins University, 2016 6 | % chong.you1987@gmail.com 7 | 8 | N = size( X, 2 ); 9 | if ~exist('p', 'var') 10 | p = 2; 11 | end 12 | 13 | if nargout > 1, Xnorm = zeros(1, N); end; 14 | 15 | for iN = 1:N 16 | if p == Inf 17 | cnorm = max(abs(X(:, iN)), [], 1); 18 | else 19 | cnorm = sum(abs(X(:, iN)) .^p, 1) .^(1/p); 20 | end 21 | X(:, iN) = X(:, iN) / (cnorm + eps); 22 | 23 | if nargout > 1, Xnorm(iN) = cnorm; end; 24 | end 25 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/dimReduction_PCA.m: -------------------------------------------------------------------------------- 1 | function Xp = dimReduction_PCA(X, dim) 2 | %DIMREDUCTION_PCA Dimension reduction by PCA. 3 | % XP = dimReduction_PCA(X,DIM) computes DIM-dimensional embedding by PCA. 4 | % Let X = U D V' be its SVD where the singular values in D are ordered. 5 | % XP is computed as the first DIM rows of D * V'. 6 | 7 | % Input Arguments 8 | % X -- data matrix of size D by N. 9 | % dim -- dimension 10 | % Output Arguments 11 | % Xp -- data matrix of size dim by N. 12 | 13 | % Copyright Chong You @ Johns Hopkins University, 2016 14 | % chong.you1987@gmail.com 15 | 16 | LARGE_SCALE = 5000; % if min(D, N) > LARGE_SCALE then the data is too large. 17 | if dim == 0 18 | Xp = X; 19 | return; 20 | end 21 | 22 | [m, N] = size(X); 23 | if m <= N 24 | if m > LARGE_SCALE, error(['Error in ''' mfilename ''': matrix too big\n']); end; 25 | ddata = X * X'; 26 | [U, eigval] = eig(ddata); 27 | [~, order] = sort(-diag(eigval)); 28 | Xp = U(:, order(1:dim))' * X; 29 | else 30 | if N > LARGE_SCALE, error(['Error in ''' mfilename ''': matrix too big\n']); end; 31 | ddata = X' * X; 32 | [V, eigval] = eig(ddata); 33 | [~, order] = sort(-diag(eigval)); 34 | Xp = (eigval(order(1:dim), order(1:dim)) .^.5) * V(:, order(1:dim))'; 35 | end 36 | 37 | end 38 | 39 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/evalAccuracy.m: -------------------------------------------------------------------------------- 1 | function accuracy = evalAccuracy(label1, label2) 2 | label2 = bestMap(label1, label2); 3 | accuracy = sum(label1(:) == label2(:)) / length(label2); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/evalConn.m: -------------------------------------------------------------------------------- 1 | function conn = evalConn(C, s) 2 | % C \in R^N-by-N: symmetric affinity matrix 3 | % s \in {1, 2, ... n}^N: group labels 4 | % 5 | % conn: connectivity index 6 | % conn = min_{i = 1,...,n} (second-least eigenvalue of L_i); 7 | if ~issymmetric(C) 8 | warning('(evalConn) affinity matrix not symmetric') 9 | end 10 | 11 | s_val = unique(s); 12 | n = length(s_val); 13 | 14 | conn = inf; 15 | for in = 1:n 16 | % prepare data 17 | C_in = C(s == s_val(in), s == s_val(in)); 18 | % conn 19 | if min(sum(C_in, 2)) < eps 20 | conn_in = 0.0; 21 | else 22 | OPTS.tol = 1e-3; 23 | [~, eig_in] = eigs( cnormalize(C_in, 1)', 2, 'LR', OPTS ); 24 | conn_in = 1 - eig_in(2, 2); 25 | end 26 | conn = min( [conn, conn_in] ); 27 | end 28 | 29 | end 30 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/evalSSR_error.m: -------------------------------------------------------------------------------- 1 | function error = evalSSR_error(C, s) 2 | % C \in R^N-by-N: representation matrix by self-expressiveness based method 3 | % s \in {1, 2, ... n}^N: group labels 4 | % 5 | % error: average SSR error. 6 | 7 | N = length(s); 8 | 9 | error = 0; 10 | e_vec = zeros(1, N); 11 | for iN = 1:N 12 | if norm(C(:, iN), 1) < eps 13 | error = error + 1; 14 | else 15 | error = error + norm( C(s ~= s(iN), iN), 1 ) / norm(C(:, iN), 1); 16 | end 17 | e_vec(iN) = norm( C(s ~= s(iN), iN), 1 ) / norm(C(:, iN), 1); 18 | end 19 | error = error / N; 20 | 21 | end 22 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/evalSSR_perc.m: -------------------------------------------------------------------------------- 1 | function [perc, x] = evalSSR_perc(C, s) 2 | % C \in R^N-by-N: representation matrix by self-expressiveness based method 3 | % s \in {1, 2, ... n}^N: group labels 4 | % 5 | % perc: percentage of points that is subspace sparse. 6 | % x: for plotting curve: [0; x; 1] \times [0:1/N:1, 1]; 7 | 8 | N = length(s); 9 | x = zeros(N, 1); 10 | for ii = 1:N 11 | x(ii) = max( abs(C(s ~= s(ii), ii)) ); 12 | end 13 | x = x ./ max(abs(C), [], 1)'; 14 | perc = sum(x < 1e-5) / N; 15 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/loadMNISTImages.m: -------------------------------------------------------------------------------- 1 | function images = loadMNISTImages(filename) 2 | %loadMNISTImages returns a 28x28x[number of MNIST images] matrix containing 3 | %the raw MNIST images 4 | 5 | fp = fopen(filename, 'rb'); 6 | assert(fp ~= -1, ['Could not open ', filename, '']); 7 | 8 | magic = fread(fp, 1, 'int32', 0, 'ieee-be'); 9 | assert(magic == 2051, ['Bad magic number in ', filename, '']); 10 | 11 | numImages = fread(fp, 1, 'int32', 0, 'ieee-be'); 12 | numRows = fread(fp, 1, 'int32', 0, 'ieee-be'); 13 | numCols = fread(fp, 1, 'int32', 0, 'ieee-be'); 14 | 15 | images = fread(fp, inf, 'unsigned char'); 16 | images = reshape(images, numCols, numRows, numImages); 17 | images = permute(images,[2 1 3]); 18 | 19 | fclose(fp); 20 | 21 | % Reshape to #pixels x #examples 22 | images = reshape(images, size(images, 1) * size(images, 2), size(images, 3)); 23 | % Convert to double and rescale to [0,1] 24 | images = double(images) / 255; 25 | 26 | end 27 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/loadMNISTLabels.m: -------------------------------------------------------------------------------- 1 | function labels = loadMNISTLabels(filename) 2 | %loadMNISTLabels returns a [number of MNIST images]x1 matrix containing 3 | %the labels for the MNIST images 4 | 5 | fp = fopen(filename, 'rb'); 6 | assert(fp ~= -1, ['Could not open ', filename, '']); 7 | 8 | magic = fread(fp, 1, 'int32', 0, 'ieee-be'); 9 | assert(magic == 2049, ['Bad magic number in ', filename, '']); 10 | 11 | numLabels = fread(fp, 1, 'int32', 0, 'ieee-be'); 12 | 13 | labels = fread(fp, inf, 'unsigned char'); 14 | 15 | assert(size(labels,1) == numLabels, 'Mismatch in label count'); 16 | 17 | fclose(fp); 18 | 19 | end 20 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/readme.txt: -------------------------------------------------------------------------------- 1 | This package contains the Matlab codes implementing subspace clustering by orthogonal matching pursuit as described in "Scalable Sparse Subspace Clustering by Orthogonal Matching Pursuit", CVPR 16. 2 | 3 | The method is shown to achieve state-of-the-art clustering performance on Extended Yale B face database and the MNIST handwritten digit database and is computationally efficient. 4 | 5 | Start from run_Synthetic, run_EYaleB.m, run_MNIST.m 6 | 7 | chong.you1987@gmail.com 8 | 9 | Update on May 26th 2016: corrected bugs in the code. -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | perso/* 3 | feature/ 4 | *.m~ 5 | doc/*/*.aux 6 | doc/*/*.log 7 | doc/*/*.bbl 8 | doc/*/*.blg 9 | *.mat 10 | *.swp 11 | *.png 12 | */html/* 13 | *.html 14 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/addpath_scatnet.m: -------------------------------------------------------------------------------- 1 | path_to_scatnet = fileparts(mfilename('fullpath')); 2 | 3 | addpath(fullfile(path_to_scatnet, 'classification')); 4 | addpath(fullfile(path_to_scatnet, 'convolution')); 5 | addpath(fullfile(path_to_scatnet, 'core')); 6 | addpath(genpath(fullfile(path_to_scatnet, 'demo'))); 7 | addpath(fullfile(path_to_scatnet, 'display')); 8 | addpath(fullfile(path_to_scatnet, 'filters')); 9 | addpath(fullfile(path_to_scatnet, 'filters/selesnick')); 10 | addpath(fullfile(path_to_scatnet, 'utils')); 11 | addpath(genpath(fullfile(path_to_scatnet, 'papers'))); 12 | addpath(fullfile(path_to_scatnet, 'scatutils')); 13 | addpath(genpath(fullfile(path_to_scatnet, 'unittest'))); 14 | addpath(fullfile(path_to_scatnet, 'utils')); 15 | addpath(fullfile(path_to_scatnet, 'reconstruction')); 16 | 17 | clear path_to_scatnet; 18 | 19 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/classification/classif_err.m: -------------------------------------------------------------------------------- 1 | % CLASSIF_ERR Calculates the classification error. 2 | % 3 | % Usage 4 | % err = CLASSIF_ERR(labels, test_set, src) 5 | % 6 | % Input 7 | % labels (int): The predicted labels corresponding to the testing in- 8 | % stances. 9 | % test_set (int): The object indices of the testing instances. 10 | % src (struct): The source from which the objects were taken. 11 | % 12 | % Output 13 | % err (numeric): The classification error. 14 | % 15 | % See also 16 | % AFFINE_TEST, SVM_TEST 17 | 18 | function err = classif_err(labels,test_set,src) 19 | truth = [src.objects(test_set).class]; 20 | 21 | if isfield(src,'cluster') 22 | cluster = src.cluster; 23 | else 24 | cluster = 1:max(truth); 25 | end 26 | 27 | err = 1-sum(bsxfun(@eq,cluster(labels),cluster(truth)),2)/length(truth); 28 | end 29 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/classification/classif_recog.m: -------------------------------------------------------------------------------- 1 | % CLASSIF_RECOG Calculates the average recognition rate 2 | % 3 | % Usage 4 | % [rr_mean,recog_rate] = CLASSIF_RECOG(labels,test_set,truth) 5 | % 6 | % Input 7 | % labels (int): The labels attributed to the testing instances. 8 | % test_set (int): The object indices of the testing instances. 9 | % truth: the actual labels of the testing instances 10 | % 11 | % Output 12 | % rr_mean (real): The mean recognition rate 13 | % recog_rate(real): array containing the individual recognition rates of 14 | % each class. 15 | % 16 | % Description 17 | % This function computes the average recognition rate of each class. 18 | % It is a widely used measure of the performance of the classifier when the 19 | % data set is highly unbalanced. 20 | % 21 | % See also 22 | % SVM_TEST, CLASSIF_ERR, CLASSIF_RECOG 23 | 24 | function [rg_mean,recog_rate]=classif_recog(labels,test_set,truth) 25 | if isstruct(truth) 26 | src=truth; 27 | truth = [src.objects.class]; 28 | end 29 | 30 | % Normally, the test_set contains samples of all classes 31 | recog_rate=zeros(1,max(truth)); 32 | gdTruth=truth(:,test_set); 33 | 34 | for k=1:max(truth) 35 | mask=k==gdTruth; 36 | good_elts=find(labels==k & mask); 37 | 38 | mask1=numel(find(mask==1)); 39 | recog_rate(k)=numel(good_elts)/mask1; 40 | end 41 | 42 | rg_mean=mean(recog_rate); 43 | end 44 | 45 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/classification/duration_feature.m: -------------------------------------------------------------------------------- 1 | % DURATION_FEATURE Calculate the log-duration of an object 2 | % 3 | % Usage 4 | % duration = DURATION_FEATURE(x, object) 5 | % 6 | % Input 7 | % x (numeric): The file data (not used). 8 | % object (struct): The objects contained in the data. 9 | % 10 | % Output 11 | % duration (numeric): The log-duration of the objects. 12 | % 13 | % See also 14 | % PREPARE_DATABASE 15 | 16 | function t = duration_feature(x, object) 17 | t = permute(log([object.u2]-[object.u1]+1),[1 3 2]); 18 | end 19 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/classification/fmd_src.m: -------------------------------------------------------------------------------- 1 | % FMD_SRC Creates a source for the FMD Texture dataset 2 | % 3 | % Usage 4 | % src = FMD_SRC(directory) 5 | % 6 | % Input 7 | % directory: The directory containing the FMD Texture dataset. 8 | % 9 | % Output 10 | % src: The FMD source. 11 | % 12 | % Note 13 | % The dataset is available at http://people.csail.mit.edu/celiu/CVPR2010/FMD/ 14 | 15 | 16 | function src = fmd_src(directory) 17 | if nargin<1 18 | directory = '/Users/laurentsifre/TooBigForDropbox/Databases/FMD/image/'; 19 | end 20 | src = create_src(directory, @uiuc_extract_objects_fun); 21 | end 22 | 23 | function [objects, classes] = uiuc_extract_objects_fun(file) 24 | objects.u1 = [1, 1]; 25 | objects.u2 = [512, 384]; 26 | path_str = fileparts(file); 27 | path_parts = regexp(path_str, filesep, 'split'); 28 | classes = {path_parts{end}}; 29 | end 30 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/classification/svm_extract_w.m: -------------------------------------------------------------------------------- 1 | % SVM_EXTRACT_W Calculates the discriminant vector for a linear SVM 2 | % 3 | % Usage 4 | % [w,rho] = SVM_EXTRACT_W(db, model) 5 | % 6 | % Input 7 | % db (struct): The database from which the model is calculated. 8 | % model (struct): The linear SVM model. 9 | % 10 | % Output 11 | % w (numeric): The discriminant vectors for each pair of classes in the model. 12 | % rho (numeric): The biases for each pair of classes in the model. 13 | % 14 | % See also 15 | % SVM_TRAIN 16 | 17 | function [w,rho] = svm_extract_w(db,model) 18 | if model.svm.Parameters(2) == 0 % linear SVM 19 | class_ct = model.svm.nr_class; 20 | w = zeros(size(model.svm.SVs,2),class_ct*(class_ct-1)/2); 21 | r = 1; 22 | pairs = []; 23 | for n1 = 1:class_ct 24 | for n2 = n1+1:class_ct 25 | pairs = [pairs [n1; n2]]; 26 | 27 | class1_SVs = 1+sum(model.svm.nSV(1:n1-1)):sum(model.svm.nSV(1:n1)); 28 | class2_SVs = 1+sum(model.svm.nSV(1:n2-1)):sum(model.svm.nSV(1:n2)); 29 | 30 | sv_coef1 = model.svm.sv_coef(class1_SVs,n2-1); 31 | sv_coef2 = model.svm.sv_coef(class2_SVs,n1); 32 | 33 | w(:,r) = (model.svm.SVs(class1_SVs,:).'*sv_coef1) + ... 34 | (model.svm.SVs(class2_SVs,:).'*sv_coef2); 35 | rho(r) = model.svm.rho(r); 36 | 37 | r = r+1; 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/convolution/pad_size.m: -------------------------------------------------------------------------------- 1 | % PAD_SIZE Compute the optimal size for padding 2 | % 3 | % Usage 4 | % sz_padded = PAD_SIZE(sz, min_margin, max_ds) 5 | % 6 | % Input 7 | % sz (int): The size of the original signal. 8 | % min_margin (int): The minimum margin for padding. 9 | % max_ds (int): The maximum downsampling factor. 10 | % 11 | % Output 12 | % sz_padded (int): The minimum size of the padded signal. 13 | % 14 | % Description 15 | % Calculates the smallest multiple of 2^max_ds larger than sz by at least 16 | % 2*min_margin. This ensures that there is enough margin on both sides of 17 | % the signal to avoid border effects, assuming that min_margin is equal 18 | % to at least half of the size of the largest filter used, while ensuring 19 | % that downsampling by powers of 2 up to 2^max_ds are possible through 20 | % periodization of the Fourier transform. 21 | % sz_added is also enforced to be at least 1 22 | % 23 | % See Also 24 | % PAD_SIGNAL, UNPAD_SIGNAL 25 | 26 | function sz_padded = pad_size(sz, min_margin, max_ds) 27 | sz_padded = 2^max_ds * ceil( (sz + 2*min_margin)/2^max_ds ); 28 | sz_padded = max(1, sz_padded); 29 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/convolution/sub_conv_1d_along_third_dim_simple.m: -------------------------------------------------------------------------------- 1 | function z_conv_filter = sub_conv_1d_along_third_dim_simple(zf, filter, ds) 2 | if (isstruct(filter)) 3 | filter = filter.coefft{1}; 4 | end 5 | filter_rs = repmat(reshape(filter,[1,1,numel(filter)]),... 6 | [size(zf,1),size(zf,2),1]); 7 | z_conv_filter = ifft(zf.* filter_rs,[],3); 8 | if (ds>0) % optimization 9 | z_conv_filter = 2^(ds/2)*z_conv_filter(:,:,1:2^ds:end); 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/core/modulus_layer.m: -------------------------------------------------------------------------------- 1 | % MODULUS_LAYER Calculate the modulus of coefficients in a layer 2 | % 3 | % Usage 4 | % U = MODULUS_LAYER(W) 5 | % 6 | % Input 7 | % W (struct): A scattering layer, as output by WAVELET_LAYER_*, for exam- 8 | % ple. 9 | % 10 | % Output 11 | % U (struct): The same layer with all coefficients set to their absolute 12 | % values. 13 | % 14 | % See Also 15 | % PAD_SIGNAL, UNPAD_SIGNAL 16 | 17 | function U = modulus_layer(W) 18 | U.signal = cellfun(@abs, W.signal, 'UniformOutput', 0); 19 | U.meta = W.meta; 20 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/convolution/demo_conv_sub_1d.m: -------------------------------------------------------------------------------- 1 | %% Demo of conv_sub_1d 2 | 3 | %% Usage 4 | % y_ds = CONV_SUB_1D(xf, filter, ds) (see ) 6 | % 7 | %% Description 8 | % In this demo, we show how conv_sub_1d carries out a product in the 9 | % frequency domain, equivalent to a convolution in time, along with a 10 | % downsampling of the output signal. 11 | 12 | % First, import an input signal and compute its Fourier transform 13 | N = 65536; 14 | load handel; 15 | x = y(1:N); 16 | xf = fft(x); 17 | 18 | % Then, build a constant-Q filterbank 19 | T = 4096; % averaging size 20 | filt_opt.Q = 8; % quality factor 21 | filt_opt.J = T_to_J(T,filt_opt); % number of scales 22 | filt_opt.filter_format = 'fourier_truncated'; % default format 23 | filters = filter_bank(N,filt_opt); 24 | % an arbitrary filter within the filter bank 25 | 26 | % Perform CONV_SUB_1D 27 | ds = 0; % log2 of downsampling factor 28 | filter = filters{1}.psi.filter{10}; 29 | y = conv_sub_1d(xf,filter,ds); 30 | 31 | % Plot the filtered signal 32 | plot(abs(y)); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/core/demo_scat_3d_rotation_invariance.m: -------------------------------------------------------------------------------- 1 | %% demonstrates the rotation invariance of the roto-translation scattering 2 | clear; close all; 3 | x = mandrill; 4 | x = x(128:128+255, 128:128+255); 5 | 6 | filt_opt = struct(); 7 | filt_rot_opt = struct(); 8 | % oversampling is set to infty 9 | % so that scattering of original and rotated 10 | % image will be sampled at exactly the same points 11 | scat_opt.oversampling = 10; 12 | 13 | Wop = wavelet_factory_3d(size(x), filt_opt, filt_rot_opt, scat_opt); 14 | 15 | %% compute scattering of x 16 | Sx = scat(x, Wop); 17 | sx = format_scat(Sx); 18 | 19 | %% compute scattering of x rotated by pi/2 20 | x_rot = rot90(x,1); 21 | Sx_rot = scat(x_rot, Wop); 22 | 23 | %% rotate back the scattering of the rotated image 24 | Sx_rot_back = scatfun(@(x)(rot90(x,3)), Sx_rot); 25 | sx_rot_back = format_scat(Sx_rot_back); 26 | 27 | %% display original scattering and rotated-back scattering of rotated image 28 | %% order 1 29 | subplot(121); 30 | image_scat_layer(Sx{2}, 0, 0); 31 | subplot(122); 32 | image_scat_layer(Sx_rot_back{2}, 0, 0); 33 | %% order 2 34 | subplot(121); 35 | image_scat_layer(Sx{3}, 0, 0); 36 | subplot(122); 37 | image_scat_layer(Sx_rot_back{3}, 0, 0); 38 | %% compute norm ratio 39 | norm_diff = sqrt(sum((sx(:)-sx_rot_back(:)).^2)); 40 | norm_s = sqrt(sum((sx(:)).^2)); 41 | fprintf('\n ratio of norm difference vs norm %.10f ', norm_diff/norm_s); 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/core/demo_wavelet_factory_2d.m: -------------------------------------------------------------------------------- 1 | %% Introduction to *wavelet_factory_2d* 2 | % *wavelet_factory_2d* is computing operators(except the modulus) and 3 | % filters required to compute the next layer of a scattering network. 4 | % 5 | %% Usage 6 | % [Wop, filters] = wavelet_factory_2d(size_in, filt_opt, scat_opt), documentation is given in 7 | % 8 | % 9 | %% Description 10 | % Given a size image, some filters options and scattering options, this 11 | % function comput the linear operators necessar to compute the next 12 | % coefficients of scattering. 13 | 14 | x = mandrill; 15 | 16 | % Create $ U[\empty]x $ 17 | [Wop, filters] = wavelet_factory_2d(size(x)); 18 | 19 | % Then one can apply Wop as in *scat*. Please reference to its 20 | % documentation. 21 | 22 | 23 | %% Options 24 | % filt_opt has the same fields as in *morlet_filter_bank_2d*. 25 | % 26 | % scat_opt has the same fields as in *wavelet_layer_2d*. 27 | % 28 | % See their documentation for more details. 29 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/core/demo_wavelet_layer_2d.m: -------------------------------------------------------------------------------- 1 | %% Introduction to *wavelet_layer_2d* 2 | % *wavelet_layer_2d* is computing the wavelet transform coefficient from 3 | % the coefficient of the previous layer. It should be applied iteratively 4 | % to an input signal. 5 | % 6 | %% Usage 7 | % [A, V] = *wavelet_layer_2d*(U, filters, options), documentation is given in 8 | % 9 | % 10 | %% Description 11 | % It is possible to create some wavelet filters with wavelet_factory_2d for 12 | % instance. The filters size have to be adapted to the size of the input 13 | % signal $x$. 14 | clear; close all; 15 | 16 | x = mandrill; 17 | 18 | % Create $ U[\empty]x $ 19 | U{1}.signal{1} = x; 20 | U{1}.meta.j = zeros(0,1); 21 | U{1}.meta.q = zeros(0,1); 22 | U{1}.meta.resolution=0; 23 | filters = morlet_filter_bank_2d(size(x)); 24 | 25 | % A corresponds to the output scattering coefficients, and V to the wavelet 26 | % coefficients. 27 | [A, V] = wavelet_layer_2d(U{1}, filters); 28 | 29 | colormap gray 30 | subplot(121) 31 | imagesc(real(V.signal{1})) 32 | axis off 33 | title('Real part of the first wavelet transform coefficient'); 34 | subplot(122) 35 | imagesc(imag(V.signal{1})) 36 | axis off 37 | title('Imaginary part of the first wavelet transform coefficient'); 38 | 39 | 40 | %% Options 41 | % The options are the same as in *wavelet_2d*. 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/display/demo_display_filters_2d.m: -------------------------------------------------------------------------------- 1 | %% Demo of *display_filter_bank_2d* 2 | % The display filter functions returns an image corresponding to the filter 3 | % display in spatial domain. 4 | % 5 | %% Usage 6 | % big_img=*display_filter_bank_2d*(filters, n, renorm) 7 | % 8 | %% Examples 9 | % The renormalization corresponds to a renormalization by the maximum 10 | % amplitude of the wavelet 11 | % 12 | % This displays the whole filter bank used in Fourier multiresolution. Here 13 | % n designs the size of the filter one wants to display. 14 | x = mandrill; 15 | [Wop, filters] = wavelet_factory_2d(size(x)); 16 | n = 30; 17 | renorm = 1; 18 | display_filter_bank_2d(filters, renorm, n); 19 | 20 | 21 | % This displays the whole filter bank used in Fourier multiresolution. 22 | % Here, the parameter n is not used. This displays the "h" and "g" filters for 23 | % the cascading algorithm. 24 | x = mandrill; 25 | [Wop, filters] = wavelet_factory_2d_pyramid(); 26 | renorm = 1; 27 | display_filter_bank_2d(filters, renorm, n); 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/display/demo_image_scat.m: -------------------------------------------------------------------------------- 1 | %% Introduction to *image_scat* 2 | % *image_scat* is a function to visualize scattering coefficients. It will 3 | % display the output of every path of the scattering. 4 | % 5 | %% Usage 6 | % output_image = *image_scat*(S); where *S* is the output of *scat*. 7 | % 8 | %% Example 9 | % The following code will produce 3 images. 10 | x = mandrill; 11 | [Wop,filters] = wavelet_factory_2d(size(x)); 12 | [S,U] = scat(x,Wop); 13 | image_scat(S); 14 | 15 | % They correspond to the resulting scattering coefficients of each paths 16 | % for each layer and each rotation. The legend indicates the path and the resolution. 17 | % These filters are normalized but the normalization can be removed by 18 | % modifying the option of image_scat. The caption can also be removed with 19 | % a specific option. 20 | % 21 | % To improve legibility, the image background behind the caption is 22 | % artificially enlightened. 23 | % 24 | % On the Figure 2 for instance, there is 2 different j. The first one 25 | % corresponds to the scale of the used wavelets whereas the second one 26 | % corresponds to the scale of the low-pass filter which is thus constant. 27 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/display/demo_plot_meta.m: -------------------------------------------------------------------------------- 1 | %% Demo of *plot_meta* 2 | % We show some examples on the use of *plot_meta*. It displays graphically 3 | % information about the scattering transform parameters. 4 | % 5 | %% Usage 6 | % *plot_meta*(S) and *plot_meta_layer*(meta, m, nb_row, nb_column) 7 | % 8 | %% Examples 9 | % 10 | % The p of legend corresponds to the different path. Each row is 11 | % corresponds to the meta of a layer, each column to a different parameter 12 | % indicated in the y-label. 13 | % 14 | x = mandrill; 15 | [Wop, filters] = wavelet_factory_2d(size(x)); 16 | [S, U] = scat(x, Wop); 17 | 18 | plot_meta(S); 19 | 20 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/filters/demo_bank_filters.m: -------------------------------------------------------------------------------- 1 | %% Creating a bank filter 2 | % In this demo, we will show how to build bank filter in spatial domain or 3 | % Fourier domain. 4 | % 5 | %% Reviewed functions 6 | % The following function will be demonstrated: 7 | %% 8 | % 9 | % # haar_filter_bank_2d_pyramid 10 | % # morlet_filter_bank_2d 11 | % # morlet_filter_bank_2d_pyramid 12 | % 13 | %% Demonstration 14 | % 15 | % Here are shown 4 examples of filters: 16 | 17 | x = mandrill; 18 | filters1=morlet_filter_bank_2d(size(x)); 19 | filters2=morlet_filter_bank_2d_pyramid(); 20 | filters3=haar_filter_bank_2d_pyramid(); 21 | 22 | % Then one can access to the filters(low-pass and high-pass) by accessing 23 | % the fields of 24 | filters1 25 | filters2 26 | filters3 27 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/filters/demo_individual_filter.m: -------------------------------------------------------------------------------- 1 | %% Creating one filter 2 | % In this demo, we will show how to build some filters in spatial domain or 3 | % Fourier domain. Gabor, Morlet and Gaussian filters are pointed out. 4 | % 5 | %% Reviewed functions 6 | % The following function will be demonstrated: 7 | %% 8 | % 9 | % # gabor_2d 10 | % # gaussian_2d 11 | % # morlet_2d_noDC 12 | % # morlet_2d_pyramid 13 | % 14 | %% Demonstration 15 | % 16 | % Here are shown 4 examples of filters: 17 | 18 | N=50; 19 | M=50; 20 | sigma=10; 21 | slant=3; 22 | theta=pi/3; 23 | xi=2; 24 | 25 | gab = gabor_2d(N, M, sigma, slant, xi, theta); 26 | morlet = morlet_2d_noDC(N, M, sigma, slant, xi, theta); 27 | morlet2 = morlet_2d_pyramid(N, M, sigma, slant, xi, theta); 28 | gaussian = gaussian_2d(N, M, sigma); 29 | subplot(2,2,1) 30 | imagesc(real(gab)); 31 | axis off 32 | title('Real part of Gabor wavelet in Fourier domain') 33 | subplot(2,2,2) 34 | imagesc(real(morlet)); 35 | axis off 36 | title('Real part of Morlet wavelet in Fourier domain') 37 | subplot(2,2,3) 38 | imagesc(real(morlet2)); 39 | axis off 40 | title('Real part of Morlet wavelet in Spatial domain') 41 | subplot(2,2,4) 42 | imagesc(gaussian); 43 | axis off 44 | title('Gaussian wavelet') 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/demo/scatutils/demo_format_scat.m: -------------------------------------------------------------------------------- 1 | %% Demo of *format_scat* 2 | 3 | %% Usage 4 | % [out,meta] = *format_scat*(S,fmt) (see 5 | % ). 6 | % 7 | %% Description 8 | % In this demo, we show how format_scat can be used to gather all 9 | % scattering coefficients into one single array, and visualize this array 10 | % using imagesc. 11 | % NB : so as to improve contrast, the colormap only ranges from 0 to 2, 12 | % setting all higher values in white. 13 | 14 | N = 65536; 15 | load handel; 16 | y = y(1:N); 17 | T = 4096; 18 | filt_opt = default_filter_options('audio', T); 19 | scat_opt.M = 2; 20 | [Wop, filters] = wavelet_factory_1d(N, filt_opt, scat_opt); 21 | S = scat(y, Wop); 22 | fmt = 'table'; % default format 23 | X = format_scat(S,fmt); 24 | 25 | figure; 26 | coefft = (1:size(X,1)); 27 | time = (1:size(X,2)) * T/Fs; 28 | imagesc(time,coefft,X); 29 | colormap bone; 30 | caxis([0 2]); % color thresholding improves contrast 31 | colorbar; 32 | xlabel('Time (seconds)'); 33 | ylabel('Coefficients'); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/display_filter_2d.m: -------------------------------------------------------------------------------- 1 | % DISPLAY_FILTER_2D Display and return the spatially centered cropped 2 | % version of a filter 3 | % 4 | % Usage 5 | % filt_for_disp = DISPLAY_FILTER_2D(filter, rorim, n) 6 | % 7 | % Input 8 | % filter (struct): a filter from a wavelet factory (for instance). 9 | % rorim (string): 'r' real part, 'i' imaginary part 10 | % n (numeric): size of the window, only for 'fourier_multires' type of 11 | % function 12 | % 13 | % Output 14 | % filt_for_disp (numerical): displayed (real) image. 15 | % 16 | % Description 17 | % Display the real or imaginary part of a filter and returns it. 18 | % 19 | % See also 20 | % WAVELET_FACTORY_2D, WAVELET_FACTORY_2D_PYRAMID 21 | 22 | function filt_for_disp = display_filter_2d(filter, rorim, n) 23 | if ~exist('rorim','var') 24 | rorim='r'; 25 | end 26 | 27 | switch filter.type 28 | case 'fourier_multires' 29 | filtf = filter.coefft{1}; 30 | [H, W] = size(filtf); 31 | filt = fftshift(ifft2(filtf)); 32 | filt_for_disp = (filt(floor(H/2)-n+1:floor(H/2)+n+1,floor(W/2)-n+1:floor(W/2)+n+1)); 33 | case 'spatial_support' 34 | filt_for_disp = filter.coefft; 35 | otherwise 36 | error('not yet supported'); 37 | end 38 | 39 | 40 | switch rorim 41 | case 'r' 42 | imagesc(real(filt_for_disp)); 43 | case 'i' 44 | imagesc(imag(filt_for_disp)); 45 | end 46 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/display_littlewood_paley_2d.m: -------------------------------------------------------------------------------- 1 | % DISPLAY_LITTLEWOOD_PALEY_2D Display Littlewood-Paley sum of a filter bank 2 | % 3 | % Usage 4 | % littlewood = display_littlewood_paley_2d(filters); 5 | % 6 | % Input 7 | % filters (struct): filter bank (see FILTER_BANK) 8 | % 9 | % Description 10 | % The function computes the Littlewood-Paley sum of the filter bank and 11 | % displays it. It also outputs the sum. 12 | % 13 | % See also 14 | % LITTLEWOOD_PALEY, PLOT_LITTLEWOOD_PALEY_1D, FILTER_BANK 15 | 16 | function littlewood = display_littlewood_paley_2d(filters) 17 | lp = littlewood_paley(filters); 18 | img = fftshift(lp); 19 | imagesc(img); 20 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/display_multifractal.m: -------------------------------------------------------------------------------- 1 | function display_multifractal(S,t0) 2 | clrs = {'r','g','b','c','k','m'}; 3 | 4 | S1 = [S{2}.signal{:}].'; 5 | S2 = [S{3}.signal{:}].'; 6 | 7 | subplot(121); 8 | plot(S1(:,t0)); 9 | title('m=1'); 10 | xlabel('j1'); 11 | 12 | j1s = unique(S{3}.meta.scale(:,1)).'; 13 | subplot(122); 14 | hold on 15 | for j1 = j1s 16 | plot(S2(S{3}.meta.scale(:,1)==j1,t0), ... 17 | clrs{mod(j1,length(clrs))+1}); 18 | end 19 | hold off 20 | title('m=2'); 21 | xlabel('j2-j1'); 22 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/image_complex.m: -------------------------------------------------------------------------------- 1 | function x_rgb = image_complex( x ) 2 | x = x/max(abs(x(:))); 3 | x_hsv(:,:,1) = (pi + angle(x))/(2*pi); 4 | x_hsv(:,:,2) = 1; 5 | x_hsv(:,:,3) = abs(x); 6 | x_rgb = hsv2rgb(x_hsv); 7 | end 8 | 9 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/image_scat.m: -------------------------------------------------------------------------------- 1 | % IMAGE_SCAT return scattering outputs images next to each other 2 | % 3 | % Usage 4 | % IMAGE_SCAT(S, renorm, dsp_legend) 5 | % 6 | % Input 7 | % Scatt (cell): layers of scattering (either U or S) 8 | % renorm (boolean): if 1 renormalize each path by its max. Default 9 | % value is set to 1. 10 | % dsp_legend (boolean): if set to 1, display legend. Default value is 1 11 | % 12 | % Description 13 | % Display the scattering coefficients in an image. Concerning the third 14 | % layer, thescattering coefficients are embeded next to each other in a 15 | % large image with their meta in the upper left hand corner 16 | % 17 | % See also 18 | % IMAGE_SCAT_LAYER, DISPLAY_WITH_LAYER_ORDER 19 | 20 | function image_scat(S, renorm, dsp_legend) 21 | for m = 1:numel(S); 22 | figure(m); 23 | switch (nargin) 24 | case 1 25 | big_img = image_scat_layer(S{m}); 26 | 27 | case 2 28 | big_img = image_scat_layer(S{m}, renorm); 29 | 30 | case 3 31 | big_img = image_scat_layer(S{m}, renorm, dsp_legend); 32 | 33 | end 34 | imagesc(big_img); 35 | end 36 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/meta2str.m: -------------------------------------------------------------------------------- 1 | function str = meta2str(meta,ind) 2 | % print a string resuming the meta at index ind 3 | str= []; 4 | endline_str = ' '; 5 | try 6 | fns = fieldnames(meta); 7 | catch 8 | fprintf('nometa \n') 9 | fns = {}; 10 | end 11 | for ifn = 1:numel(fns) 12 | 13 | 14 | nonumber = 0; 15 | fn = fns{ifn}; 16 | 17 | if ~(strcmp(fn,'res') || strcmp(fn,'res_rot')) 18 | 19 | vec = eval(['meta.',fn]); 20 | if (strcmp(fn,'theta1_downsampled')) 21 | fn = 'th1ds'; 22 | nonumber = 1; 23 | end 24 | if (strcmp(fn,'theta')) 25 | fn = 'th'; 26 | end 27 | if (strcmp(fn,'resolution')) 28 | fn = 'res'; 29 | end 30 | if (strcmp(fn,'theta2')) 31 | fn = 'th2'; 32 | nonumber = 1; 33 | end 34 | if (strcmp(fn,'k2')) 35 | fn = 'k2'; 36 | nonumber = 1; 37 | end 38 | if (strcmp(fn,'j') && size(vec,1)>2) 39 | vec = vec(1:2,:); % skip last J which is usualy constant 40 | end 41 | for i = 1:size(vec,1) 42 | if (nonumber) 43 | nb = ''; 44 | else 45 | nb =int2str(i) ; 46 | end 47 | str = [str,fn,nb,'=',int2str(vec(i,ind)),endline_str]; 48 | end 49 | 50 | end 51 | end 52 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/plot_diracnorm_scat.m: -------------------------------------------------------------------------------- 1 | % PlotNormScatt(x,Scatt) 2 | % Color plot of a normalized scattering representation 3 | % x gives the horizontal axis 4 | % nScatt is the normalized scattering tranform which is piecewise constant 5 | % The color on each interval depends upon the path length: 6 | % 0 is yellow, 1 is red, 2 is green 3 is blue, 4 is magenta 7 | 8 | function plot_diracnorm_scat(x,nScatt) 9 | color(1) = 'y'; 10 | color(2) = 'r'; 11 | color(3) = 'g'; 12 | color(4) = 'b'; 13 | color(5) = 'm'; 14 | color(6) = 'k'; 15 | color(7:99) = 'k'; 16 | 17 | N=size(x,2); 18 | 19 | n=1; 20 | while(n Y(2)) 36 | m = (round(10^(7) * y - 10 * floor(Y(1) * 10^(6))))+1; 37 | end 38 | plot(X,Y.^2,color(m)); 39 | 40 | end 41 | hold off; 42 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/scatter_meta.m: -------------------------------------------------------------------------------- 1 | % scatter_meta : Scatter two different meta field of scattering 2 | % 3 | % Usage : 4 | % scatter_meta(S{3}, 'j', 1, 'j', 2) will draw a scatter plot 5 | % where each point corresponds to a scattering path, the x axis 6 | % corresponds to j1, the y axis corresponds to j2 7 | function scatter_meta(meta, field_name_1, id1, field_name_2, id2) 8 | 9 | vec2plot=eval(['meta.',field_name_1]); 10 | vec2plot = vec2plot(id1,:); 11 | 12 | vec2plot2=eval(['meta.',field_name_2]); 13 | vec2plot2 = vec2plot2(id2,:); 14 | 15 | scatter(vec2plot,vec2plot2); 16 | 17 | 18 | xlabel([field_name_1,int2str(id1)]); 19 | ylabel([field_name_2,int2str(id2)]); 20 | end 21 | 22 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/scattergram_layer.m: -------------------------------------------------------------------------------- 1 | %SCATTERGRAM_LAYER Formats a one-dimensional layer as an image 2 | % Usages 3 | % img = scattergram_layer(X,[]) 4 | % 5 | % img = scattergram_layer(X,j) 6 | % 7 | % Input 8 | % X (struct): a scattering representation layer 9 | % j (integer array): a vector of scale indexes 10 | % 11 | % Output 12 | % img (numeric): a two-dimensional array of scattering coefficients, 13 | % indexed by scale and time 14 | % 15 | % Description 16 | % This function is called by SCATTERGRAM, layer by layer, in order to 17 | % provide a time-frequency visualisation of scattering coefficients. 18 | % 19 | % See also 20 | % SCATTERGRAM 21 | 22 | 23 | function img = scattergram_layer(X,j) 24 | if all(size(j)==[0 0]) 25 | j = zeros(0,1); 26 | end 27 | 28 | nbTimePt = max(cellfun(@(x)(size(x,1)), X.signal)); 29 | 30 | max_jm = max(X.meta.j(end,:)+1); 31 | 32 | img = -Inf*ones(max_jm, nbTimePt); 33 | 34 | ind = find(all(bsxfun(@eq,X.meta.j(1:end-1,:),j),1)); 35 | 36 | signal = cellfun(@(x)(interpft(x,nbTimePt)), ... 37 | X.signal(ind),'UniformOutput',false); 38 | 39 | img(X.meta.j(end,ind)+1,:) = [signal{:}].'; 40 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/display/str2imfast.m: -------------------------------------------------------------------------------- 1 | function bigimg = str2imfast(str) 2 | load 'all_char.mat' 3 | bigimg = zeros(11,9*numel(str)); 4 | for c = 1:numel(str); 5 | cc = str(c); 6 | ii = unicode2native(cc); 7 | if numel(img_db{ii}>0) 8 | im = img_db{ii}; 9 | bigimg((1:11),(1:9) + (c-1)*9) = im; 10 | 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/doc/arch/arch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/doc/arch/arch.pdf -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/doc/gaussian_filters.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/doc/gaussian_filters.pdf -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/doc/impl/impl.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/doc/impl/impl.pdf -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/dyadic_freq_1d.m: -------------------------------------------------------------------------------- 1 | % DYADIC_FREQ_1D Compute center frequencies and bandwidths for the 1D Dyadic 2 | % 3 | % Usage 4 | % [psi_xi, psi_bw, phi_bw] = DYADIC_FREQ_1D(filt_opt) 5 | % 6 | % Input 7 | % filt_opt (struct): The parameters defining the filter bank. For example, 8 | % see SPLINE_FILTER_BANK_1D for details. 9 | % 10 | % Output 11 | % psi_xi (numeric): The center frequencies of the wavelet filters. 12 | % psi_bw (numeric): The bandwidths of the wavelet filters. 13 | % phi_bw (numeric): The bandwidth of the lowpass filter. 14 | % 15 | % Description 16 | % Compute the center frequencies and bandwidth for the wavelets and lowpass 17 | % filter of the one-dimensional dyadic filter bank, such as 18 | % SPLINE_FILTER_BANK_1D. 19 | % 20 | % See also 21 | % FILTER_FREQ, MORLET_FREQ_1D 22 | 23 | function [psi_xi, psi_bw, phi_bw] = dyadic_freq_1d(filter_options) 24 | xi0 = 3*pi/4; 25 | 26 | psi_xi = xi0.*2.^(-[0:filter_options.J-1]); 27 | psi_bw = pi/2.*2.^(-[0:filter_options.J-1]); 28 | 29 | phi_bw = pi*2^(-[filter_options.J-1]); 30 | end 31 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/filter_freq.m: -------------------------------------------------------------------------------- 1 | % FILTER_FREQ Calculate center frequencies and bandwidths 2 | % 3 | % Usage 4 | % [psi_xi, psi_bw, phi_bw] = FILTER_FREQ(filt_opt) 5 | % 6 | % Input 7 | % filt_opt (struct): The parameters defining the filter bank. 8 | % 9 | % Output 10 | % psi_xi (numeric): The center frequencies of the wavelet filters. 11 | % psi_bw (numeric): The bandwidths of the wavelet filters. 12 | % phi_bw (numeric): The bandwidth of the lowpass filter. 13 | % 14 | % Description 15 | % Called by WAVELET_1D and WAVELET_LAYER_1D, this function provides the 16 | % center frequency and bandwidth of a mother wavelet, whose parameters 17 | % are specified in filt_opt. It operates as a mere disjunction between 18 | % SPLINE_FREQ_1D, and MORLET_FREQ_1D. 19 | % 20 | % See also 21 | % MORLET_FREQ_1D, SPLINE_FREQ_1D, WAVELET_1D, WAVELET_LAYER_1D 22 | 23 | function [psi_xi, psi_bw, phi_bw] = filter_freq(filter_options) 24 | if strcmp(filter_options.filter_type,'spline_1d') || ... 25 | strcmp(filter_options.filter_type,'selesnick_1d') 26 | [psi_xi,psi_bw,phi_bw] = dyadic_freq_1d(filter_options); 27 | elseif strcmp(filter_options.filter_type,'morlet_1d') || ... 28 | strcmp(filter_options.filter_type,'gabor_1d') 29 | [psi_xi,psi_bw,phi_bw] = morlet_freq_1d(filter_options); 30 | else 31 | error('Unknown filter type ''%s''', filter_options.filter_type); 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/gaussian_2d.m: -------------------------------------------------------------------------------- 1 | % GAUSSIAN_2D computes a Gaussian function. 2 | % 3 | % Usage 4 | % gau = GAUSSIAN_2D(N, M, sigma, precision, offset) 5 | % 6 | % Input 7 | % N (numeric): width of the filter matrix 8 | % M (numeric): height of the filter matrix 9 | % sigma (numeric): standard deviation of the Gaussian 10 | % precision (string): 'single' or 'double' 11 | % offset (numeric): 2-by-1 Vvector index of the row and column of the 12 | % center of the filter (if offset is [0,0] the filter is centered in 13 | % [1,1]) 14 | % 15 | % Output 16 | % gau (numeric): N-by-M Gaussian function 17 | % 18 | % Description 19 | % Computes a Gaussian centered in offset and of standard deviation 20 | % sigma. 21 | 22 | function gau = gaussian_2d(N, M, sigma, precision, offset) 23 | if ~exist('precision', 'var') 24 | precision = 'single'; 25 | end 26 | 27 | if (~exist('offset', 'var')) 28 | offset = [floor(N/2), floor(M/2)]; 29 | end 30 | 31 | [x , y] = meshgrid(1:M, 1:N); 32 | 33 | x = x - offset(2) - 1; 34 | y = y - offset(1) - 1; 35 | 36 | gau = 1/(2*pi*sigma^2) * exp( -(x.^2+y.^2)./(2*sigma^2) ); 37 | 38 | if (strcmp(precision, 'single')) 39 | gau = single(gau); 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/littlewood_paley.m: -------------------------------------------------------------------------------- 1 | % LITTLEWOOD_PALEY Calculate Littlewood-Paley sum of a filter bank 2 | % 3 | % Usage 4 | % A = littlewood_paley(filters, N); 5 | % 6 | % Input 7 | % filters (struct): filter bank (see FILTER_BANK) 8 | % N (vector, optional): the signal size at which the sum should be 9 | % calculated 10 | % 11 | % Description 12 | % The function computes the Littlewood-Paley sum of the filter bank at the 13 | % signal size N, which needs to be of the form filters.meta.size_filter*2^(-j0), where 14 | % filters.N is the size for which the filters are defined. 15 | % 16 | % See also 17 | % PLOT_LITTLEWOOD_PALEY_1D, DISPLAY_LITTLEWOOD_PALEY_2D, FILTER_BANK 18 | 19 | function energy = littlewood_paley(filters,N) 20 | if nargin < 2 21 | N = []; 22 | end 23 | 24 | if isempty(N) && isfield(filters,'meta') && isfield(filters.meta,'size_filter') 25 | N = filters.meta.size_filter; 26 | else 27 | error('Unable to find max filter size!'); 28 | end 29 | 30 | if length(N) == 1 31 | N = [N 1]; 32 | end 33 | 34 | energy = zeros(N); 35 | for p = 1:numel(filters.psi.filter) 36 | filter_coefft = realize_filter(filters.psi.filter{p},N); 37 | energy = energy + abs(filter_coefft.^2); 38 | end 39 | 40 | energy = 0.5*(energy + circshift(rot90(energy,2), [1, 1])); 41 | 42 | filter_coefft = realize_filter(filters.phi.filter,N); 43 | energy = energy + abs(filter_coefft.^2); 44 | end 45 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/rotation_matrix_2d.m: -------------------------------------------------------------------------------- 1 | % ROTATION_MATRIX_2D computes a 2-by-2 rotation matrix for a given angle 2 | % 3 | % Usage 4 | % rotmat = ROTATION_MATRIX_2D(theta) 5 | % 6 | % Input 7 | % theta (numeric): the angle of the rotation 8 | % 9 | % Ouput 10 | % rotmat (numeric): 2-by-2 rotation matrix corresponding to the axis con- 11 | % vention of matlab for image coordinates 12 | 13 | function rotmat = rotation_matrix_2d(theta) 14 | rotmat=[cos(theta) sin(theta) ; - sin(theta) cos(theta) ]; 15 | end 16 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/FSfarras.m: -------------------------------------------------------------------------------- 1 | function [af, sf] = FSfarras 2 | 3 | % Farras filters organized for the dual-tree 4 | % complex DWT. 5 | % 6 | % USAGE: 7 | % [af, sf] = FSfarras 8 | % OUTPUT: 9 | % af{i}, i = 1,2 - analysis filters for tree i 10 | % sf{i}, i = 1,2 - synthesis filters for tree i 11 | % See farras, dualtree, dualfilt1. 12 | % 13 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 14 | % http://taco.poly.edu/WaveletSoftware/ 15 | 16 | af{1} = [ 17 | 0 0 18 | -0.08838834764832 -0.01122679215254 19 | 0.08838834764832 0.01122679215254 20 | 0.69587998903400 0.08838834764832 21 | 0.69587998903400 0.08838834764832 22 | 0.08838834764832 -0.69587998903400 23 | -0.08838834764832 0.69587998903400 24 | 0.01122679215254 -0.08838834764832 25 | 0.01122679215254 -0.08838834764832 26 | 0 0 27 | ]; 28 | 29 | sf{1} = af{1}(end:-1:1, :); 30 | 31 | af{2} = [ 32 | 0.01122679215254 0 33 | 0.01122679215254 0 34 | -0.08838834764832 -0.08838834764832 35 | 0.08838834764832 -0.08838834764832 36 | 0.69587998903400 0.69587998903400 37 | 0.69587998903400 -0.69587998903400 38 | 0.08838834764832 0.08838834764832 39 | -0.08838834764832 0.08838834764832 40 | 0 0.01122679215254 41 | 0 -0.01122679215254 42 | ]; 43 | 44 | sf{2} = af{2}(end:-1:1, :); 45 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/afb.m: -------------------------------------------------------------------------------- 1 | function [lo, hi] = afb(x, af) 2 | 3 | % Analysis filter bank 4 | % 5 | % USAGE: 6 | % [lo, hi] = afb(x, af) 7 | % INPUT: 8 | % x - N-point vector, where 9 | % 1) N is even 10 | % 2) N >= length(af) 11 | % af - analysis filters 12 | % af(:, 1) - lowpass filter (even length) 13 | % af(:, 2) - highpass filter (even length) 14 | % OUTPUT: 15 | % lo - Low frequecy output 16 | % hi - High frequency output 17 | % EXAMPLE: 18 | % [af, sf] = farras; 19 | % x = rand(1,64); 20 | % [lo, hi] = afb(x, af); 21 | % y = sfb(lo, hi, sf); 22 | % err = x - y; 23 | % max(abs(err)) 24 | % 25 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 26 | % http://taco.poly.edu/WaveletSoftware/ 27 | 28 | N = length(x); 29 | L = length(af)/2; 30 | x = cshift(x,-L); 31 | 32 | % lowpass filter 33 | lo = upfirdn(x, af(:,1), 1, 2); 34 | lo(1:L) = lo(N/2+[1:L]) + lo(1:L); 35 | lo = lo(1:N/2); 36 | 37 | % highpass filter 38 | hi = upfirdn(x, af(:,2), 1, 2); 39 | hi(1:L) = hi(N/2+[1:L]) + hi(1:L); 40 | hi = hi(1:N/2); 41 | 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/cshift.m: -------------------------------------------------------------------------------- 1 | function y = cshift(x, m) 2 | 3 | % Circular Shift 4 | % 5 | % USAGE: 6 | % y = cshift(x, m) 7 | % INPUT: 8 | % x - N-point vector 9 | % m - amount of shift 10 | % OUTPUT: 11 | % y - vector x will be shifed by m samples to the left 12 | % 13 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 14 | % http://taco.poly.edu/WaveletSoftware/ 15 | 16 | N = length(x); 17 | n = 0:N-1; 18 | n = mod(n-m, N); 19 | y = x(n+1); 20 | 21 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/dualtree.m: -------------------------------------------------------------------------------- 1 | function w = dualtree(x, J, Faf, af) 2 | 3 | % Dual-tree Complex Discrete Wavelet Transform 4 | % 5 | % USAGE: 6 | % w = dualtree(x, J, Faf, af) 7 | % INPUT: 8 | % x - N-point vector 9 | % 1) N is divisible by 2^J 10 | % 2) N >= 2^(J-1)*length(af) 11 | % J - number of stages 12 | % Faf - filters for the first stage 13 | % af - filters for the remaining stages 14 | % OUTPUT: 15 | % w - DWT coefficients 16 | % w{j}{1}, j = 1..J - real part 17 | % w{j}{2}, j = 1..J - imaginary part 18 | % w{J+1}{d} - lowpass coefficients, d = 1,2 19 | % EXAMPLE: 20 | % x = rand(1, 512); 21 | % J = 4; 22 | % [Faf, Fsf] = FSfarras; 23 | % [af, sf] = dualfilt1; 24 | % w = dualtree(x, J, Faf, af); 25 | % y = idualtree(w, J, Fsf, sf); 26 | % err = x - y; 27 | % max(abs(err)) 28 | % 29 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 30 | % http://taco.poly.edu/WaveletSoftware/ 31 | 32 | % normalization 33 | x = x/sqrt(2); 34 | 35 | % Tree 1 36 | [x1 w{1}{1}] = afb(x, Faf{1}); 37 | for j = 2:J 38 | [x1 w{j}{1}] = afb(x1, af{1}); 39 | end 40 | w{J+1}{1} = x1; 41 | 42 | % Tree 2 43 | [x2 w{1}{2}] = afb(x, Faf{2}); 44 | for j = 2:J 45 | [x2 w{j}{2}] = afb(x2, af{2}); 46 | end 47 | w{J+1}{2} = x2; 48 | 49 | 50 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/idualtree.m: -------------------------------------------------------------------------------- 1 | function y = idualtree(w, J, Fsf, sf) 2 | 3 | % Inverse Dual-tree Complex DWT 4 | % 5 | % USAGE: 6 | % y = idualtree(w, J, Fsf, sf) 7 | % INPUT: 8 | % w - DWT coefficients 9 | % J - number of stages 10 | % Fsf - synthesis filters for the last stage 11 | % sf - synthesis filters for preceeding stages 12 | % OUTUT: 13 | % y - output signal 14 | % See dualtree 15 | % 16 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 17 | % http://taco.poly.edu/WaveletSoftware/ 18 | 19 | % Tree 1 20 | y1 = w{J+1}{1}; 21 | for j = J:-1:2 22 | y1 = sfb(y1, w{j}{1}, sf{1}); 23 | end 24 | y1 = sfb(y1, w{1}{1}, Fsf{1}); 25 | 26 | % Tree 2 27 | y2 = w{J+1}{2}; 28 | for j = J:-1:2 29 | y2 = sfb(y2, w{j}{2}, sf{2}); 30 | end 31 | y2 = sfb(y2, w{1}{2}, Fsf{2}); 32 | 33 | % normalization 34 | y = (y1 + y2)/sqrt(2); 35 | 36 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/selesnick_bis.m: -------------------------------------------------------------------------------- 1 | function outf= selesnick_bis(sizein, options) 2 | 3 | J=getoptions(options,'J',10); 4 | 5 | % get filters 6 | [Faf, Fsf] = FSfarras; 7 | [af, sf] = dualfilt1; 8 | 9 | 10 | sizebis=sizein; 11 | sizebis(1)=2^(floor(log2(sizein(1)))); 12 | 13 | padn=(sizein(1)-sizebis(1))/2; 14 | 15 | x = zeros(sizebis); % zero signal 16 | % Compute dual-tree complex DWT of zero signal 17 | w = dualtree(x, J, Faf, af); 18 | 19 | for j=1:J+1 20 | 21 | L=length(w{j}{1}); 22 | % Set a single (real) coefficient to 1 23 | w{j}{1}(round(L/2)) = 1; 24 | % Compute the inverse transform 25 | y1 = idualtree(w, J, Fsf, sf); 26 | w{j}{1}(round(L/2)) = 0; 27 | 28 | % Set a single (imaginary) coefficient to 1 29 | w{j}{2}(round(L/2)) = 1; 30 | % Compute the inverse transform 31 | y2 = idualtree(w, J, Fsf, sf); 32 | w{j}{2}(round(L/2)) = 0; 33 | 34 | aux = padarray(y1 + 1i*y2,padn); 35 | aux = 2^(-j/2)* fftshift(aux); 36 | if j <= J 37 | outf.psi{1}{j}{1} = fft(aux); 38 | else 39 | outf.phi = fft(aux); 40 | end 41 | 42 | end 43 | 44 | 45 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/filters/selesnick/sfb.m: -------------------------------------------------------------------------------- 1 | function y = sfb(lo, hi, sf) 2 | 3 | % Synthesis filter bank 4 | % 5 | % USAGE: 6 | % y = sfb(lo, hi, sf) 7 | % INPUT: 8 | % lo - low frqeuency input 9 | % hi - high frequency input 10 | % sf - synthesis filters 11 | % sf(:, 1) - lowpass filter (even length) 12 | % sf(:, 2) - highpass filter (even length) 13 | % OUTPUT: 14 | % y - output signal 15 | % See also afb 16 | % 17 | % WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY 18 | % http://taco.poly.edu/WaveletSoftware/ 19 | 20 | N = 2*length(lo); 21 | L = length(sf); 22 | lo = upfirdn(lo, sf(:,1), 2, 1); 23 | hi = upfirdn(hi, sf(:,2), 2, 1); 24 | y = lo + hi; 25 | y(1:L-2) = y(1:L-2) + y(N+[1:L-2]); 26 | y = y(1:N); 27 | y = cshift(y, 1-L/2); 28 | 29 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/DSS_Figure2.m: -------------------------------------------------------------------------------- 1 | % Generate Figure 2 of the "Deep Scattering Spectrum" paper. 2 | 3 | % Load signal (music). 4 | x = wavread('kodaly.wav'); 5 | 6 | % Prepare filters. 7 | filt_opt.B = 8; 8 | filt_opt.Q = 4*filt_opt.B; 9 | filt_opt.J = T_to_J(4096, filt_opt); 10 | filt_opt.boundary = 'per'; 11 | 12 | filters = filter_bank(length(x), filt_opt); 13 | 14 | % Extract Fourier transform of filters and assemble into a table. 15 | psi_f = cellfun(@realize_filter, filters{1}.psi.filter, 'UniformOutput', 0); 16 | psi_f = [psi_f{:}]; 17 | 18 | % Calculate the Fourier transform of the squared lowpass filter. 19 | phi2 = fft(abs(ifft(realize_filter(filters{1}.phi.filter))).^2); 20 | phi2 = phi2/phi2(1); 21 | 22 | % Calculate the scalogram - amplitude of filter bank responses - and square. 23 | xt1 = abs(ifft(bsxfun(@times, fft(x), psi_f))).^2; 24 | 25 | % Smooth the squared scalogram using the square lowpass filter. 26 | xt2 = ifft(bsxfun(@times, fft(xt1), phi2)); 27 | 28 | % We only need to see the highest seven octaves. 29 | xt1 = xt1(:,1:7*filt_opt.Q); 30 | xt2 = xt2(:,1:7*filt_opt.Q); 31 | 32 | % Compute the logarithm. 33 | xt1 = log(xt1+1e-6); 34 | xt2 = log(xt2+1e-6); 35 | 36 | % Display the representations. 37 | figure(2); 38 | subplot(121); 39 | imagesc(xt1.'); 40 | set(gca,'XTick',[]); 41 | set(gca,'YTick',[]); 42 | subplot(122); 43 | imagesc(xt2.'); 44 | set(gca,'XTick',[]); 45 | set(gca,'YTick',[]); 46 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/DSS_Figure3.m: -------------------------------------------------------------------------------- 1 | % Generate Figure 3 of the "Deep Scattering Spectrum" paper. 2 | 3 | % Set up filter options. 4 | N = 2^10; 5 | filt_opt.filter_type = 'morlet_1d'; 6 | filt_opt.Q = 8; 7 | filt_opt.J = T_to_J(128, filt_opt); 8 | 9 | % Create filter bank. 10 | filters = filter_bank(N, filt_opt); 11 | 12 | % Extract wavelets psi in Fourier domain. 13 | psi_f = cellfun(@realize_filter, filters{1}.psi.filter, 'UniformOutput', 0); 14 | psi_f = [psi_f{:}]; 15 | 16 | % Extract lowpass phi in Fourier domain. 17 | phi_f = realize_filter(filters{1}.phi.filter); 18 | 19 | % Set up figure dimensions. 20 | fig_width = 3.5; 21 | fig_height = 0.6; 22 | figure(3); 23 | clf; 24 | set(gcf, 'PaperSize', [fig_width fig_height]); 25 | set(gcf, 'PaperPosition', [3 3 fig_width fig_height]); 26 | set(gcf, 'Units', 'inches'); 27 | set(gcf, 'Position', [3 3 fig_width fig_height]); 28 | axes('Units', 'inches', ... 29 | 'Position', [0.05 0.05 fig_width-0.1 fig_height-0.1]); 30 | 31 | % Plot psis and phi. 32 | figure(3); 33 | plot(1:size(psi_f,1), phi_f, 'r', ... 34 | 1:size(psi_f,1),psi_f,'b'); 35 | 36 | % Set axis ranges. 37 | ylim([0 max(psi_f(:))*1.2]); 38 | xlim([1 size(psi_f,1)/2*1.1]); 39 | 40 | % Remove axis ticks. 41 | set(gca,'XTick',[]); 42 | set(gca,'YTick',[]); 43 | 44 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/DSS_Figure6.m: -------------------------------------------------------------------------------- 1 | % Generate Figure 6 of the "Deep Scattering Spectrum" paper. 2 | 3 | % Load the signal. 4 | x = wavread('chord_signal.wav'); 5 | 6 | % Prepare the filters and scattering operators. 7 | filt_opt.filter_type = {'gabor_1d','morlet_1d'}; 8 | filt_opt.B = [4 4]; 9 | filt_opt.Q = 4*filt_opt.B; 10 | filt_opt.J = T_to_J([256 32768],filt_opt); 11 | 12 | scat_opt.oversampling = 8; 13 | scat_opt.M = 2; 14 | 15 | Wop = wavelet_factory_1d(length(x), filt_opt, scat_opt); 16 | 17 | % Compute scattering coefficients. 18 | [S, U] = scat(x, Wop); 19 | 20 | % Renormalize coefficients. 21 | epsilon = 1e-2; 22 | S = renorm_scat(S, epsilon); 23 | S = renorm_1st_phi(S, U, Wop, epsilon); 24 | 25 | % Compute the logarithm. 26 | S = log_scat(S,1e-3); 27 | U = log_scat(U,1e-3); 28 | 29 | % Display scalogram U{2}, first-order coefficients S{2} and second-order 30 | % coefficients S{3} for j1 = 58. 31 | figure(6); 32 | scattergram(U{2}, [], S{2}, [], S{3}, 58); 33 | 34 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/DSS_Figure7.m: -------------------------------------------------------------------------------- 1 | % Generate Figure 7 of the "Deep Scattering Spectrum" paper. 2 | 3 | % Load the signal. 4 | x = wavread('mod_signal.wav'); 5 | 6 | % Prepare the filters and scattering operators. 7 | filt_opt.filter_type = {'gabor_1d','morlet_1d'}; 8 | filt_opt.B = [8 4]; 9 | filt_opt.Q = 8*filt_opt.B; 10 | filt_opt.J = T_to_J([256 4096],filt_opt); 11 | 12 | scat_opt.oversampling = 6; 13 | scat_opt.M = 2; 14 | 15 | Wop = wavelet_factory_1d(length(x), filt_opt, scat_opt); 16 | 17 | % Compute scattering coefficients. 18 | [S, U] = scat(x, Wop); 19 | 20 | % Renormalize coefficients. 21 | epsilon = 1e-3; 22 | S = renorm_scat(S, epsilon); 23 | S = renorm_1st_phi(S, U, Wop, epsilon); 24 | 25 | % Compute the logarithm. 26 | S = log_scat(S,1e-3); 27 | U = log_scat(U,1e-3); 28 | 29 | % Display scalogram U{2}, first-order coefficients S{2} and second-order 30 | % coefficients S{3} for j1 = 110. 31 | figure(7); 32 | scattergram(U{2}, [], S{2}, [], S{3}, 110); 33 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/DSS_Table1.m: -------------------------------------------------------------------------------- 1 | super = 2; 2 | opt.filter_type = {'morlet_1d','spline_1d'}; 3 | opt.B = [8 1]; 4 | opt.Q = [super*8 1]; 5 | opt.filter_format = 'fourier_truncated'; 6 | M = 3; 7 | 8 | Js = [9:2:15]; 9 | 10 | N = 2^17; 11 | 12 | src = phone_src('/path/to/timit'); 13 | files = src.files; 14 | rs = RandStream.create('mt19937ar','Seed',floor(pi*1e9)); 15 | files = files(rs.randperm(length(files))); 16 | 17 | scat_opt.M = M; 18 | scat_opt.oversampling = 2; 19 | 20 | for l = 1:length(Js) 21 | opts{l} = opt; 22 | 23 | opts{l}.J = T_to_J(2^Js(l),opts{l}); 24 | 25 | [Wop{l},filters{l}] = wavelet_factory_1d(N, opts{l}, scat_opt); 26 | end 27 | 28 | E = zeros(length(Js),M+1,length(files)); 29 | 30 | for k = 1:length(files) 31 | fprintf('%s\n',files{k}); 32 | x = data_read(files{k}); 33 | x = x(1:min(N,length(x))); 34 | x = [x; zeros(N-length(x),1)]; 35 | x = x-mean(x); 36 | x = x/sqrt(sum(abs(x(:)).^2)); 37 | for l = 1:length(Js) 38 | [t,meta] = format_scat(scat(x,Wop{l})); 39 | 40 | t = squeeze(t); 41 | for m = 0:max(meta.order) 42 | t1 = t(meta.order==m,:); 43 | E(l,m+1,k) = sum(abs(t1(:)).^2); 44 | end 45 | end 46 | mean(E(:,:,1:k),3) 47 | end 48 | 49 | % At the end, we should have 50 | % 0.0000 0.9453 0.0484 0.0023 51 | % 0.0000 0.6800 0.2900 0.0191 52 | % 0.0000 0.3486 0.5325 0.1156 53 | % 0.0000 0.2772 0.5607 0.2471 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/chord_signal.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/chord_signal.wav -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/dilation.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/dilation.wav -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/gtzan_src.m: -------------------------------------------------------------------------------- 1 | % GTZAN_SRC Creates a source for the GTZAN dataset 2 | % 3 | % Usage 4 | % src = GTZAN_SRC(directory, N) 5 | % 6 | % Input 7 | % directory (char): The directory containing the GTZAN dataset. 8 | % N (int): The size to which the audio files are to be truncated (default 9 | % 5*2^17). 10 | % 11 | % Output 12 | % src (struct): The GTZAN source. 13 | % 14 | % Description 15 | % Creates a source index for the GTZAN dataset (available at 16 | % http://marsyasweb.appspot.com/download/data_sets/) that can be used for 17 | % calculating a feature database and classifying musical genres. 18 | % 19 | % See also 20 | % CREATE_SRC 21 | 22 | function src = gtzan_src(directory,N) 23 | if nargin < 1 24 | directory = 'gtzan'; 25 | end 26 | 27 | if nargin < 2 28 | N = 5*2^17; 29 | end 30 | 31 | src = create_src(directory,@(file)(gtzan_objects_fun(file,N))); 32 | end 33 | 34 | function [objects,classes] = gtzan_objects_fun(file,N) 35 | objects.u1 = 1; 36 | objects.u2 = N; 37 | 38 | path_str = fileparts(file); 39 | 40 | path_parts = regexp(path_str,filesep,'split'); 41 | 42 | classes = {path_parts{end}}; 43 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/kodaly.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/kodaly.wav -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/mod_signal.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/mod_signal.wav -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/phone_partition.m: -------------------------------------------------------------------------------- 1 | % PHONE_PARTITION Specifies training, testing and development sets for TIMIT 2 | % 3 | % Usage 4 | % [train_set, test_set, dev_set] = PHONE_PARTITION(src) 5 | % 6 | % Input 7 | % src (struct): The TIMIT phone source, as obtained from PHONE_SRC. 8 | % 9 | % Output 10 | % train_set (int): The standard training set (TRAIN). 11 | % test_set (int): The core testing set (TEST, 24 speakers). 12 | % dev_set (int): The standard development set (TEST, 50 speakers). 13 | % 14 | % Description: 15 | % Extracts the indices of the phones in src in the standard TRAIN set, the 16 | % core TEST set of 24 speakers, and the standard development set in TEST 17 | % consisting of 50 speakers [1]. 18 | % 19 | % Note that if src does not contain all the phrases in the relevant sets, 20 | % phone_partition only extracts those phones that are present. 21 | % 22 | % References 23 | % [1] A. K. Halberstadt, “Heterogeneous acoustic measurements and multiple 24 | % classifiers for speech recognition,” Ph.D. dissertation, Massachusetts 25 | % Institute of Technology, 1998. 26 | % 27 | % See also 28 | % CREATE_PARTITION, PHONE_SRC 29 | 30 | function [train_set, test_set, dev_set] = phone_partition(src) 31 | train_set = find([src.objects.subset]==0); 32 | test_set = find([src.objects.subset]==1); 33 | dev_set = find([src.objects.subset]==2); 34 | end 35 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/questions.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/questions.wav -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/DSS/renorm_1st_phi.m: -------------------------------------------------------------------------------- 1 | function S = renorm_1st_phi(S,U,Wop,epsilon) 2 | U0p = U{1}; 3 | U0p.signal{1} = abs(U0p.signal{1}); 4 | S1 = Wop{2}(U0p); 5 | S1 = S1.signal{1}; 6 | sub_multiplier = 2^(S{2}.meta.resolution(1)/2); 7 | S{2}.signal = cellfun(@(x)(x./(S1+epsilon*sub_multiplier)),S{2}.signal,'UniformOutput',0); 8 | end 9 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/GIS/multi_J_scatter.m: -------------------------------------------------------------------------------- 1 | function mScatt=multi_J_Scatter(sig,fparam,options,Jmax) 2 | %Compute the scattering vector for all the J such that 1<=J<=Jmax. Note 3 | %that no values of J has been defined in fparam (no fparam.J) and that the 4 | %filters used with these functions will most of the time be cubic spline 5 | %wavelets. 6 | 7 | N=length(sig); 8 | Wops=cell(Jmax,1); 9 | 10 | for k=1:Jmax 11 | fparam.J=k; 12 | options.M = fparam.J; 13 | Wops{k} = wavelet_factory_1d(N, fparam, options); 14 | end 15 | 16 | mScatt=zeros(Jmax+1,2*N); 17 | mScatt(1,1:N)=sig; 18 | 19 | 20 | for p=2:Jmax+1 21 | 22 | tScatt=reorderScatt(scat(sig,Wops{p-1})); 23 | 24 | mScatt(p,:)=tScatt; 25 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/.generate_figures.m.swn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/.generate_figures.m.swn -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/.generate_figures.m.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/.generate_figures.m.swo -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/example_facile.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %this script produces the figures of the paper scattering_fractal_analysis 4 | %september 2013 5 | %Joan Bruna 6 | % 7 | % 8 | 9 | 10 | close all; 11 | %clear all; 12 | %startup; 13 | 14 | clear filt_opt; 15 | clear scat_opt; 16 | %set the maximum analysis scale 17 | filt_opt.J = 14; 18 | filt_opt.filter_format='fourier'; 19 | %size of realizations 20 | N=2^(4+filt_opt.J); 21 | 22 | %choose the wavelet 23 | filt_opt.filter_type='selesnick_1d'; 24 | %filt_opt.filter_type='morlet_1d'; 25 | scat_opt.M=2; 26 | 27 | scat_opt.path_margin= Inf; 28 | [Wop, filters]=wavelet_factory_1d(N,filt_opt,scat_opt); 29 | 30 | R=4; 31 | options.Wop=Wop; 32 | options.J=filt_opt.J; 33 | 34 | poisson=@(alpha) (cumsum(double(rand(N,1) < N^(-alpha)))); 35 | dpoisson=@(alpha) ((double(rand(N,1) < N^(-alpha)))); 36 | 37 | [S{1},T{1},Tu{1},ex{1}] = scat_renorm_1d_scatnet(dpoisson, 0.6, options, R); 38 | 39 | figure 40 | plot_full_transfer(log2(T{1})); 41 | 42 | oldopts.J=14; 43 | oldopts.filters=selesnick_bis([N 1], oldopts); 44 | oldopts.fullscatt=1; 45 | oldopts.oversampling=oldopts.J; 46 | [S{2},T{2},Tu{2},ex{2}] = scatt_renorm_estimation(dpoisson, 0.6, oldopts, R); 47 | 48 | figure 49 | plot_full_transfer(log2(T{2})); 50 | 51 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/fGnsimu.m: -------------------------------------------------------------------------------- 1 | % Simulates a fractional gaussian noise of size N and Hurst exponent H 2 | % Returns the vector B^H(1) - B^H(0), ..., B^H(size) - B^H(size-1) where B^H is a fractional Brownian motion with Hurst exponent H 3 | function x = fGnsimu(N,H) 4 | 5 | correl = .5*((0:N-1).^(2*H) + (2:N+1).^(2*H) - 2*(1:N).^(2*H)); 6 | x =gaussprocess([1 correl],N); 7 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/first_order_reshape.m: -------------------------------------------------------------------------------- 1 | function out=first_order_reshape(S,ref) 2 | 3 | S=S{2}; 4 | 5 | for j=1:size(S.signal,2) 6 | out(j)= S.signal{j} / S.signal{ref}; 7 | end 8 | 9 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/mfracts.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/mfracts.tgz -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/plot_full_transfer.m: -------------------------------------------------------------------------------- 1 | function plot_full_transfer(T) 2 | 3 | cc=colormap('jet'); 4 | step=floor(size(cc,1) / size(T,1)); 5 | 6 | lowlimit=-2; 7 | earlystop=2; 8 | earlyend=1; 9 | 10 | for i=1:size(T,1)-earlyend 11 | plot([max(lowlimit,2-i):size(T,2)-i+1-earlystop],T(i,max(1,i+lowlimit-1):end-earlystop),'Color',cc(i*step,:)) 12 | leg{i}=sprintf('%d',i); 13 | hold on 14 | end 15 | legend(leg) 16 | hold off 17 | 18 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/plot_stat_transfer.m: -------------------------------------------------------------------------------- 1 | function plot_stat_transfer(T,limi,limi2,str) 2 | 3 | if nargin < 3 4 | limi=size(T,1)-2; 5 | limi2=limi; 6 | end 7 | 8 | %figure 9 | pupu=min(limi,size(T,1)) 10 | start=2; 11 | 12 | cc=colormap('jet'); 13 | step=floor(size(cc,1) / pupu); 14 | for i=start:pupu 15 | plot(T(i,i+1:limi2),'Color',cc(i*step,:),'LineWidth',str) 16 | %semilogy(T(i,i+1:limi2),'Color',cc(i*step,:)) 17 | leg{i-start+1}=sprintf('%d ',i); 18 | hold on 19 | end 20 | legend(leg) 21 | hold off 22 | 23 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/scat_renorm_1d.m: -------------------------------------------------------------------------------- 1 | function [S,T,Tu,ex] = scat_renorm_1d(process, param ,options, R) 2 | 3 | 4 | firstref=getoptions(options,'firstref',1); 5 | J=options.J; 6 | 7 | scatcoeffs= J + J*(J-1)/2; 8 | ave1=zeros(scatcoeffs,2); 9 | for t=1:R 10 | X=process(param); 11 | [Sr]=scat(X,options.Wop); 12 | ave1=update_avg_coeffs(ave1,Sr); 13 | fprintf('%d .. ',t) 14 | end 15 | fprintf('\n') 16 | [~,Sr] = update_avg_coeffs(ave1/R, Sr); 17 | ex=X; 18 | 19 | Sr = renorm_scat(Sr); 20 | 21 | S = first_order_reshape(Sr,firstref); 22 | [T, Tu] = sec_order_reshape(Sr); 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/scat_renorm_1d_scatnet.m: -------------------------------------------------------------------------------- 1 | function [S,T,Tu,ex] = scat_renorm_1d_scatnet(process, param ,options, R) 2 | 3 | 4 | firstref=getoptions(options,'firstref',1); 5 | J=options.J; 6 | 7 | scatcoeffs= J + J*(J-1)/2; 8 | ave1=zeros(scatcoeffs,2); 9 | for t=1:R 10 | X=process(param); 11 | 12 | % --------- SCATTERING WITH SCATNET FILTER BANKS ---------- 13 | [S,U]=scat(X,options.Wop); 14 | % --------- AVERAGE OVER U SIGNALS TO GET Sr FROM JOAN'S VERSION -------- 15 | Sr = U; 16 | for i=1:3 17 | for j=1:length(Sr{i}.signal) 18 | Sr{i}.signal{j} = 2^(-Sr{i}.meta.resolution(j)/2)*mean(Sr{i}.signal{j}); 19 | end 20 | end 21 | % -------------------------------------------------------------- 22 | 23 | ave1=update_avg_coeffs(ave1,Sr); 24 | fprintf('%d .. ',t) 25 | end 26 | fprintf('\n') 27 | [~,Sr] = update_avg_coeffs(ave1/R, Sr); 28 | ex=X; 29 | 30 | Sr = renorm_scat(Sr); 31 | 32 | S = first_order_reshape(Sr,firstref); 33 | [T, Tu] = sec_order_reshape(Sr); 34 | end 35 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/sec_order_reshape.m: -------------------------------------------------------------------------------- 1 | function [T, Tu] = sec_order_reshape(S) 2 | 3 | % Second order coefficients 4 | S2 = S{3}; 5 | 6 | T=[]; 7 | for i=1:size(S2.signal,2) 8 | T(S2.meta.j(1,i)+1, S2.meta.j(2,i)+1) = S2.signal{i}; 9 | end 10 | 11 | 12 | limi1=size(T,1)-1; 13 | limi2=limi1; 14 | Tu=zeros(1,size(T,2)-1); 15 | weights=Tu; 16 | for j=1:min(limi1,size(T,1)) 17 | for n=j+1:min(limi2,size(T,2)) 18 | pes = 2^(-j); 19 | Tu(n-j) = Tu(n-j) + pes*T(j,n); 20 | weights(n-j) = weights(n-j) + pes; 21 | end 22 | end 23 | I=find(weights>0); 24 | Tu=Tu(I); 25 | weights=weights(I); 26 | Tu=Tu./weights; 27 | 28 | 29 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/IPASM/update_avg_coeffs.m: -------------------------------------------------------------------------------- 1 | function [runout, Sout] = update_avg_coeffs(runin, Sin) 2 | 3 | Sout=Sin; 4 | 5 | runout=0*runin; 6 | rast=1; 7 | %first and second order coeffs 8 | for j=2:3 9 | for i=1:size(Sin{j}.signal,2) 10 | runout(rast)=runin(rast)+Sin{j}.signal{i}; 11 | Sout{j}.signal{i} = runin(rast); 12 | rast=rast+1; 13 | end 14 | end 15 | 16 | 17 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/D107.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/D107.gif -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/ISCV_Figure1.m: -------------------------------------------------------------------------------- 1 | 2 | %%%%%script to generate figure 1 of Invariant Scattering Convolution Networks 3 | %%%%%feb 2012%%%%%%% 4 | %%%%%%Joan Bruna and Stephane Mallat$$$$$$$$$ 5 | 6 | 7 | %%%%%This figure shows the Morlet Wavelet used throughout the numerical 8 | %%%%%experiments of the paper%%%%%%%% 9 | 10 | N=256; 11 | %options.wavelet_family='morlet'; 12 | %options=configure_wavelet_options(options); 13 | %filters=options.filter_bank_name([N N], options); 14 | foptions.J=2; 15 | foptions.L=6; 16 | soptions.M=2; 17 | [Wop,filters]=wavelet_factory_2d([N N], foptions, soptions); 18 | 19 | R=8; 20 | 21 | Nc=55; 22 | 23 | figure 24 | imagesc(flipud(crop(real(fftshift(ifft2(filters.psi.filter{R}.coefft{1}))),Nc,N/2))) 25 | colormap gray 26 | axis square 27 | set(gca,'YTick',[]) 28 | set(gca,'XTick',[]) 29 | 30 | figure 31 | imagesc(flipud(crop(imag(fftshift(ifft2(filters.psi.filter{R}.coefft{1}))),Nc,N/2))) 32 | colormap gray 33 | axis square 34 | set(gca,'YTick',[]) 35 | set(gca,'XTick',[]) 36 | 37 | 38 | figure 39 | imagesc(add_circular_mask(flipud(abs(fftshift(filters.psi.filter{R}.coefft{1}))),0.98,1)) 40 | %imagesc((flipud(abs(fftshift(filters.psi{1}{2}{2}))))) 41 | cc=colormap(gray); 42 | colormap(1-cc) 43 | axis square 44 | axis off 45 | set(gca,'YTick',[]) 46 | set(gca,'XTick',[]) 47 | 48 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/ISCV_Figure9.m: -------------------------------------------------------------------------------- 1 | %%%%%script to generate figure 9 from the paper 'Invariant Scattering Convolution Networks' 2 | %%%%%feb 2012%%%%%%% 3 | %%%%%%Joan Bruna and Stephane Mallat$$$$$$$$$ 4 | 5 | 6 | %%%%%This figure displays the scattering coefficients of 7 | %%%%%% a texture realisation taken from the Curet dataset. 8 | 9 | close all; 10 | clear options; 11 | 12 | Nim=128;%TODO waiting for filters to be appliccable for non-dyadic sizes 13 | copts.renorm_process=0; 14 | copts.l2_renorm=1; 15 | foptions.J=7; 16 | foptions.L=8; 17 | soptions.M=2; 18 | [Wop,filters]=wavelet_factory_2d([Nim Nim], foptions, soptions); 19 | 20 | dirac=zeros(Nim); 21 | dirac(1)=1; 22 | dirac=fftshift(dirac); 23 | [scdirac]=scat(dirac,Wop); 24 | 25 | im = double(imread('28-011.png')); 26 | im=im(1:Nim,1:Nim); 27 | im=im-mean(im(:)); 28 | im=im-norm(im(:)); 29 | 30 | [sc_cur]=scat(im,Wop); 31 | met = recover_meta(sc_cur,scdirac); 32 | 33 | cur_disp=scat_display(sc_cur, scdirac,copts, met.ave); 34 | 35 | gg=colormap(gray); 36 | invgg=1-gg; 37 | 38 | figure 39 | imagesc(im); 40 | colormap(invgg); 41 | set(gca,'XTick',[]); 42 | set(gca,'YTick',[]); 43 | axis square 44 | 45 | figure 46 | imagesc(cur_disp{1}) 47 | %colormap(invgg); 48 | set(gca,'XTick',[]); 49 | set(gca,'YTick',[]); 50 | axis square 51 | 52 | 53 | figure 54 | imagesc(cur_disp{2}); 55 | %colormap(invgg); 56 | set(gca,'XTick',[]); 57 | set(gca,'YTick',[]); 58 | axis square 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/add_circular_mask.m: -------------------------------------------------------------------------------- 1 | function out=add_circular_mask(in,th,norm) 2 | if nargin < 3 3 | norm=0; 4 | end 5 | 6 | thickness=4; 7 | [N,M]=size(in); 8 | [ix,iy]=meshgrid([-N/2+1/2:N/2-1/2],[-N/2+1/2:N/2-1/2]); 9 | rad=ix.^2+iy.^2; 10 | mask=max(0,thickness-abs(sqrt(rad)-(th*N/2))); 11 | outermask=(rad < (th*N/2)^2); 12 | if norm==0 13 | out=in.*outermask+min(0,min(in(:)))*(1-outermask); 14 | mask=mask*(max(64,0*max(out(:)))/max(mask(:))); 15 | else 16 | out=in.*outermask+min(in(:))*(1-outermask); 17 | mask=mask*((max(out(:)))/max(mask(:))); 18 | end 19 | tope=max(out(:)); 20 | %out=min(tope,out+mask); 21 | out=(mask/tope).*mask+(1-mask/tope).*out; 22 | 23 | 24 | if 0 25 | cjet=colormap(gray); 26 | cjet=1-cjet; 27 | inr=in(:); 28 | if norm==1 29 | inr=(inr-min(inr))*(55/(max(inr)-min(inr))); 30 | end 31 | tempo=cjet(max(1,min(64,round(inr))),:); 32 | out=reshape(tempo,N,M,3); 33 | mtempo(:,:,1)=outermask; 34 | mtempo(:,:,2)=outermask; 35 | mtempo(:,:,3)=outermask; 36 | out=out.*mtempo+ (1-mtempo); 37 | end 38 | 39 | 40 | end 41 | 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/crop.m: -------------------------------------------------------------------------------- 1 | function M = crop(M,n,c) 2 | 3 | % crop - crop an image to reduce its size 4 | % 5 | % M = crop(M,n,c); 6 | % 7 | % n is the new size of the image 8 | % c is the center of the grop 9 | % 10 | % Copyright (c) 2007 Gabriel Peyr? 11 | 12 | n0 = size(M); 13 | 14 | if nargin<2 15 | n = round( n0(1:2)/2 ); 16 | end 17 | if nargin<3 || isempty(c) 18 | c = round( n0(1:2)/2 ); 19 | end 20 | 21 | if isempty(n) 22 | return; 23 | end 24 | 25 | if length(n)==1 26 | n = [n n]; 27 | end 28 | if length(c)==1 29 | c = [c c]; 30 | end 31 | 32 | c = round(c); 33 | 34 | 35 | selx = c(1)-ceil(n(1)/2)+1:c(1)+floor(n(1)/2); 36 | sely = c(2)-ceil(n(2)/2)+1:c(2)+floor(n(2)/2); 37 | 38 | selx(selx<1) = []; 39 | selx(selx>n0(1)) = []; 40 | sely(sely<1) = []; 41 | sely(sely>n0(2)) = []; 42 | 43 | M = M(selx,sely,:); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/dualwavelets.m: -------------------------------------------------------------------------------- 1 | function [Wout,Phiout,Phioutbis]=dualwavelets(W,Phi,LP) 2 | %for jr=1:Jres 3 | %filters.psi=W; 4 | %filters.phi=Phi; 5 | %LP=littlewood_paley_ISCV(filters); 6 | J=size(W,2); 7 | L=size(W{end},2); 8 | eps=1e-12; 9 | tight=0; 10 | 11 | Wout = W; 12 | Phiout = Phi; 13 | 14 | for j=1:J 15 | if ~isempty(W{j}) 16 | for l=1:L 17 | if tight 18 | % if frame is tight, LP = 1 for all omega, so we only need to conjugate 19 | Wout{j}{l}=conj(W{j}{l}); 20 | else 21 | % if frame is not tight, we need to divide by LP so that 22 | % sum W_j*Wd_j = sum W_j*conj(W_j)/LP = LP/LP = 1 23 | % but this can be dangerous is LP becomes very small, so only 24 | % do this on the support of W_j 25 | supp=(abs(W{j}{l})>eps); 26 | Wout{j}{l} = supp.*(conj(W{j}{l})./(LP)); 27 | end 28 | end 29 | end 30 | end 31 | eps = 2e-2; 32 | supp=(abs(Phi)>eps); 33 | Phiout=supp.*((Phi)./(LP)); 34 | if tight 35 | Phiout=Phi; 36 | Phioutbis=supp.*min(8,1./Phi); 37 | Ic=find(supp==0); 38 | Phioutbis(Ic)=0; 39 | end 40 | end 41 | 42 | 43 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/legacy_reshape_filters.m: -------------------------------------------------------------------------------- 1 | function [psi,phi,lp]=legacy_reshape_filters(filters,sizein) 2 | 3 | J=max(filters.psi.meta.j)+1; 4 | L=max(filters.psi.meta.theta); 5 | 6 | r=1; 7 | for j=1:J 8 | for l=1:L 9 | tmp = filters.psi.filter{r}.coefft{1}; 10 | tmp = fftshift(ifft2(tmp)); 11 | tmp = fftshift(cropc(tmp,sizein)); 12 | psi{j}{l} = fft2(tmp); 13 | r=r+1; 14 | end 15 | end 16 | tmp=filters.phi.filter.coefft{1}; 17 | tmp = fftshift(ifft2(tmp)); 18 | tmp = fftshift(cropc(tmp,sizein)); 19 | phi = fft2(tmp); 20 | 21 | tempo.psi{1}=psi; 22 | tempo.phi{1}=phi; 23 | lp=littlewood_paley_ISCV(tempo); 24 | 25 | end 26 | 27 | 28 | function out=cropc(in,sizein) 29 | 30 | [M1,M2]=size(in); 31 | 32 | out=in(M1/2-sizein(1)/2+1:M1/2+sizein(1)/2, M2/2-sizein(2)/2+1:M2/2+sizein(2)/2); 33 | 34 | end 35 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/littlewood_paley_ISCV.m: -------------------------------------------------------------------------------- 1 | function energy = littlewood_paley_ISCV(filters,nophi) 2 | if nargin < 2 3 | nophi = 0; 4 | end 5 | if ~exist('res','var') 6 | res=0; 7 | end 8 | 9 | Rtot=size(filters.psi,2); 10 | 11 | for res=1:Rtot 12 | W=filters.psi{res}; 13 | Phi=filters.phi{res}; 14 | 15 | J=size(W); 16 | [N,M] = size(Phi); 17 | 18 | energy{res}=zeros(N,M); 19 | for j=1:J(2) 20 | if ~isempty(W{j}) 21 | O=size(W{j}); 22 | for o=1:O(2) 23 | %energy = energy + circshift(abs(W{j}{o}),floor([N/2 M/2])).^2; 24 | energy{res} = energy{res} + abs(W{j}{o}).^2; 25 | end 26 | end 27 | end 28 | energy{res} = energy{res} + abs(Phi).^2; 29 | 30 | energym = fliplr(flipud(energy{res})); 31 | energym = circshift(energym,[1 1]); 32 | energy{res} = 0.5*(energy{res}+energym); 33 | 34 | end 35 | 36 | 37 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/readidx.m: -------------------------------------------------------------------------------- 1 | function [arr1,arr2] = readidx(FILENAME,t1,t2) 2 | 3 | %[fid, message] = fopen(FILENAME,'r','ieee-be'); 4 | fid= fopen(FILENAME,'r','b'); 5 | %[FILENAME,PERMISSION,MACHINEFORMAT,ENCODING] = fopen(fid); 6 | magic = fread(fid, 1, 'int32'); 7 | if magic==2051 8 | num = fread(fid, 1, 'int32'); 9 | ndim(1) = fread(fid, 1, 'int32'); 10 | ndim(2) = fread(fid, 1, 'int32'); 11 | a = ndim(1)*ndim(2); 12 | elseif magic==2049 13 | num = fread(fid, 1, 'int32'); 14 | a=1; 15 | else 16 | disp('unknown magic number'); 17 | end 18 | arr1 = zeros(a,t1); 19 | arr2 = zeros(a,t2-t1); 20 | for i=1:t1 21 | arr1(:,i) = fread(fid, a, 'uint8'); 22 | end 23 | for i=t1+1:t2 24 | arr2(:,i-t1) = fread(fid, a, 'uint8'); 25 | end 26 | 27 | fclose(fid); 28 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/recover_meta.m: -------------------------------------------------------------------------------- 1 | function meta=recover_meta(in, dirac) 2 | 3 | %meta.order 4 | %meta.scale 5 | %meta.orientation 6 | %meta.dirac_norm 7 | %meta.ave 8 | 9 | J=in{1}.meta.j; 10 | L=max(in{2}.meta.theta); 11 | 12 | meta.order(1)=1; 13 | meta.scale(1)=-1; 14 | meta.orientation(1)=0; 15 | meta.dirac_norm(1)=norm(dirac{1}.signal{1}(:)); 16 | meta.ave(1)=mean(in{1}.signal{1}(:)); 17 | r=2; 18 | for m=2:size(in,2) 19 | for l=1:size(in{m}.signal,2) 20 | meta.order(r)=m; 21 | meta.scale(r)=simplestack(in{m}.meta.j(1:end-1,l),J,m-1); 22 | meta.orientation(r)=simplestack(in{m}.meta.theta(:,l)-1,L,m-1); 23 | meta.dirac_norm(r)=norm(dirac{m}.signal{l}(:)); 24 | meta.ave(r)=mean(in{m}.signal{l}(:)); 25 | r=r+1; 26 | end 27 | end 28 | 29 | end 30 | 31 | 32 | function out=simplestack(code, base, len) 33 | out=0; 34 | for l=1:len 35 | out=base*out+code(l); 36 | end 37 | 38 | end 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/retrieve_mnist_data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/papers/ISCV/retrieve_mnist_data.m -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/cellfun_monitor.m: -------------------------------------------------------------------------------- 1 | % CELLFUN_MONITOR apply a function to each element of a cell array and monitor 2 | % the estimated time left every second 3 | % 4 | % Usage 5 | % cell_out = CELLFUN_MONITOR(fun, cell_in); 6 | % 7 | % Input 8 | % fun (function_handle) : the function handle to be applied 9 | % cell_in (cell) : the cell whose element will be applied fun to 10 | % 11 | % Output 12 | % cell_out (cell) : the transformed cell 13 | % 14 | % See also 15 | % CELLFUN 16 | 17 | function cell_out = cellfun_monitor(fun, cell_in) 18 | K = numel(cell_in); 19 | time_start = clock; 20 | time_elapsed_at_last_print= 0; 21 | time_between_each_print = 1; 22 | 23 | for k = 1:K 24 | cell_out{k} = fun(cell_in{k}); 25 | 26 | time_elapsed = etime(clock, time_start); 27 | if (time_elapsed - time_elapsed_at_last_print > time_between_each_print) 28 | time_elapsed_at_last_print = time_elapsed; 29 | estimated_time_left = time_elapsed * (K-k) / k; 30 | fprintf('%d / %d : estimated time left %d seconds\n',... 31 | k,K,floor(estimated_time_left)); 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/cellsrc2db.m: -------------------------------------------------------------------------------- 1 | % CELLSRC2DB Constitute a database compatible with the ScatNet 2 | % convention with a cell of one object per image and a src 3 | % 4 | % Usage 5 | % db = cellsrc2db(cell, src); 6 | function db = cellsrc2db(cell, src) 7 | db.src = src; 8 | db.features = cell2mat(cell); 9 | for i = 1:numel(cell) 10 | db.indices{i} = i; 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/figure_1.m: -------------------------------------------------------------------------------- 1 | %% Figure 1 of RSDS paper 2 | % ``Rotation, Scaling and Deformation Invariant Scattering 3 | % for Texture Discrimination" 4 | % Laurent Sifre, Stephane Mallat. 5 | % Proc. IEEE CVPR 2013 Portland, Oregon 6 | % 7 | %% 8 | 9 | clear; close all; 10 | 11 | %% build a filter bank of oriented and dilated morlet wavelets 12 | size_in = [512, 512]; 13 | options.margins = [0, 0]; 14 | filters = morlet_filter_bank_2d(size_in, options); 15 | 16 | %% build two grids of dirac 17 | dirac_step = 64; 18 | dirac_grid_1 = zeros(size_in); 19 | dirac_grid_1(1:dirac_step:end, 1:dirac_step:end) = 1; 20 | dirac_grid_2 = zeros(size_in); 21 | dirac_grid_2(dirac_step/2+1:dirac_step:end, ... 22 | dirac_step/2+1:dirac_step:end) = 1; 23 | 24 | %% convolves the grid with morlet filters 25 | dirac_grid_1_f = fft2(dirac_grid_1); 26 | dirac_grid_2_f = fft2(dirac_grid_2); 27 | 28 | psi_1 = filters.psi.filter{17}; 29 | psi_2 = filters.psi.filter{17+4}; 30 | 31 | texture_1 = conv_sub_2d(dirac_grid_1_f, psi_1, 0); 32 | texture_1 = texture_1 + conv_sub_2d(dirac_grid_1_f, psi_2, 0); 33 | 34 | texture_2 = conv_sub_2d(dirac_grid_1_f, psi_1, 0); 35 | texture_2 = texture_2 + conv_sub_2d(dirac_grid_2_f, psi_2, 0); 36 | 37 | %% take real part 38 | texture_1 = real(texture_1); 39 | texture_2 = real(texture_2); 40 | 41 | %% display the two textures 42 | subplot(121); 43 | imagesc(texture_1); 44 | subplot(122); 45 | imagesc(texture_2); 46 | colormap gray; -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/figure_4.m: -------------------------------------------------------------------------------- 1 | % a script to reproduce figure 4 of paper 2 | % 3 | % ``Rotation, Scaling and Deformation Invariant Scattering 4 | % for Texture Discrimination" 5 | % Laurent Sifre, Stephane Mallat 6 | % Proc. IEEE CVPR 2013 Portland, Oregon 7 | % 8 | 9 | clear; close all; 10 | 11 | % build a filter bank of oriented and dilated morlet wavelets 12 | size_in = [512, 512]; 13 | options.margins = [0, 0]; 14 | filters = morlet_filter_bank_2d(size_in, options); 15 | 16 | % display it 17 | colormap gray; 18 | display_filter_bank_2d(filters); -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/kthtips_src.m: -------------------------------------------------------------------------------- 1 | % KTHTIPS_SRC Creates a source for the KTH TIPS Texture dataset 2 | % 3 | % Usage 4 | % src = KTHTIPS_SRC(directory) 5 | % 6 | % Input 7 | % directory: The directory containing the KTH TIPS Texture dataset. 8 | % 9 | % Output 10 | % src: The KTH TIPS source. 11 | % 12 | % Note 13 | % The dataset is available at http://www.nada.kth.se/cvap/databases/kth-tips/ 14 | 15 | function src = kthtips_src(directory) 16 | if (nargin<1) 17 | directory = '/Users/laurentsifre/TooBigForDropbox/Databases/KTH_TIPS'; 18 | end 19 | src = create_src(directory, @uiuc_extract_objects_fun); 20 | end 21 | 22 | function [objects, classes] = uiuc_extract_objects_fun(file) 23 | objects.u1 = [1, 1]; 24 | x = imreadBW(file); 25 | [h, w] = size(x); 26 | objects.u2 = [h, w]; 27 | path_str = fileparts(file); 28 | path_parts = regexp(path_str, filesep, 'split'); 29 | classes = {path_parts{end}}; 30 | end 31 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/srcfun.m: -------------------------------------------------------------------------------- 1 | % SRCFUN Apply function to each filenames of a ScatNet-compatible src 2 | % 3 | % Usage 4 | % cell_out = SRCFUN(fun, src); 5 | 6 | function cell_out = srcfun(fun, src) 7 | time_start = clock; 8 | for k = 1:length(src.files) 9 | db.indices{k} = k; 10 | filename = src.files{k}; 11 | cell_out{k} = fun(filename); 12 | 13 | tm0 = tic; 14 | time_elapsed = etime(clock, time_start); 15 | estimated_time_left = time_elapsed * (length(src.files)-k) / k; 16 | fprintf('calculated features for %s. (%.2fs)\n',src.files{k},toc(tm0)); 17 | fprintf('%d / %d : estimated time left %d seconds\n',k,length(src.files),floor(estimated_time_left)); 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/uiuc_src.m: -------------------------------------------------------------------------------- 1 | % UIUC_SRC Creates a source for the UIUC Texture dataset 2 | % 3 | % Usage 4 | % src = UIUC_SRC(directory) 5 | % 6 | % Input 7 | % directory: The directory containing the UIUC Texture dataset. 8 | % 9 | % Output 10 | % src: The UIUC source. 11 | % 12 | % Note 13 | % The dataset is available at http://www-cvr.ai.uiuc.edu/ponce_grp/data/ 14 | 15 | 16 | function src = uiuc_src(directory) 17 | if (nargin<1) 18 | directory = ''; % PUT DEFAULT DIRECTORY HERE 19 | end 20 | src = create_src(directory, @uiuc_extract_objects_fun); 21 | end 22 | 23 | function [objects, classes] = uiuc_extract_objects_fun(file) 24 | objects.u1 = [1, 1]; 25 | objects.u2 = [480, 640]; 26 | path_str = fileparts(file); 27 | path_parts = regexp(path_str, filesep, 'split'); 28 | classes = {path_parts{end}}; 29 | end 30 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/RSDS/umd_src.m: -------------------------------------------------------------------------------- 1 | % UMD_SRC Creates a source for the UMD Texture dataset 2 | % 3 | % Usage 4 | % src = UMD_SRC(directory) 5 | % 6 | % Input 7 | % directory: The directory containing the UMD Texture dataset. 8 | % 9 | % Output 10 | % src: The UMD source. 11 | % 12 | 13 | 14 | function src = umd_src(directory) 15 | if (nargin<1) 16 | directory = '/Users/laurentsifre/TooBigForDropbox/Databases/umd'; 17 | end 18 | src = create_src(directory, @uiuc_extract_objects_fun); 19 | end 20 | 21 | function [objects, classes] = uiuc_extract_objects_fun(file) 22 | objects.u1 = [1, 1]; 23 | objects.u2 = [960, 1280]; 24 | path_str = fileparts(file); 25 | path_parts = regexp(path_str, filesep, 'split'); 26 | classes = {path_parts{end}}; 27 | end 28 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/papers/paper-list.txt: -------------------------------------------------------------------------------- 1 | Each folder corresponds to a paper. We have chosen not to include the PDF file related to the paper in the software. However, they are available at http://www.di.ens.fr/data/software/scatnet/papers/ 2 | 3 | Paper list: 4 | ISCV: Invariant Scattering Convolution Networks, J. Bruna, S. Mallat, submitted to IEEE Transactions in Pattern Analysis and Machine intelligence. 5 | GIS: Group Invariant Scattering, S. Mallat. Communications in Pure and Applied Mathematics, October 2012. 6 | RSDS: Rotation, Scaling and Deformation InvariantScattering for Texture Discrimination, L. Sifre, S. Mallat, submitted to IEEE CVPR 2013. 7 | DSS: Deep Scattering Spectrum, J. Anden, S. Mallat, submitted to IEEE trans on signal processing. 8 | IPASM: Intermittent Process Analysis with Scattering Moments, J. Bruna, S. Mallat, E. Bacry and J-F. Muzy -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/generate_path.m: -------------------------------------------------------------------------------- 1 | function path=generatePath(J) 2 | %Generate a table of 2^J-1 paths. The maximum length of a path in the scattering vector 3 | %will be J. 4 | %For paths with a length strictly inferior to J, the remaining coefficients 5 | %are replaced by -1. 6 | %This function is typically used for the display of the figures presented in the 7 | %paper: 8 | % "Group Invariant Scattering", S. Mallat, 9 | % Comm. in Pure and Applied Mathematics, Dec. 2012, Wiley 10 | 11 | path=ones(2^J-1,J); 12 | path=-path; 13 | path(1)=J-1; 14 | rnb=2; 15 | for j1=J-2:-1:0 16 | path(rnb,1)=j1; 17 | for k=1:rnb-1 18 | path(rnb+k,1)=j1; 19 | for j=2:J 20 | path(rnb+k,j)=path(k,j-1); 21 | end 22 | end 23 | rnb=2*rnb; 24 | end 25 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/hanning_standalone.m: -------------------------------------------------------------------------------- 1 | % HANNING_STANDALONE Hanning window. 2 | % 3 | % Usage 4 | % window = HANNING_STANDALONE(window_length) 5 | % 6 | % Input 7 | % window_length (integer): length of the desired window. 8 | % 9 | % Output 10 | % window (numeric): Hanning window vector 11 | % 12 | % Description 13 | % This function generates a symmetric Hanning window of arbitrary 14 | % length, not including the first and last zero-weighted samples. 15 | 16 | function window = hanning_standalone(window_length) 17 | oddity = rem(window_length,2); 18 | half_length = (window_length+oddity)/2; 19 | half_window = 0.5 * (1-cos(2*pi*(1:half_length)'/(window_length+1))); 20 | window = [half_window; half_window(end-oddity:-1:1)]; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/max_scat.m: -------------------------------------------------------------------------------- 1 | function Y = max_scat(X,N) 2 | for m = 0:length(X)-1 3 | Y{m+1}.signal = {}; 4 | % initialize target meta with same fields as source 5 | Y{m+1}.meta = struct(); 6 | field_names = fieldnames(X{m+1}.meta); 7 | for k = 1:length(field_names) 8 | Y{m+1}.meta = setfield(Y{m+1}.meta,field_names{k}, ... 9 | zeros(size(getfield(X{m+1}.meta,field_names{k}),1),0)); 10 | end 11 | r1 = 1; 12 | for p1 = 1:length(X{m+1}.signal) 13 | signal = X{m+1}.signal{p1}; 14 | % determine the window size at the current resolution 15 | N1 = N/2^(X{m+1}.meta.resolution(p1)); 16 | % copy metas of this signal into metas of multiple signals 17 | Y{m+1}.meta = map_meta(X{m+1}.meta,p1,Y{m+1}.meta,p1); 18 | % extract set of frames of length N1 19 | signal = reshape(signal,[N1 size(signal,1)/N1 size(signal,2)]); 20 | signal = permute(signal,[2 3 1]); 21 | signal = max(signal,[],3); 22 | Y{m+1}.signal{p1} = signal(:,:); 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/remove_margin.m: -------------------------------------------------------------------------------- 1 | % remove_margin : remove margins along specified dimensions 2 | % 3 | % Input 4 | % - x (numeric) : the array (up to 3d) for which to remove the margin 5 | % - margins (margins) : the margins 6 | % 7 | % Output 8 | % - x2 (numeric) : the array with removed margin 9 | % 10 | % Usage 11 | % x2 = remove_margin(x, [0,0,1,1,1,1]) 12 | % will remove 1 elements at begining and end of array along 13 | % dimension 2 and 3. 14 | 15 | function x2 = remove_margin(x, margins) 16 | [N,M,P] = size(x); 17 | x2 = x; 18 | 19 | x2 = x2(1+margins(1):N-margins(2),:,:); 20 | x2 = x2(:,1+margins(3):M-margins(4),:); 21 | x2 = x2(:,:,1+margins(5):P-margins(6)); 22 | 23 | end 24 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/renorm_low_pass_layer_1d.m: -------------------------------------------------------------------------------- 1 | 2 | function [A,Utilde] = renorm_low_pass_layer_1d(A, U, epsilon) 3 | 4 | if nargin < 3 5 | epsilon = 1e-6; % ~1e-6 6 | end 7 | 8 | Utilde = U; 9 | 10 | for p = 1:length(U.signal) 11 | sub_multiplier = 2^(U.meta.resolution(p)/2); 12 | denom = interpft(A.signal{p},size(U.signal{p},1)); 13 | Utilde.signal{p} = U.signal{p} ./ (denom + epsilon*sub_multiplier); 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/renorm_parent_2d.m: -------------------------------------------------------------------------------- 1 | % RENORM_PARENT_2D Renormalization for 2d scattering 2 | % 3 | % Usage 4 | % Sx_rn = renorm_parent_2d(Sx) 5 | % 6 | % Input 7 | % Sx (cell): output of 2d scattering 8 | % 9 | % Output 10 | % Sx_rn (cell): the renormalized 2d scattering 11 | % 12 | % Description 13 | % This function will renormalize every 2nd order node by its parent 14 | % (hence his name renorm_PARENT_2d) 15 | % 16 | % See also 17 | % SCAT, REMORM_PARENT_3D 18 | 19 | function Sx_rn = renorm_parent_2d(Sx) 20 | 21 | Sx_rn = Sx; 22 | 23 | % a function handle to find the parent node 24 | parent = @(p)(find(Sx{2}.meta.j(1,:) == Sx{3}.meta.j(1,p) &... 25 | Sx{2}.meta.theta(1,:) == Sx{3}.meta.theta(1,p) & ... 26 | Sx{2}.meta.q(1,:) == Sx{3}.meta.q(1,p))); 27 | 28 | % for each signal in order 2, divide by its ancestor 29 | for p = 1:numel(Sx{3}.signal) 30 | Sx_rn{3}.signal{p} = Sx_rn{3}.signal{p}./Sx{2}.signal{parent(p)}; 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/renorm_parent_3d.m: -------------------------------------------------------------------------------- 1 | % RENORM_PARENT_3D Renormalization for roto-translation scattering 2 | % 3 | % Usage 4 | % Sx_rn = renorm_parent_3d(Sx) 5 | % 6 | % Input 7 | % Sx (cell): output of roto-translation scattering 8 | % 9 | % Output 10 | % Sx_rn (cell): the renormalized roto-translation scattering 11 | % 12 | % Description 13 | % This function will renormalize every 2nd order node by its parent 14 | % (hence his name renorm_PARENT_3d) 15 | % 16 | % See also 17 | % SCAT, REMORM_PARENT_2D 18 | 19 | 20 | function Sx_rn = renorm_parent_3d(Sx) 21 | Sx_rn = Sx; 22 | % a function handle to find the parent node 23 | parent = @(p)(find(Sx{2}.meta.j(1,:) == Sx{3}.meta.j(1,p) & ... 24 | Sx{2}.meta.q(1,:) == Sx{3}.meta.q(1,p) )); 25 | % a function handle to find the parent node 26 | for p = 1:numel(Sx{3}.signal) 27 | Sx_rn{3}.signal{p} = Sx_rn{3}.signal{p}./Sx{2}.signal{parent(p)}; 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/renorm_scat.m: -------------------------------------------------------------------------------- 1 | % RENORM_SCAT Renormalize a scattering coefficients by their parents 2 | % 3 | % Usage 4 | % S = renorm_scat(S) 5 | % 6 | % Input 7 | % S: A scattering transform. 8 | % 9 | % Output 10 | % S: The scattering transform with second- and higher-order coefficients 11 | % divided by their parent coefficients. 12 | 13 | function X = renorm_scat(X, epsilon, min_order) 14 | if nargin < 2 15 | epsilon = 2^(-20); % ~1e-6 16 | end 17 | 18 | if nargin < 3 19 | min_order = 2; 20 | end 21 | 22 | for m = length(X)-1:-1:min_order 23 | for p2 = 1:length(X{m+1}.signal) 24 | j = X{m+1}.meta.j(:,p2); 25 | p1 = find(all(bsxfun(@eq,X{m}.meta.j,j(1:m-1)),1)); 26 | sub_multiplier = 2^(X{m+1}.meta.resolution(p2)/2); 27 | ds = log2(size(X{m}.signal{p1},1)/size(X{m+1}.signal{p2},1)); 28 | if ds > 0 29 | parent = X{m}.signal{p1}(1:2^ds:end,:,:)*2^(ds/2); 30 | else 31 | parent = interpft(X{m}.signal{p1},size(X{m}.signal{p1},1)*2^(-ds))*2^(-ds/2); 32 | end 33 | X{m+1}.signal{p2} = X{m+1}.signal{p2}./(parent+epsilon*sub_multiplier); 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/renorm_wavelet_layer_factory_1d.m: -------------------------------------------------------------------------------- 1 | % wavelet_factory_1d: Create wavelet cascade from filters 2 | % Usage 3 | % [Wop, filters] = wavelet_factory_1d(N, filter_options, scat_options) 4 | % Input 5 | % N: The size of the signals to be transformed. 6 | % filter_options: The filter options, same as for filter_bank. 7 | % scat_options: General options to be passed to wavelet_1d and 8 | % wavelet_layer_1d. Contains scat_options.M, which determines the max- 9 | % imal order of the scattering transform. 10 | % Output 11 | % Wop: A cell array of wavelet transforms needed for the scattering trans- 12 | % form. 13 | % filters: A cell array of the filters used in defining the wavelets. 14 | 15 | function [Wop, filters] = renorm_wavelet_layer_factory_1d(N, filter_options, scat_options) 16 | filters = filter_bank(N, filter_options); 17 | 18 | for m = 0:scat_options.M 19 | filt_ind = min(numel(filters), m+1); 20 | Wop{m+1} = @(X)(renorm_layers_wavelet_1d(X, filters{filt_ind}, ... 21 | scat_options)); 22 | end 23 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/scat_energy.m: -------------------------------------------------------------------------------- 1 | % SCAT_ENERGY Calculate scattering energy 2 | % 3 | % Usage 4 | % energy = scat_energy(S, U) 5 | % 6 | % Input 7 | % S (cell): The scattering transform. 8 | % U (cell): The wavelet modulus coefficients (optional). 9 | % 10 | % Output 11 | % energy (numeric): The energy of the scattering transform (the sum of the 12 | % squares of the coefficients). If both S and U are given, the energy of 13 | % both are computed and summed. 14 | 15 | function energy = scat_energy(S, U) 16 | if nargin < 2 17 | U = []; 18 | end 19 | 20 | if ~isempty(U) 21 | energy = scat_energy(S) + scat_energy(U); 22 | else 23 | if iscell(S) 24 | energy = 0; 25 | for m = 1:numel(S) 26 | energy = energy + scat_energy(S{m}); 27 | end 28 | else 29 | energy = 0; 30 | for p = 1:numel(S.signal) 31 | sig = S.signal{p}; 32 | % TODO: fix so that multiple signals work!! 33 | %sz = size(sig); 34 | %sig = reshape(sig,[prod(sz(1:end-1)) sz(end)]); 35 | energy = energy + sum(abs(sig(:)).^2,1); 36 | end 37 | end 38 | end 39 | end 40 | 41 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/scat_mask.m: -------------------------------------------------------------------------------- 1 | function Sx = scat_mask(filename, Wop) 2 | 3 | Sx = scat(imreadBW(filename), Wop); 4 | %% 5 | filename_mask = strrep(filename, 'image', 'mask'); 6 | mask = imreadBW(filename_mask); 7 | Wop0{1} = Wop{1}; 8 | mask_avg = scat(mask, Wop0); 9 | mask_avg = mask_avg{1}.signal{1}; 10 | 11 | %% 12 | for m = 1:numel(Sx) 13 | for p = 1:numel(Sx{m}.signal) 14 | Sx{m}.signal{p} = Sx{m}.signal{p} .* mask_avg / sum(mask_avg(:)); 15 | end 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/scatfun.m: -------------------------------------------------------------------------------- 1 | % scatfun: applies fun to all signal of a scattering 2 | % 3 | % Usage 4 | % Sx_out = scatfun(fun, Sx); 5 | function Sx_out = scatfun(fun, Sx) 6 | for m = 1:numel(Sx) 7 | Sx_out{m} = scatfun_layer(fun, Sx{m}); 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/scatfun_layer.m: -------------------------------------------------------------------------------- 1 | % scatfun_layer : applies fun to all signal of a ScatNet layer 2 | % 3 | % Usage 4 | % layer_out = scatfun_layer(fun, layer); 5 | function layer_out = scatfun_layer(fun, layer) 6 | layer_out = layer; 7 | for p = 1:numel(layer.signal) 8 | layer_out.signal{p} = fun(layer.signal{p}); 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/separate_freq.m: -------------------------------------------------------------------------------- 1 | function Z = separate_freq(Y) 2 | if iscell(Y) 3 | Z = {}; 4 | 5 | for m = 0:length(Y)-1 6 | Z{m+1} = separate_freq(Y{m+1}); 7 | end 8 | 9 | return; 10 | end 11 | 12 | Z.signal = {}; 13 | Z.meta = struct(); 14 | 15 | r = 1; 16 | for k = 1:length(Y.signal) 17 | if ~iscell(Y.signal{k}) 18 | % because matlab is stupid and ignores last dim if 1 19 | sz_orig = size(Y.signal{k}); 20 | if numel(sz_orig) == 2 21 | sz_orig(3) = 1; 22 | end 23 | else 24 | sz_orig = [length(Y.signal{k}) 0 size(Y.signal{k}{1},2)]; 25 | end 26 | 27 | for l = 1:sz_orig(1) 28 | if ~iscell(Y.signal{k}) 29 | nsignal = Y.signal{k}(l,:); 30 | else 31 | nsignal = Y.signal{k}{l}; 32 | end 33 | 34 | nsignal = reshape(nsignal,[numel(nsignal)/sz_orig(3) sz_orig(3)]); 35 | 36 | Z.signal{r} = nsignal; 37 | 38 | r = r+1; 39 | end 40 | end 41 | 42 | [temp,I] = sortrows(Y.meta.j(1:size(Y.meta.j,1),:).'); 43 | 44 | Z.signal = Z.signal(I); 45 | 46 | field_names = fieldnames(Y.meta); 47 | for n = 1:length(field_names) 48 | src_value = getfield(Y.meta,field_names{n}); 49 | Z.meta = setfield(Z.meta,field_names{n},src_value(:,I)); 50 | end 51 | 52 | Z.signal = cellfun(@(x)(permute(x,[1 3 2])), Z.signal, ... 53 | 'UniformOutput', false); 54 | end 55 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/standardize.m: -------------------------------------------------------------------------------- 1 | function db_std = standardize(db, epsilon) 2 | 3 | % Compute the standard deviation of each line of the matice db.features 4 | % and divide all the coefficients of this line by that value. At the end 5 | % each line has a variance of one. 6 | if (nargin<2) 7 | epsilon = 1e-6; 8 | end 9 | db_std = db; 10 | feat_mean = mean(db.features,2); 11 | feat_std = std(db.features,0,2); 12 | db_std.features = bsxfun(@rdivide, bsxfun(@minus,db.features,feat_mean), feat_std+epsilon); 13 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/scatutils/standardize_wavelet_layer_1d.m: -------------------------------------------------------------------------------- 1 | function [A_white, V_white] = standardize_wavelet_layer_1d(A_and_V, sigmas, epsilon) 2 | if nargin < 2 3 | error('no sigma provided so V remains unchanged!'); 4 | end 5 | if nargin <3 6 | epsilon = 2^(-20); 7 | end 8 | 9 | A_white = A_and_V{1}; 10 | V = A_and_V{2}; 11 | V_white = V; 12 | 13 | for p=1:length(V.signal) 14 | V_white.signal{p} = V.signal{p} ./ (sigmas(p) + epsilon); 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/check_options_white_list.m: -------------------------------------------------------------------------------- 1 | % CHECK_OPTIONS_WHITE_LIST Check that all fields of a struct are valid 2 | % 3 | % Usage 4 | % CHECK_OPTIONS_WHITE_LIST(options, white_list) 5 | % 6 | % Input 7 | % options (struct): a structure with optional fields 8 | % white_list (cell of string): containing the valid fields 9 | % 10 | % Ouput 11 | % none 12 | % 13 | % Description 14 | % Will crash with an error if the input options contains invalid fields 15 | % 16 | % See also : 17 | % FILL_STRUCT 18 | % CHECK_OPTIONS_WHITE_LIST 19 | 20 | function [] = check_options_white_list(options, white_list) 21 | fn = fieldnames(options); 22 | invalid_fields = setdiff(fn, white_list); 23 | if (numel(invalid_fields) > 0) 24 | res = cellfun(@(x) [x ', '], invalid_fields, 'UniformOutput', false); 25 | res = cell2mat(res'); 26 | res(end-1:end) = []; 27 | error('invalid fields : %s', res); 28 | end 29 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/downsample_noninteger.m: -------------------------------------------------------------------------------- 1 | function xds = downsample_noninteger(x, step) 2 | [n, m ] = size(x); 3 | [u, v] = meshgrid(1:m, 1:n); 4 | [uds, vds] = meshgrid(1:step:m, 1:step:n); 5 | xds = interp2(u,v,x,uds,vds); 6 | end 7 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/fill_struct.m: -------------------------------------------------------------------------------- 1 | % FILL_STRUCT Sets default values of a structure 2 | % 3 | % Usage 4 | % s = FILL_STRUCT(s, field, value, ...) 5 | % 6 | % Input 7 | % s (struct): Structure whose fields are to be set. 8 | % field (char): The name of the field to set. 9 | % value: The default value of the field. 10 | % 11 | % Output 12 | % s (struct): The structure with the default values set. 13 | % 14 | % Description 15 | % If the s.field is empty or not set, it is set to the default value 16 | % specified. If desired, multiple field/value pairs can be specified in the 17 | % same function call. 18 | 19 | function s = fill_struct(varargin) 20 | s = varargin{1}; 21 | 22 | for k = 1:(nargin-1)/2 23 | field_name = varargin{2*(k-1)+2}; 24 | field_value = varargin{2*(k-1)+3}; 25 | if ~isfield(s,field_name) || isempty(getfield(s,field_name)) 26 | s = setfield(s,field_name,field_value); 27 | end 28 | end 29 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/fun_multiscale.m: -------------------------------------------------------------------------------- 1 | function [yms, xms] = fun_multiscale (fun, x, scale_fac, nb_scale) 2 | xms = scale_ds(x, scale_fac, nb_scale); 3 | for i = 1:nb_scale 4 | yms{i} = fun(xms{i}); 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/func_output.m: -------------------------------------------------------------------------------- 1 | % FUNC_OUTPUT Extracts multiple outputs of a function 2 | % 3 | % Usage 4 | % out = FUNC_OUTPUT(func, output_ind, ...) 5 | % 6 | % Input 7 | % func (function handle): The function whose outputs are to be extracted. 8 | % output_ind (int): The indices of the outputs. 9 | % 10 | % Output 11 | % out: The desired output of func specified by output_ind. 12 | % 13 | % Description 14 | % The function func is called, with the third and later arguments given to 15 | % it as arguments. If output_ind is a scalar, the output it refers to is 16 | % output by FUNC_OUTPUT. If multiple output indices are given in output_ind, 17 | % the corresponding outputs are returned as a cell array. 18 | 19 | function out = func_output(func,output_ind,varargin) 20 | out = cell(1,max(output_ind)); 21 | [out{:}] = func(varargin{:}); 22 | if numel(output_ind) == 1 23 | out = out{output_ind}; 24 | else 25 | out = out(output_ind); 26 | end 27 | end 28 | 29 | 30 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/getoptions.m: -------------------------------------------------------------------------------- 1 | function v = getoptions(options, name, v, mendatory) 2 | % getoptions - retrieve options parameter 3 | % 4 | % v = getoptions(options, 'entry', v0); 5 | % is equivalent to the code: 6 | % if isfield(options, 'entry') 7 | % v = options.entry; 8 | % else 9 | % v = v0; 10 | % end 11 | % 12 | % Copyright (c) 2007 Gabriel Peyre 13 | 14 | if nargin<4 15 | mendatory = 0; 16 | end 17 | 18 | if isfield(options, name) 19 | v = eval(['options.' name ';']); 20 | elseif mendatory 21 | error(['You have to provide options.' name '.']); 22 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/git_hash.m: -------------------------------------------------------------------------------- 1 | function commit = git_hash() 2 | [temp,commit] = system('git show --format=%H'); 3 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/imreadBW.m: -------------------------------------------------------------------------------- 1 | % function [f] = imreadBW (filename) 2 | % This function reads any image, convert it in black and white and rescale 3 | % it to range 0..1 4 | function f = imreadBW (filename) 5 | 6 | fcol= imread(filename); 7 | 8 | %do it only if the image is in color 9 | if numel(size(fcol))==3 10 | fcold=double(fcol); 11 | if (size(size(fcol),2)==3) 12 | f=1/255*(0.3*fcold(:,:,1) + 0.59*fcold(:,:,2) + 0.11*fcold(:,:,3)); 13 | end 14 | if (size(size(fcol),2)==2) 15 | f=fcold; 16 | end 17 | else 18 | f=double(fcol)/255; 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/imresize_notoolbox.m: -------------------------------------------------------------------------------- 1 | function out = imresize_notoolbox(in,size_out) 2 | % laurent sifre - 7 nov 2012 3 | % do the same thing as imresize but without the image toolbox 4 | % in = mandrill; 5 | % in = in(:,1:400); 6 | % size_out = [1024,1024]; 7 | % in(end,end) = 1; 8 | %% 9 | [n,m] = size(in); 10 | N = size_out(1); 11 | M = size_out(2); 12 | [x,y] = meshgrid(1:m,1:n); 13 | [X,Y] = meshgrid(1:M,1:N); 14 | xi = 1 + (m-1)*(X-1)/(M-1); 15 | yi = 1 + (n-1)*(Y-1)/(N-1); 16 | out = interp2(x,y,in,xi,yi,'linear'); 17 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/imwriteBW.m: -------------------------------------------------------------------------------- 1 | function [] = imwriteBW(x,filename) 2 | m = min(x(:)); 3 | M = max(x(:)); 4 | 5 | 6 | xn = (x-m)/(M-m); 7 | imwrite(xn,filename); 8 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/mandrill.m: -------------------------------------------------------------------------------- 1 | function f=mandrill() 2 | f = imreadBW('mandrill.png'); 3 | end 4 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/rgb2yuv.m: -------------------------------------------------------------------------------- 1 | function x_yuv = rgb2yuv(x_rgb) 2 | r = x_rgb(:,:,1); 3 | g = x_rgb(:,:,2); 4 | b = x_rgb(:,:,3); 5 | wr = 0.2126; 6 | wb = 0.0722; 7 | wg = 1-wr-wb; 8 | umax = 0.436; 9 | vmax = 0.615; 10 | Y = wr*r +wg*g+wb*b; 11 | x_yuv(:,:,1) = Y; 12 | x_yuv(:,:,2) = umax*((b-Y)/(1-wb)); 13 | x_yuv(:,:,3) = vmax* ((r-Y)/(1-wr)); 14 | end 15 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/rgb_fun.m: -------------------------------------------------------------------------------- 1 | %function feat = rgb_fun(filename, fun) 2 | % apply function handler fun separately to all rgb channel of image located 3 | % in filename 4 | function feat = rgb_fun(filename, fun) 5 | rgbx = imread(filename); 6 | feat = []; 7 | if (numel(size(rgbx)) == 3) 8 | for c = 1:3 9 | cx = single(squeeze(rgbx(:,:,c))); 10 | feat = [feat, fun(cx)]; 11 | end 12 | else 13 | cx = single(squeeze(rgbx(:,:))); 14 | feat = repmat(fun(cx),[1,3]); 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/scale_ds.m: -------------------------------------------------------------------------------- 1 | function [xds,h] = scale_ds(x, scale_fac, nb_scale) 2 | xds{1} = x; 3 | for i = 1:nb_scale-1 4 | step = scale_fac^i; 5 | options.sigma_phi = sqrt(step^2 -1)*0.5; 6 | options.P = 2 + floor(2*step); 7 | filters = morlet_filter_bank_2d_pyramid(options); 8 | 9 | h{i} = filters.h.filter; 10 | 11 | tmp = conv_sub_2d(x, h{i}, 0); 12 | xds{i+1} = downsample_noninteger(tmp, step); 13 | end 14 | 15 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/sub_options.m: -------------------------------------------------------------------------------- 1 | % SUB_OPTIONS Copy optional fields among a specified valid list 2 | % 3 | % Usage 4 | % options2 = SUB_OPTIONS(options, field_list) 5 | % 6 | % Input 7 | % options (struct): an input struct of field 8 | % field_list (cell of string): the list of optional fields to copy 9 | % 10 | % Outpout 11 | % options2 (struct): containing a copy of all field of options that also 12 | % belong to valid_list 13 | % 14 | % See also 15 | % CHECK_OPTIONS_WHITE_LIST 16 | % FILL_STRUCT 17 | function options2 = sub_options(options, field_list) 18 | field_to_copy = intersect(fieldnames(options), field_list); 19 | options2 = struct(); 20 | for ifield = 1:numel(field_to_copy) 21 | field = field_to_copy{ifield}; 22 | options2.(field) = options.(field); 23 | end 24 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/uiuc_example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2016 CVPR SSCOMP/scatnet-0.2/utils/uiuc_example.jpg -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/uiuc_sample.m: -------------------------------------------------------------------------------- 1 | function x = uiuc_sample 2 | x = imreadBW('uiuc_example.jpg'); 3 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/upsample.m: -------------------------------------------------------------------------------- 1 | % UPSAMPLE Upsamples a signal using cubic spline interpolation 2 | % 3 | % Usage 4 | % y = upsample(x, N) 5 | % 6 | % Input 7 | % x (numeric): The signal to be upsampled. 8 | % N (numeric): The number of points in the upsampled signal. 9 | % 10 | % Output 11 | % y (numeric): The upsampled signal. 12 | % 13 | % Description 14 | % The input signal x is interpolated using cubic splines through the 15 | % INTERP1 function with symmetric boundary conditions. 16 | % 17 | % See also 18 | % INTERP1 19 | 20 | function y = upsample(x, N) 21 | y = interp1([-length(x):2*length(x)-1].', ... 22 | [flipud(x(:)); x(:); flipud(x(:))], ... 23 | [0:N-1].'/N*length(x), 'spline'); 24 | 25 | y = y/sqrt(N/length(x)); 26 | end -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/scatnet-0.2/utils/yuv_fun.m: -------------------------------------------------------------------------------- 1 | %function feat = rgb_fun(filename, fun) 2 | % apply function handler fun separately to all rgb channel of image located 3 | % in filename 4 | function feat = yuv_fun(filename, fun) 5 | rgbx = imread(filename); 6 | 7 | feat = []; 8 | if (numel(size(rgbx)) ~= 3) 9 | rgbx = repmat(rgbx,[1,1,3]); 10 | end 11 | yuvx = rgb2yuv(rgbx); 12 | feat = []; 13 | for c = 1:3 14 | cx = single(squeeze(yuvx(:,:,c))); 15 | feat = [feat, fun(cx)]; 16 | end 17 | end 18 | 19 | 20 | -------------------------------------------------------------------------------- /2016 CVPR SSCOMP/vararginParser.m: -------------------------------------------------------------------------------- 1 | function vararg = vararginParser(vararg, vararg_in) 2 | %VARARGINPARSER Input parser. 3 | 4 | % How to use: 5 | % % Set default 6 | % vararg = {'firstparameter', 1, 'secondparameter', magic(3)}; 7 | % % Overwrite by input 8 | % vararg = vararginParser(vararg, varargin); 9 | % % Generate variables 10 | % for pair = reshape(vararg, 2, []) % pair is {propName;propValue} 11 | % eval([pair{1} '= pair{2};']); 12 | % end 13 | 14 | % Copyright Chong You @ Johns Hopkins University, 2016 15 | % chong.you1987@gmail.com 16 | 17 | % count arguments 18 | if mod(length(vararg_in), 2) ~= 0 19 | error('varargin needs propertyName/propertyValue pairs') 20 | end 21 | % overwrite vararg. 22 | optionNames = vararg(1:2:end); 23 | for pair = reshape(vararg_in, 2, []) % pair is {propName;propValue} 24 | optName = pair{1}; 25 | index = find( strcmpi(optName, optionNames) ); 26 | if ~isempty(index) 27 | vararg{index * 2} = pair{2}; 28 | else 29 | error('%s is not a recognized parameter name', optName) 30 | end 31 | end 32 | 33 | end -------------------------------------------------------------------------------- /2017 CVPR NVR3/binaryalphadigs_processed.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2017 CVPR NVR3/binaryalphadigs_processed.mat -------------------------------------------------------------------------------- /2017 CVPR NVR3/cccircprod.m: -------------------------------------------------------------------------------- 1 | function Y = cccircprod(X,p) 2 | [a,b,n] = size(X); 3 | [~,r] = size(p); 4 | Y = zeros(a*r,n); 5 | for t = 1:n 6 | y = X(:,:,t)*p; 7 | Y(:,t) = reshape(y,a*r,1); 8 | % Y(:,t) = X(:,:,t)*p; 9 | end 10 | 11 | end -------------------------------------------------------------------------------- /2017 CVPR NVR3/clu_ncut.m: -------------------------------------------------------------------------------- 1 | function [idx] = clu_ncut(L,K) 2 | % this routine groups the data X into K subspaces by NCut 3 | % inputs: 4 | % L -- an N*N affinity matrix, N is the number of data points 5 | % K -- the number of subpaces (i.e., clusters) 6 | L = (L + L')/2; 7 | D = diag(1./sqrt(sum(L,2))); 8 | L = D*L*D; 9 | [U,S,V] = svd(L); 10 | 11 | V = U(:,1:K); 12 | V = D*V; 13 | 14 | idx = kmeans(V,K,'emptyaction','singleton','replicates',10,'display','off'); 15 | idx = idx'; -------------------------------------------------------------------------------- /2017 CVPR NVR3/codes/KSC_Acc.m: -------------------------------------------------------------------------------- 1 | function acc = KSC_Acc(X,aa,K,gnd) 2 | 3 | [U, S, V]=svd(X); 4 | S = diag(S); 5 | r = sum(S>1e-6); 6 | S = diag(S(1 : r)); 7 | U = U(:, 1 : r); 8 | V = V(:, 1 : r); 9 | 10 | M = U * S.^(1/2); 11 | % M = U * diag(diag(S).^(1/2)); 12 | mm = normr(M); 13 | rs = mm * mm'; 14 | for t=1:length(aa) 15 | L = rs.^(2 * aa(t)); 16 | Idx = spectral_clustering(L, K); 17 | % acc = 1 - calculate_err(gnd, actual_ids); 18 | % acc = 1 - ClusterErr(K,gnd,Idx); 19 | acc = accuracy(gnd,Idx)/100; 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /2017 CVPR NVR3/codes/accuracy.m: -------------------------------------------------------------------------------- 1 | function score = accuracy(true_labels, cluster_labels) 2 | %ACCURACY Compute clustering accuracy using the true and cluster labels and 3 | % return the value in 'score'. 4 | % 5 | % Input : true_labels : N-by-1 vector containing true labels 6 | % cluster_labels : N-by-1 vector containing cluster labels 7 | % 8 | % Output : score : clustering accuracy 9 | % 10 | % Author : Wen-Yen Chen (wychen@alumni.cs.ucsb.edu) 11 | % Chih-Jen Lin (cjlin@csie.ntu.edu.tw) 12 | 13 | % Compute the confusion matrix 'cmat', where 14 | % col index is for true label (CAT), 15 | % row index is for cluster label (CLS). 16 | n = length(true_labels); 17 | cat = spconvert([(1:n)' true_labels ones(n,1)]); 18 | cls = spconvert([(1:n)' cluster_labels ones(n,1)]); 19 | cls = cls'; 20 | cmat = full(cls * cat); 21 | 22 | % 23 | % Calculate accuracy 24 | % 25 | [match, cost] = hungarian(-cmat); 26 | score = 100*(-cost/n); 27 | -------------------------------------------------------------------------------- /2017 CVPR NVR3/codes/spectral_clustering.m: -------------------------------------------------------------------------------- 1 | function [ ids ] = spectral_clustering(W, k) 2 | 3 | D = diag(1./sqrt(sum(W, 2))); 4 | W = D * W * D; 5 | [U, S, V] = svd(W); 6 | V = U(:, 1 : k); 7 | V = normr(V); 8 | 9 | ids = kmeans(V, k, 'emptyaction', 'singleton', 'replicates', 10, 'display', 'off'); 10 | % ids = kmeans(V, k, 'start','sample','maxiter', 1000,'replicates',100,'EmptyAction','singleton'); 11 | end 12 | -------------------------------------------------------------------------------- /2017 CVPR NVR3/digit_NVR3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csjunxu/SubspaceClusteringMethods/bd34d2e17b5dcf9c9084d72a6ebd42d3cad0f1ce/2017 CVPR NVR3/digit_NVR3.mat -------------------------------------------------------------------------------- /2017 CVPR NVR3/procdata.m: -------------------------------------------------------------------------------- 1 | function A = procdata(X,a,b) 2 | [d,n] = size(X); 3 | 4 | for t 5 | 6 | end -------------------------------------------------------------------------------- /2017 CVPR NVR3/run_face_nvr3.m: -------------------------------------------------------------------------------- 1 | clc; clear; close all; warning off 2 | 3 | addpath codes2 4 | addpath codes 5 | 6 | filename = 'YaleBCrop025_NVR3'; load(strcat(filename,'.mat')); 7 | fid = fopen([filename '.txt'],'a+'); 8 | 9 | r = 6; 10 | nSet = [2 3 5 8 10]; 11 | toler = 1e-3; maxiter = 200; 12 | 13 | lambda = 5; gamma1 = 1; eta1 = 0.0002; gamma2 = 2; eta2 = 0.005; 14 | 15 | for i = [ 1 : 5 ] 16 | 17 | n = nSet(i); idx = Ind{n}; gnd = s{n}; 18 | 19 | totacc = 0; avgacc = 0; Acc = zeros(size(idx,1),1); 20 | for j = 1 : size(idx,1) 21 | 22 | A = []; ph = 0; 23 | for p = 1 : n 24 | for h = 1:size(YY,3) 25 | ph = ph+1; A(:,:,ph) = YY(:,:,h,idx(j,p)); 26 | end 27 | end 28 | A = mat2gray(A); 29 | 30 | [Z,P,Q] = NVR3(A,r,lambda,gamma1,eta1,gamma2,eta2,maxiter,toler); 31 | 32 | acc = KSC_Acc(Z,2,n,gnd); 33 | 34 | Acc(j) = acc; totacc = totacc+acc; avgacc = totacc/j; 35 | 36 | fprintf(1,'#Obj = %3d(%3d/%3d), acc: %6.4f, avgacc: %6.4f\n',n,j,size(idx,1),acc,avgacc); 37 | fprintf(fid,'#Obj = %3d(%3d/%3d), acc: %6.4f, avgacc: %6.4f\r\n',n,j,size(idx,1),acc,avgacc); 38 | 39 | end 40 | 41 | end 42 | 43 | fclose all; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SubspaceClusteringMethods 2 | Codes 3 | -------------------------------------------------------------------------------- /ReadResults.m: -------------------------------------------------------------------------------- 1 | clear; 2 | 3 | Original_image_dir = 'C:\Users\csjunxu\Desktop\SC\Results\'; 4 | fpath = fullfile(Original_image_dir, 'YaleB_LSR*.mat'); 5 | mat_dir = dir(fpath); 6 | mat_num = length(mat_dir); 7 | 8 | meanavgmissrate = []; 9 | for i = 1 : mat_num 10 | fprintf([mat_dir(i).name '\n']); 11 | eval(['load C:\Users\csjunxu\Desktop\SC\Results\' mat_dir(i).name]); 12 | meanavgmissrate = [meanavgmissrate mean(avgmissrate)]; 13 | end 14 | 15 | [minmeanavgmissrate, index] = sort(meanavgmissrate, 'ascend'); 16 | fprintf([num2str(minmeanavgmissrate(1)) '\n']); 17 | fprintf('The minimum one is %s', mat_dir(index(1)).name); 18 | -------------------------------------------------------------------------------- /Transform.m: -------------------------------------------------------------------------------- 1 | clear; 2 | 3 | % %% YaleB = 'YaleB.mat'; 4 | % load 'YaleBa.mat'; 5 | 6 | %% USPS 7 | load 'C:\Users\csjunxu\Desktop\SC\Datasets\USPS.mat'; 8 | fea = fea' - min(min(fea)); 9 | 10 | % %% MNIST 11 | % load 'MNIST.mat'; 12 | % fea = fea'; 13 | 14 | 15 | 16 | nSet = max(gnd); 17 | 18 | Y = cell(nSet, 1); 19 | S = cell(nSet, 1); 20 | for i = 1:nSet 21 | Y{i, 1} = fea(:, gnd==i); 22 | S{i, 1} = gnd(find(gnd==i)); 23 | end 24 | Ind = USPSInd; 25 | 26 | save C:\Users\csjunxu\Desktop\SC\Datasets\USPS_Crop.mat Y S Ind; 27 | --------------------------------------------------------------------------------