To make faster the implemented algorithm

조회 수: 2 (최근 30일)
Amjad Iqbal
Amjad Iqbal 2021년 12월 21일
댓글: Image Analyst 2021년 12월 22일
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