
How can I apply 2D Fourier transformation code for image in matlab to generate r-spectrum values?
11 views (last 30 days)
Show older comments
semhar kiflay
on 9 Dec 2016
Commented: Image Analyst
on 13 Dec 2016
How can I apply 2D Fourier transformation code in matlab to generate r-spectrum values:
I am performing 2D Fourier textural analysis for Google earth imagery to extract textural biomass by applying different window size of 20, 40, 60, 80 and 100 pixel size windows (windowing the image). 2D Fourier textural analysis will be applied to the windowed image with different window size in spatial frequencies in cycles per km as f=1000r*N1*ΔS1 (with ΔS being the pixel size in meters and N being the window size in pixels). The step will ignore phase information to compute periodogram values. These periodogram values are averaged on all possible traveling directions θ to yield an azimuthally averaged radial spectrum, a so-called ‘r-spectrum’. The r-spectrum table contains frequency for each window.
0 Comments
Accepted Answer
Image Analyst
on 10 Dec 2016
Edited: Image Analyst
on 10 Dec 2016
Wouldn't you just use fft2() and then scan the spectrum getting the radius for each frequency and building up the average radial profile? It sounds like that's what you're describing. Just off the top of my head:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'cameraman.tif'; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
caption = sprintf('Original Grayscale Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Display the histogram so we can see what gray level we need to threshold it at.
subplot(2, 2, 2);
f = abs(fft2(grayImage));
shiftedf = fftshift(f);
imshow(log(shiftedf), []);
axis on;
title('FFT2', 'FontSize', fontSize, 'Interpreter', 'None');
[rows, columns] = size(shiftedf);
radialProfile = zeros(1, ceil(sqrt(rows^2+columns^2)));
count = zeros(1, ceil(sqrt(rows^2+columns^2)));
midRow = rows/2 + 1;
midCol = columns/2 + 1;
for col = 1 : columns
for row = 1 : rows
radius = round(sqrt((row - midRow)^2 + (col - midCol)^2));
if radius == 0
continue;
end
radialProfile(radius) = radialProfile(radius) + shiftedf(row, col);
count(radius) = count(radius) + 1;
end
end
% Compute mean
radialProfile = radialProfile ./ count;
subplot(2, 2, 3:4);
plot(radialProfile, 'b-', 'LineWidth', 2);
grid on;
xlabel('Radius', 'FontSize', 20);
ylabel('Mean Power Signal', 'FontSize', 20);

4 Comments
Image Analyst
on 13 Dec 2016
I don't know the explanation of that diagram but it looks like the spectrum if in cycles per km. So you'll have to take that into account when you do the fft because if the size of the image you fft'ed is different then the axis will be different scales. So one pixel for one sized image might be f1 cycles per km, but the pixel distance might be f2 cycles per km if the magnification or field of view for the second image was different than the first. I think they must be taking that into account to get the right spectrum x axis scale no matter what the magnification or image size was.
More Answers (0)
See Also
Categories
Find more on Filter Design 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!