function pca code
function pca code
fig = figure('Name', 'PCA-Based Image Fusion', 'NumberTitle', 'off', 'Position', [100, 100, 600, 400]);
% UI Components
uicontrol('Style', 'text', 'Position', [200, 350, 200, 25], 'String', 'Infrared & Visible Image Fusion',
'FontSize', 12, 'FontWeight', 'bold');
btn1 = uicontrol('Style', 'pushbutton', 'Position', [50, 300, 200, 40], 'String', 'Select Visible Image',
'Callback', @select_vi);
btn2 = uicontrol('Style', 'pushbutton', 'Position', [350, 300, 200, 40], 'String', 'Select Infrared
Image', 'Callback', @select_ir);
btn3 = uicontrol('Style', 'pushbutton', 'Position', [225, 200, 150, 40], 'String', 'Run Fusion',
'Callback', @run_fusion);
global I1 I2;
% Callback Functions
function select_vi(~, ~)
if file
I1 = imread(fullfile(path, file));
if size(I1, 3) > 1
I1 = rgb2gray(I1);
end
end
function select_ir(~, ~)
if file
I2 = imread(fullfile(path, file));
if size(I2, 3) > 1
I2 = rgb2gray(I2);
end
end
end
function run_fusion(~, ~)
if isempty(I1) || isempty(I2)
return;
end
% Preprocessing
I1 = histeq(I1);
I2 = histeq(I2);
% Anisotropic Diffusion
D1 = double(I1) - A1;
D2 = double(I2) - A2;
C1 = cov([D1(:), D2(:)]);
else
end
figure;
imshow(uint8(Out), []);
title('Fused Image');
imwrite(uint8(Out), 'Fused_Output.png');
end
end
function pca_fusion_gui()
fig = figure('Name', 'PCA Image Fusion', 'NumberTitle', 'off', 'Position', [100, 100, 600, 450]);
% UI Components
uicontrol('Style', 'text', 'Position', [200, 400, 200, 25], 'String', 'Infrared & Visible Image Fusion',
'FontSize', 12, 'FontWeight', 'bold');
uicontrol('Style', 'pushbutton', 'Position', [50, 350, 200, 40], 'String', 'Select Visible Image',
'Callback', @select_vi, 'TooltipString', 'Choose a visible light image');
uicontrol('Style', 'pushbutton', 'Position', [350, 350, 200, 40], 'String', 'Select Infrared Image',
'Callback', @select_ir, 'TooltipString', 'Choose an infrared image');
uicontrol('Style', 'pushbutton', 'Position', [225, 250, 150, 40], 'String', 'Run Fusion', 'Callback',
@run_fusion, 'TooltipString', 'Fuse the images using PCA');
global I1 I2;
% Callback Functions
function select_vi(~, ~)
if file
I1 = imread(fullfile(path, file));
if size(I1, 3) > 1
I1 = rgb2gray(I1);
end
end
end
function select_ir(~, ~)
I2 = imread(fullfile(path, file));
if size(I2, 3) > 1
I2 = rgb2gray(I2);
end
end
end
function run_fusion(~, ~)
if isempty(I1) || isempty(I2)
return;
end
% Preprocessing
I1 = histeq(I1);
I2 = histeq(I2);
% Anisotropic Diffusion
% PCA Fusion
D1 = double(I1) - A1;
D2 = double(I2) - A2;
C1 = cov([D1(:), D2(:)]);
[V11, D11] = eig(C1);
else
end
figure;
imshow(uint8(Out), []);
title('Fused Image');
imwrite(uint8(Out), 'Fused_Output.png');
entropy_value = entropy(uint8(Out));
fprintf('Performance Metrics:\n');
end
end
function pca_fusion_gui()
fig = figure('Name', 'PCA Image Fusion', 'NumberTitle', 'off', 'Position', [100, 100, 600, 450]);
% UI Components
uicontrol('Style', 'text', 'Position', [200, 400, 200, 25], 'String', 'Infrared & Visible Image Fusion',
'FontSize', 12, 'FontWeight', 'bold');
uicontrol('Style', 'pushbutton', 'Position', [50, 350, 200, 40], 'String', 'Select Visible Image',
'Callback', @select_vi, 'TooltipString', 'Choose a visible light image');
uicontrol('Style', 'pushbutton', 'Position', [350, 350, 200, 40], 'String', 'Select Infrared Image',
'Callback', @select_ir, 'TooltipString', 'Choose an infrared image');
uicontrol('Style', 'pushbutton', 'Position', [225, 250, 150, 40], 'String', 'Run Fusion', 'Callback',
@run_fusion, 'TooltipString', 'Fuse the images using PCA');
global I1 I2;
% Callback Functions
function select_vi(~, ~)
if file
I1 = imread(fullfile(path, file));
if size(I1, 3) > 1
I1 = rgb2gray(I1);
end
imshow(I1, 'Parent', ax1);
end
end
function select_ir(~, ~)
if file
I2 = imread(fullfile(path, file));
if size(I2, 3) > 1
I2 = rgb2gray(I2);
end
end
end
function run_fusion(~, ~)
if isempty(I1) || isempty(I2)
return;
end
% Preprocessing
I1 = histeq(I1);
I2 = histeq(I2);
% Anisotropic Diffusion
% PCA Fusion
D1 = double(I1) - A1;
D2 = double(I2) - A2;
C1 = cov([D1(:), D2(:)]);
else
end
figure;
imshow(uint8(Out), []);
title('Fused Image');
imwrite(uint8(Out), 'Fused_Output.png');
entropy_value = entropy(uint8(Out));
fprintf('Performance Metrics:\n');
fprintf('PSNR: %.2f dB\n', psnr_value);
end
end