How to Speed up the FOR loop in my CODE
Mostrar comentarios más antiguos
Hi, I am working on wavelet decomposition and found a formula for it and wrote it by myself for computation.
The formula is :

This is LH filtered and i do it for LL, LH, HL and HH so i get 4 images..
Can someone check the for loop in it and help me improve the computation time of it.
Elapsed time is 10.040462 seconds. I want to reduce time as much as possible as i need to work on hundreds of images
% Wavelet Decomposition
%Decomposition wavelet 'coif1' filters
[Lo_D,Hi_D] = wfilters('coif1','d');
img = imread('tumor-1.jpg');
img= im2double(img);
figure, imshow(img), title('original image');
[nrows ncols] = size(img);
imgg = zeros(nrows+6,ncols+6);
imgg(1:nrows,1:ncols) = img(:,:);
figure, imshow(imgg);
% wavelet decomposition.
imgD_LL = zeros(size(img));
imgD_LH = zeros(size(img));
imgD_HL = zeros(size(img));
imgD_HH = zeros(size(img));
% Deconstruction
tic
for i = 1: nrows
for j = 1:ncols
for p = 1:numel(Lo_D)
for q = 1:numel(Hi_D)
tempqD_LL(q) = Lo_D(p)*Lo_D(q)*imgg(i+p,j+q);
tempqD_LH(q) = Lo_D(p)*Hi_D(q)*imgg(i+p,j+q);
tempqD_HL(q) = Hi_D(p)*Lo_D(q)*imgg(i+p,j+q);
tempqD_HH(q) = Hi_D(p)*Hi_D(q)*imgg(i+p,j+q);
end
if (length(tempqD_LL) == q)
tempQD_LL(p) = sum(tempqD_LL);
tempQD_LH(p) = sum(tempqD_LH);
tempQD_HL(p) = sum(tempqD_HL);
tempQD_HH(p) = sum(tempqD_HH);
end
end
if (length(tempQD_LL) == p )
imgD_LL(i,j) = sum(tempQD_LL);
imgD_LH(i,j) = sum(tempQD_LH);
imgD_HL(i,j) = sum(tempQD_HL);
imgD_HH(i,j) = sum(tempQD_HH);
end
end
end
toc
% Plots Deconstruction..
figure,
subplot(2,2,1), imshow(imgD_LL, [min(min(imgD_LL)) max(max(imgD_LL))]), title('Img Deconstruction - LL filter');
subplot(2,2,2), imshow(imgD_LH, [min(min(imgD_LH)) max(max(imgD_LH))]); title('Img Deconstruction - LH filter');
subplot(2,2,3), imshow(imgD_HL, [min(min(imgD_HL)) max(max(imgD_HL))]); title('Img Deconstruction - HL filter');
subplot(2,2,4), imshow(imgD_HH, [min(min(imgD_HH)) max(max(imgD_HH))]); title('Img Deconstruction - HH filter');
The Image used in above is:

I found the functions to do it but they are not same as my paper
i want to use my code below..
Thanks.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!