More efficient way of analyzing the Fourier transformation of an image?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I'm trying to automatically analyze the direction of carbon fibres in a plastic part via thermography.
Currently, the process is as follows: Take Fourier transformation of the image, then get a line through the centre of the (shifted) Fourier transformed image, and sum up the amplitude values along that line.
The problem is, I've got hundreds of images, and they're split up into dozens of sub-images each. The Fourier analysis part takes hours. Is there any way to do this faster than my current code:
phi1=double(rgb2gray(imread('peppers.png')));
xsize=min(size(phi1));
fftsize=2.^(nextpow2(xsize));
phi1m=phi1-mean2(phi1);
imfft=fftshift(fft2(phi1m,fftsize,fftsize)/fftsize);
imfftnorm=sqrt(imfft.*conj(imfft))/max(max(abs(imfft)));
xmp=size(imfft,1)/2;
ymp=size(imfft,2)/2;
radius=round(fftsize/3);
imrot=imrotate(imfftnorm,-90);
ampl=zeros(1800,1);
for ang=1:1800
xend=xmp-round(cosd(-ang/10)*radius);
yend=ymp-round(sind(-ang/10)*radius);
l1=improfile(imrot,[xmp xend],[ymp yend]);
xend2=xmp+round(cosd(-ang/10)*radius);
yend2=ymp+round(sind(-ang/10)*radius);
l2=improfile(imrot,[xmp xend2],[ymp yend2]);
ampl(ang)=nansum(l1(:))+nansum(l2(:));
end
The Fourier transformation is rather fast, it's only the for loop and especially the improfile stuff that takes a comparatively long time.
2 commentaires
Image Analyst
le 27 Avr 2020
What do you want to know? The Computer Vision Toolbox lets you compute the HOG (histogram of oriented gradients).
Réponse acceptée
Raunak Gupta
le 1 Mai 2020
Hi,
From the code I see that ang for loop doesn’t seems to have dependency between the iterations on the data values, so maybe you can use parfor to replace the for loop. Also make sure you are not plotting the output of improfile on a figure otherwise the code will become serial as it will require to plot each figure first and then move forward.
For better understanding about parfor you may refer the following.
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!