How can I apply 2D Fourier transformation code for image in matlab to generate r-spectrum values?

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.

 Akzeptierte Antwort

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 Kommentare

First of all I really appreciate the answer and thank you for the prompt response. I have tried using the code to perform 2D Fourier transformation (fft) after the image is windowed & to get resulting r-spectrum per window size not per pixel. Would you kindly assist me to do that?
I don't know what you mean. The window size is in pixels. How can you do something per window size and not also be doing it per pixel since they're the same thing?
The spectrum is the spectrum - it doesn't know or care how it was arrived at, and neither does the average radial profile of the spectrum. Your spectrum will be the same size no matter what window size you use, and so the radial profile will also be the same length no matter what the window size.
The information is per pixel, however the pixels should be grouped to make a window size (For example, 20 pixels per window size) since the aim is to observe the number of cycles (frequency) which repeats in that particular window size. had it been it pixel it will not be possible. There by the r-spectrum will be calculated for that window size, in this case a window with 20 pixels. Please see the image attached
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by