% % Dataset Configuration
this_script_path = matlab.desktop.editor.getActiveFilename;
this_script_folder = fileparts(this_script_path);
proj_root = fileparts(this_script_folder);
addpath(fullfile(proj_root, "TSC_MATLAB"));
'data_file', "Pavia.mat", ...
'gt_file', "Pavia_gt.mat", ...
'gt_key', "pavia_gt"), ...
'data_file', "PaviaUni.mat", ...
'gt_file', "PaviaU_gt.mat", ...
'data_key', "paviaU", ...
'gt_key', "paviaU_gt"), ...
'data_file', "Salinas_corrected.mat", ...
'gt_file', "Salinas_gt.mat", ...
'data_key', "salinas_corrected", ...
'gt_key', "salinas_gt"), ...
'Indian_pines', struct( ...
'data_file', "Indian_pines.mat", ...
'gt_file', "Indian_pines_gt.mat", ...
'data_key', "indian_pines", ...
'gt_key', "indian_pines_gt") ...
function run_tsc_hsi(ds_name, DATASETS)
cfg = DATASETS.(ds_name);
% Load Data and Ground Truth
data_struct = load(fullfile("MAT Files", cfg.data_file));
gt_struct = load(fullfile("GT Files", cfg.gt_file));
data_cube = data_struct.(cfg.data_key);
gt_data = gt_struct.(cfg.gt_key);
[H, W, B] = size(data_cube);
% Mask to remove the background pixels
% Determine K from unique non-zero labels
gt_labels = unique(gt_data);
gt_labels(gt_labels == 0) = [];
% Reshape the data cube to a matrix (D x N)
X_full = reshape(data_cube, [], B);
% Run TSC on the filtered out pixels
[~, ~, ~, c, K_used] = tsc(X, K, 'Verbose', true, 'MaxNZ', 50);
% Map cluster labels back to image grid (H x W)
c_image_vec = zeros(H*W, 1);
c_image_vec(mask_vec) = c; % fill only foreground pixels
c_image = reshape(c_image_vec, H, W);
% Visualize clustering result
figure('Color', 'w', 'Position', [100 100 900 800]);
'TileSpacing','compact', ...
% -------------------------
% -------------------------
% -------------------------
% -------------------------
title('Ground Truth', 'FontWeight','bold');
% -------------------------
% -------------------------
title(sprintf('TSC Clustering (%s, K = %d)', ds_name, K_used), 'FontWeight','bold');
cb1 = colorbar(ax1, 'southoutside');
cb2 = colorbar(ax2, 'southoutside');