To make faster the implemented algorithm

2 次查看(过去 30 天)
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 个评论
yanqi liu
yanqi liu 2021-12-22
yes,sir,what is F value?may be set F = 1?
Image Analyst
Image Analyst 2021-12-22
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, [])

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Banks 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by