Hi @Olivia,
To address your query, “I want to calculate the power of the spatial frequency range 20-30 cycles per millimeter in a picture. I am not sure how I can accomplish this using MATLAB code”, please see updated code snippet below. So, basically this step is required “Convert to Grayscale, if it's a color image for frequency analysis” in which your case it is. Then, apply Fourier Transform by computing the 2D Fourier Transform of the grayscale image. Afterwards, use Shift Zero Frequency to the center for better visualization then Calculate Frequency Range by determining the frequency range in cycles per millimeter based on the image resolution.Finally, Calculate Power by counting the number of pixels in the specified frequency range to calculate the power.
% Read the image
image = imread('/MATLAB Drive/IMG_7236.jpg');
% Convert the image to grayscale
gray_image = rgb2gray(image);
% Perform Fourier Transform on the image
ft_image = fft2(double(gray_image));
% Shift the zero frequency component to the center
ft_image_shifted = fftshift(ft_image);
% Calculate the frequency range in cycles per millimeter
% Assuming the image resolution in pixels per millimeter
resolution = 10; % For example, 10 pixels per millimeter
freq_range = [20 30] / resolution;
% Calculate the power in the specified frequency range
power = sum(sum(abs(ft_image_shifted) >= freq_range(1) & abs(ft_image_shifted) <= freq_range(2)));
disp(['Power of spatial frequency range 20-30 cycles per millimeter: ', num2str(power)]);
This is basically how I will approach to solve the problem. Please see attached results and feel free to customize this code based on your preference.
Hope, this helps resolve your problem. Please let me know if you have any further questions.