Untitled

mail@pastecode.io avatar
unknown
matlab
a year ago
1.6 kB
2
Indexable
Never
% Specify the folders containing the original and pre-processed images
original_folder = 'C:\Users\lalai\OneDrive\Documents\MATLAB\Metrics_Preprocess\Resized_Datasets_with_hair';
preprocessed_folder = 'C:\Users\lalai\OneDrive\Documents\MATLAB\Metrics_Preprocess\Preprocessed';

% Get the list of image files in the folders
original_files = dir(fullfile(original_folder, '*.jpg'));
preprocessed_files = dir(fullfile(preprocessed_folder, '*.jpg'));

% Initialize variables to store the metrics
psnr_values = zeros(numel(original_files), 1);
ssim_values = zeros(numel(original_files), 1);
iou_values = zeros(numel(original_files), 1);
mse_values = zeros(numel(original_files), 1);

% Loop over the images in the folders and compute the metrics
for i = 1:numel(original_files)
    % Load the original and preprocessed images
    original = imread(fullfile(original_folder, original_files(i).name));
    preprocessed = imread(fullfile(preprocessed_folder, preprocessed_files(i).name));
    
    % Compute the PSNR
    psnr_values(i) = psnr(preprocessed, original);
    
    % Compute the SSIM
    ssim_values(i) = ssim(preprocessed, original);
    
    % Calculate the mean squared error
    mse_values(i) = immse(preprocessed, original);

 end

% Compute the average metrics
avg_psnr = mean(psnr_values);
avg_ssim = mean(ssim_values);
avg_mse = mean(mse_values);

% Display the results
fprintf('Average PSNR: %.2f dB\n', avg_psnr);
fprintf('Average SSIM: %.4f\n', avg_ssim);
fprintf('Average MSE: %.4f\n', avg_mse);