- https://www.mathworks.com/help/matlab/ref/fft2.html
- https://www.mathworks.com/help/matlab/ref/fftshift.html
1/f amplitude frequency plot
9 views (last 30 days)
Show older comments
I'm running an image analysis using fourier transform.
I want to use spectral amplitude as a measure of naturalness of an image.
It is said that the i/f amplitude-frequency scaling is modulated by the naturalness of scenes, with steeper slops for naturalistics compared to artifactual scenes.
I just want to run this in matlab and test on two images, naturalistic and artifactual to see how it is.
Please share a simple code to read an image and run this 1/f amplitude - frequency scaling.
I'm here so far:
clear all; close all; clc
imdata = imread('C:\....\ab.jpg');
figure(1);imshow(imdata); title('Original Image');
imdata = rgb2gray(imdata);
figure(2); imshow(imdata); title('Gray Image');
%get fourier transform of an image
F = fft2(imdata);
%fourier transform of an image
S = abs(F);
figure(3);imshow(S,[]);title('Fourier Transform of an Image');
%get the centered spectrium
Fsh = fftshift(F);
figure(4);imshow(abs(Fsh),[]);title('Centered Fourier Transform of Image')
%apply log transform
S2 = log(1+abs(Fsh));
figure(5);imshow(S2,[]);title('log transformed image')
%reconstruct our image
F = ifftshift(Fsh);
f =ifft2(F);
figure(6);imshow(f,[]),title('reconstruct image')
If I'm missing something, too, please explain how to go about it.
0 Comments
Answers (1)
Hari
on 24 Feb 2025
Hi Ayesha,
I understand that you want to analyze the naturalness of images using 1/f amplitude-frequency scaling through Fourier transform.
I assume you want to compare the amplitude spectrum of naturalistic and artifactual images by analyzing their frequency content.
In order to perform 1/f amplitude-frequency scaling analysis, you can follow the below steps:
Read and Preprocess Images:
Load your images and convert them to grayscale.
imdata_natural = rgb2gray(imread('path_to_natural_image.jpg'));
imdata_artificial = rgb2gray(imread('path_to_artificial_image.jpg'));
Compute Fourier Transform:
Calculate the 2D Fourier transform to get frequency representation.
F_natural = fft2(imdata_natural);
F_artificial = fft2(imdata_artificial);
Calculate Amplitude Spectrum:
Shift the zero-frequency component to the center and compute amplitude.
amplitude_natural = abs(fftshift(F_natural));
amplitude_artificial = abs(fftshift(F_artificial));
Plot 1/f Amplitude-Frequency Scaling:
Compute and plot the radial average of the amplitude spectrum.
radial_natural = mean(amplitude_natural, 2);
radial_artificial = mean(amplitude_artificial, 2);
loglog(radial_natural, 'b'); hold on;
loglog(radial_artificial, 'r');
legend('Natural', 'Artificial');
Interpret Results:
Compare slopes on the log-log plot; steeper slopes suggest more natural scenes.
Refer to the documentation of “fft2” and “fftshift” functions to know more about their usage:
Hope this helps!
0 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!