To make faster the implemented algorithm

2 visualizzazioni (ultimi 30 giorni)
Amjad Iqbal
Amjad Iqbal il 21 Dic 2021
Commentato: Image Analyst il 22 Dic 2021
Dear Experts,
I implemented a small algorithm which is very slow and take many hours to generate results.
Although algorithm's output is perfect, can you please guide me to make algorithm faster using filter2 or conv2?
I need to use faster function for these two loops given in the script attached.
Many thanks.
function EB = EB_Fast2D(Image, F)
k = 64; % size of patch/window
% F = 100;
n = length(Image); % image is 2D data
F = (-0.5:1/n:0.5-1/n)*F;
dc = zeros(size(Image));
for j= 1: size(Image,2)
for i = k+1:size(Image,1)-k
A = Image(:,j);
A1 = zeros(size(Image,1),1);
A1(i-k : i+k) = A(i-k:i+k); %
sig_fft = fftshift(fft(A1, size(A1,1)));
sum_Ap = cumsum(abs(sig_fft).^2);
sum_Am = wrev(cumsum(wrev(abs(sig_fft).^2)));
[val,idx] = min(abs(sum_Ap - sum_Am));
dc(i,j) = F(idx);
end
end
EB = (0.5/F).* dc;
end
  2 Commenti
yanqi liu
yanqi liu il 22 Dic 2021
yes,sir,what is F value?may be set F = 1?
Image Analyst
Image Analyst il 22 Dic 2021
n will be the longest lateral dimension of the image you pass in. So rows or columns, whichever is longer. What is the point of that?
How big is your image? As you can see from below, with a 256x256 image it takes only 1.2 seconds, not hours. But the final is all zeros. Not exactly sure what you're doing because you forgot to put in any comments and it doesn't look like the algorithm makes sense to me.
And this is supposed to handle only gray scale images, right? Not color images. By the way (for others) you will need the Wavelet Toolbox to run this.
Image = imread('cameraman.tif');
F = 20;
tic
%function EB = EB_Fast2D(Image, F)
k = 64; % size of patch/window
% F = 100;
n = length(Image) % image is 2D data
n = 256
F = (-0.5:1/n:0.5-1/n)*F;
dc = zeros(size(Image));
for j= 1: size(Image,2)
for i = k+1:size(Image,1)-k
A = Image(:,j);
A1 = zeros(size(Image,1),1);
A1(i-k : i+k) = A(i-k:i+k); %
sig_fft = fftshift(fft(A1, size(A1,1)));
sum_Ap = cumsum(abs(sig_fft).^2);
sum_Am = wrev(cumsum(wrev(abs(sig_fft).^2)));
[val,idx] = min(abs(sum_Ap - sum_Am));
dc(i,j) = F(idx);
end
end
EB = (0.5 ./ F).* dc; % Need ./ not /
fprintf('Min EB = %f, Max EB = %f\n', min(EB(:)), max(EB(:)))
Min EB = -0.000000, Max EB = -0.000000
elapsedSeconds = toc
elapsedSeconds = 1.3471
imshow(EB, [])

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Filter Banks in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by