After PCA, the reconstructed image is darker than the original.
1 view (last 30 days)
Show older comments
original iris image
pca iris image
After PCA of the iris image, I reconstructed the image and it became dark. And when I analyzed the original image and PCA image with SSIM, the result was 0.09333. Other than that, I tried MSE and PSNR, and all the results showed low structural similarity between images. What part of the code should I modify to solve this problem?
clc; clear;
% Importing an iris image
i_image = '홍채 이미지 예시2.jpg';
i = imread(i_image);
figure(1);
imshow(i);
title('Original Image');
% Image RGB Channel Extraction
red = double(i(:, :, 1));
green = double(i(:, :, 2));
blue = double(i(:, :, 3));
% Specifying the number of principal components
num_components = 200;
% Red Channel PCA
[coeff_r, score_r, ~] = pca(red);
reduced_score_r = score_r(:, 1:num_components);
reconstructed_R = reduced_score_r * coeff_r(:, 1:num_components)';
% Green Channel PCA
[coeff_g, score_g, ~] = pca(green);
reduced_score_g = score_g(:, 1:num_components);
reconstructed_G = reduced_score_g * coeff_g(:, 1:num_components)';
% Blue Channel PCA
[coeff_b, score_b, ~] = pca(blue);
reduced_score_b = score_b(:, 1:num_components);
reconstructed_B = reduced_score_b * coeff_b(:, 1:num_components)';
% Reconfiguring the image
reconstructed_red = reshape(reconstructed_R, size(red));
reconstructed_green = reshape(reconstructed_G, size(green));
reconstructed_blue = reshape(reconstructed_B, size(blue));
reconstructed_image = cat(3, uint8(reconstructed_red), uint8(reconstructed_green), uint8(reconstructed_blue));
% Show Reconfigured Images
figure(4);
imshow(uint8(reconstructed_image));
title('PCA Image');
% SSIM
ssimval=ssim(i, reconstructed_image);
% MSE
err=immse(i, reconstructed_image);
% PSNR
peaksnr=psnr(i, reconstructed_image);
0 Comments
Answers (1)
Angelo Yeo
on 20 May 2024
The reconstructed image is darker because you did not compensate the mean which is substracted when calculating covariance matrix. See pca for more information.
clc; clear;
% Importing an iris image
i_image = '홍채 이미지 예시2.jpg';
i = imread(i_image);
figure(1);
imshow(i);
title('Original Image');
% Image RGB Channel Extraction
red = double(i(:, :, 1));
green = double(i(:, :, 2));
blue = double(i(:, :, 3));
% Specifying the number of principal components
num_components = 200;
% Red Channel PCA
[coeff_r, score_r, ~,~,~,mu_red] = pca(red);
reduced_score_r = score_r(:, 1:num_components);
reconstructed_R = reduced_score_r * coeff_r(:, 1:num_components)';
% Green Channel PCA
[coeff_g, score_g, ~,~,~,mu_green] = pca(green);
reduced_score_g = score_g(:, 1:num_components);
reconstructed_G = reduced_score_g * coeff_g(:, 1:num_components)';
% Blue Channel PCA
[coeff_b, score_b, ~,~,~,mu_blue] = pca(blue);
reduced_score_b = score_b(:, 1:num_components);
reconstructed_B = reduced_score_b * coeff_b(:, 1:num_components)';
% Reconfiguring the image
reconstructed_red = reshape(reconstructed_R, size(red)) + mu_red;
reconstructed_green = reshape(reconstructed_G, size(green)) + mu_green;
reconstructed_blue = reshape(reconstructed_B, size(blue)) + mu_blue;
reconstructed_image = cat(3, uint8(reconstructed_red), uint8(reconstructed_green), uint8(reconstructed_blue));
% Show Reconfigured Images
figure(4);
imshow(uint8(reconstructed_image));
title('PCA Image');
% SSIM
ssimval=ssim(i, reconstructed_image);
% MSE
err=immse(i, reconstructed_image);
% PSNR
peaksnr=psnr(i, reconstructed_image);
3 Comments
Image Analyst
on 21 May 2024
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!