0

Please can you help me correcting this code? I want to save the result of the Fast Fourier Transform of each image apart so I can reuse the proper coefficients for every band of wave I get from the FFT to calculate the bessel potential of the function? My code is below,

clc;
close all;
imagefiles = dir('*.jpg'); %any jpg file found in the folder
nfiles = length(imagefiles);    % Number of image files found
stored_values = cell(1,nfiles); % Preallocate the array for saving the values

for ii=1:nfiles

    currentfilename = imagefiles(ii).name;
    I = imread(currentfilename);
    myimage = rgb2gray(I);
    Y = fft2(myimage)
    fftMagnitude = abs(fftshift(Y))
    stored_values{ii}=fftMagnitude %store values of fft

    syms Y
    A = [-1, pi; Y, 0];
    J = besselj((1/2), A)
    stored_values{ii}=J  %save the besselj result in another cell ??

end

The code runs correctly but it's not giving numbers in arrays it's just showing the dimension of the image so I think that I'm mistaking the way of saving and calling the datas again. Can you please help? Thank you.

S. Nour
  • 1
  • 3
  • It looks like you are overwriting stored_values in the last line of the loop? If you remove that, and assuming you are trying to save fftMagnitude, what you have should work. Make sure you are accessing the data in the cell with curly braces: stored_values{1}. – Matt Nov 18 '18 at 22:07
  • Okay I removed the last line and run the code again and it gives this result: stored_values = 1×2 cell array [321×481 double] [481×321 double] J = [ (2^(1/2)*sin(1)*1i)/pi^(1/2), 0] [ (2^(1/2)*sin(Y))/(Y^(1/2)*pi^(1/2)), 0] What I want is that the result of the fftMagnitude comes in the cell but it's not. And I want to save the result of J in another cell. – S. Nour Nov 18 '18 at 22:19
  • It looks like the results of fftMagnitude are in stored_values. It's showing you that stored_values contains 2 cells, one with a 321x481 array and one with a 481x321 array. If you want to access either of those you can do so with `stored_values{1}` or `stored_values{2}`. – Matt Nov 18 '18 at 22:40
  • Thank you. So do you mean that the result for the first image is in stored_values{1} and for the second is in stored_values{2} and so on? because that's what I need. the result of each image in a cell so I don't lose the data of the previous processing by the data of the next one. – S. Nour Nov 18 '18 at 23:15
  • Yep, sounds like you've got it. If you need to save the J values you can just use a second cell. – Matt Nov 18 '18 at 23:30
  • Okay thank you! I'll see what I can do more. – S. Nour Nov 18 '18 at 23:44

0 Answers0