Extract wavelength from an image using FFT
26 次查看(过去 30 天)
显示 更早的评论
I'm doing some experiments to study the effects of acoustics on an oil-in-water emulsion. The emulsion forms patterns like shown in the attached image and I'm trying to extract the wavelength from this image using 1D FFT.
I think I have to invert the image data and apply fft then plot it to find the peak which should be the wavelength.
I'm sharing some of the work I've done.
clear all;
close all;
clc;
warning off;
% [file,path] = uigetfile;
%
% filename = [path file];
filename = 'image.jpg';
Z = imread(filename);
% process image
Z = imboxfilt(Z); % apply filter to reduce noise
Zeq = imadjust(Z); % enhance constrast
Zinv = max(max(Zeq))-Zeq; % invert color scheme
% pixel scale
% formula: 0.1553374 microns * (60/obj) *(bin/mag)
pscale = 0.1553374*(60/4)*(1/1);
%pscale = 1;
Zavg = mean(Zinv); % average intensities
X = pscale*[1:1:length(Zavg)];
Ts = mean(diff(X));
Fs = 1/Ts;
% Sampling frequency
Fs = 1/(X(2)-X(1));
% Calculate fft
ydft = fft(Zavg);
% Only take one side of the Fourier transform
ydft = 2*ydft(1:ceil((length(Zavg)+1)/2));
% Calculate the frequencies
f = 0:Fs/length(Zavg):Fs/2;
% Normalise according to length of signal
ydft = ydft'/(2*length(f'));
P1 = abs(ydft);
figure(1)
semilogx(1./f,P1), xlabel('wavelength [um]');
I would really appreciate if anyone can please check this and see if its right or has a better and simpler code for it.
0 个评论
回答(1 个)
Akash
2023-9-29
Hi Diwakar,
I understand that you are conducting experiments to study the effects of acoustics on an oil-in-water emulsion and have implemented the code to plot the spectrum to identify the peak corresponding to the wavelength.
In the code you provided, the inverse of the frequency "(1./f)" is used as an approximation of the wavelength, assuming a linear relationship between frequency and wavelength. However, it's important to note that the relationship between frequency and wavelength in an image "FFT" is not always straightforward.
To accurately determine the wavelength from an image "FFT", I recommend referring to the below mentioned MATLAB Answer discussion:-
This discussion provides insights and guidance on converting the "FFT" results from frequency to wavelength, enabling you to extract more accurate wavelength information from the image.
Hope it helps.
Thanks,
Akash.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!