GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — FastProjDefocusComp/computeCompensationImage_demo.m at master · pilotlee17/FastProjDefocusComp

Expand file tree

/

computeCompensationImage_demo.m

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
124 lines (120 loc) · 6.44 KB
/

computeCompensationImage_demo.m

Copy path

File metadata and controls

124 lines (120 loc) · 6.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%% Comparison of the proposed edge intensification method and previous widely-used optimization method
clear
clc
addpath(genpath('data/'));
addpath('code/');
%% Select an original image
image_no = 1; % image_no = 1~15
path = ['data\t', num2str(image_no), '.png'];
%% Blur kernel setup
sigma = 1;
kernel_radius = (2*ceil(2*sigma)+1+1)/2;
r = kernel_radius;
gau = fspecial('gaussian', [2*kernel_radius-1, 2*kernel_radius-1], sigma);
%% Previous optimization method
[result_opt_display, time_consume_sd] = optimization_method(gau, kernel_radius, path);
%% The proposed method
badge_ori = imread(path);
badge_ori = badge_ori(:,:,1);
window_h_total = 150; window_w_total = 150;
start_i_total = 485; start_j_total = 335;
tic;
[comp, target] = proposed_method(badge_ori, gau, start_i_total, start_j_total, window_h_total, window_w_total, kernel_radius);
our_time = toc;
comp_r = uint8(comp);
target_r = uint8(target);
%% Compute the blurred original image
original_zoom = zeros(window_h_total+2*(kernel_radius-1), window_w_total+2*(kernel_radius-1));
original_zoom(kernel_radius:(kernel_radius+window_h_total-1), kernel_radius:(kernel_radius+window_w_total-1)) = target;
original_filted = zeros(window_h_total, window_w_total);
k = 1;
for i=1:window_h_total
for j=1:window_w_total
%if boundary2_inv(i+start_i_total-1, j+start_j_total-1)
%badge_art(i+(kernel_radius-1), j+(kernel_radius-1)) = sum(sum(kernel{i,j}.*badge_ori_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1))))) / sum(sum(kernel{i, j}));
original_filted(i, j) = sum(sum(gau.*original_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)))));
%item = x_syms(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)));
%y_filted_syms(i+(kernel_radius-1), j+(kernel_radius-1)) = (kernel_r{i,j}(:))' * item(:);
k = k + 1;
%end
end
end
%original_filted = imfilter(target, gau, 'replicate');
%% Compute the blurred compensation image (the proposed method)
comp_zoom = zeros(window_h_total+2*(kernel_radius-1), window_w_total+2*(kernel_radius-1));
comp_zoom(kernel_radius:(kernel_radius+window_h_total-1), kernel_radius:(kernel_radius+window_w_total-1)) = comp;
comp_filted = zeros(window_h_total, window_w_total);
k = 1;
for i=1:window_h_total
for j=1:window_w_total
%if boundary2_inv(i+start_i-1, j+start_j-1)
%badge_art(i+(kernel_radius-1), j+(kernel_radius-1)) = sum(sum(kernel{i,j}.*badge_ori_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1))))) / sum(sum(kernel{i, j}));
comp_filted(i, j) = sum(sum(gau.*comp_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)))));
%item = x_syms(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)));
%y_filted_syms(i+(kernel_radius-1), j+(kernel_radius-1)) = (kernel_r{i,j}(:))' * item(:);
k = k + 1;
%end
end
end
%comp_filted = imfilter(comp, gau, 'replicate');
%% Compute the blurred compensation image (previous optimization method)
result_zoom = zeros(window_h_total+2*(kernel_radius-1), window_w_total+2*(kernel_radius-1));
result_zoom(kernel_radius:(kernel_radius+window_h_total-1), kernel_radius:(kernel_radius+window_w_total-1)) = result_opt_display;
result_filted = zeros(window_h_total, window_w_total);
k = 1;
for i=1:window_h_total
for j=1:window_w_total
%if boundary2_inv(i+start_i-1, j+start_j-1)
%badge_art(i+(kernel_radius-1), j+(kernel_radius-1)) = sum(sum(kernel{i,j}.*badge_ori_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1))))) / sum(sum(kernel{i, j}));
result_filted(i, j) = sum(sum(gau.*result_zoom(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)))));
%item = x_syms(i:(i+2*(kernel_radius-1)), j:(j+2*(kernel_radius-1)));
%y_filted_syms(i+(kernel_radius-1), j+(kernel_radius-1)) = (kernel_r{i,j}(:))' * item(:);
k = k + 1;
%end
end
end
%% Plot
figure;
subplot(3,2,1); imshow(uint8(target)); xlabel('Original image');
subplot(3,2,2); imshow(uint8(original_filted)); xlabel('Blurred original image');
subplot(3,2,3); imshow(uint8(result_opt_display)); xlabel({'Compensation image'; '(optimization method)'});
subplot(3,2,4); imshow(uint8(result_filted)); xlabel({'Blurred compensation image'; '(optimization method)'});
subplot(3,2,5); imshow(uint8(comp)); xlabel({'Compensation image'; '(proposed)'});
subplot(3,2,6); imshow(uint8(comp_filted)); xlabel({'Blurred Compensation image'; '(proposed)'});
%% Efficiency evaluation
clc
fprintf('--------------------Efficiency (Time)---------------------\n');
fprintf('The Computation Time (in seconds) of previous_optimization is %0.4f.\n', time_consume_sd);
fprintf('The Computation Time (in seconds) of proposed is %0.4f.\n',our_time);
fprintf('----------------------------------------------------------\n');
%% SSIM metric
ref = double(target);
A_before = double(original_filted);
A_after = comp_filted;
A_sd = result_filted;
[ssimval_1, ssimmap_1] = ssim(A_before,ref);
[ssimval_2, ssimmap_2] = ssim(A_after,ref);
[ssimval_3, ssimmap_3] = ssim(A_sd,ref);
fprintf('--------------------SSIM--------------------\n');
fprintf('The SSIM of blurred original image is %0.4f.\n',ssimval_1);
fprintf('The SSIM of previous_optimization is %0.4f.\n',ssimval_3);
fprintf('The SSIM of proposed method is %0.4f.\n',ssimval_2);
fprintf('--------------------------------------------\n');
%% PSNR metric
[psnrval_1, snr_1] = psnr(A_before,ref, min(max(max(max(A_before))), max(max(max(ref)))) );
[psnrval_2, snr_2] = psnr(A_after,ref, min(max(max(max(A_before))), max(max(max(ref)))));
[psnrval_3, snr_3] = psnr(A_sd,ref, min(max(max(max(A_before))), max(max(max(ref)))));
fprintf('--------------------PSNR--------------------\n');
fprintf('The PSNR of blurred original image is %0.4f.\n',psnrval_1);
fprintf('The PSNR of previous_optimization is %0.4f.\n',psnrval_3);
fprintf('The PSNR of proposed method is %0.4f.\n',psnrval_2);
fprintf('--------------------------------------------\n');
%% RMSE metric
rmseval_1 = sqrt(immse(A_before,ref));
rmseval_2 = sqrt(immse(A_after,ref));
rmseval_3 = sqrt(immse(A_sd,ref));
fprintf('--------------------RMSE--------------------\n');
fprintf('The RMSE of blurred original image is %0.4f.\n',rmseval_1);
fprintf('The RMSE of previous_optimization is %0.4f.\n',rmseval_3);
fprintf('The RMSE of proposed method is %0.4f.\n',rmseval_2);
fprintf('--------------------------------------------\n');
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.