フィルターのクリア

More efficient way of analyzing the Fourier transformation of an image?

1 回表示 (過去 30 日間)
Korbi
Korbi 2020 年 4 月 27 日
コメント済み: Korbi 2020 年 5 月 1 日
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 件のコメント
Image Analyst
Image Analyst 2020 年 4 月 27 日
What do you want to know? The Computer Vision Toolbox lets you compute the HOG (histogram of oriented gradients).
Korbi
Korbi 2020 年 4 月 27 日
Thanks for your response.
I've got pictures like these (left):
and want to automatically identify the directions of the depicted fibres.
The picture on the right shows the corresponding Fourier transformation.
With the code above, I'd get a graph like this (not the same picture, but a similar one with slightly different orientations):
and could then use the peaks function to identify the directions of fibres.
From what I've seen, the HOG is more useful if you want to identify regions of the image, for which the lines aren't clear enough.

サインインしてコメントする。

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 5 月 1 日
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.
  1 件のコメント
Korbi
Korbi 2020 年 5 月 1 日
Thanks a lot, that cut the loop time in half!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by