Borrar filtros
Borrar filtros

How to perform a task on each 2D within a 3D array and get back the 3D at the end of it?

1 visualización (últimos 30 días)
I want to perform a task on each 2D of a 3D array but I am having difficulties in concatenating the 2Ds into a 3D array again. What I am getting is the result of only the last 2D array in the 3D array. I have a 1024x600x10, I want to perform a task on (:,:,1),....(:,:,10) and get them back into 3D array. Thanks in advance.
This is the code I wrote:
noisy_C_scan= noisy_C_scan(:,:,:);% This is the 3D array
for n=1:10
[no_a_scan_pixels,no_a_scans] = size(noisy_C_scan(:,:,n));
N=no_a_scan_pixels;
% % %% High Pass Filter window % %
LPFwin_s=gausswin(no_a_scan_pixels,2);
LPFwin=fftshift(LPFwin_s);
HPFwin_s=1./LPFwin_s;
HPFwin=fftshift(HPFwin_s);
%
% %% Space-domain OCT image (Low pass filtered d2f data)
%
k2F = noisy_C_scan(:,:,n).*repmat(HPFwin,1,no_a_scans); % LPFwin
%% end
j=sqrt(-1);
n=0 : 1 :N-1;
k=calib_interpolation( 100000 );
kmin=min(k);
kmax=max(k);% kmin=min(k);
delta_k=kmax-kmin;
k= (k-kmin)./ (delta_k);
k=k.*N;
nk=k'*n;
DFTmtx=exp (-j*2*pi*nk/N);
% %% DFT
non_uniform_FFT= DFTmtx* k2F;% This is a 2D array after each iteration.
non_uniform_FFt= cat(3,non_uniform_FFT,non_uniform_FFT); % I intend to get (:,:,:) array
end

Respuesta aceptada

dpb
dpb el 9 de Feb. de 2021
...
non_uniform_FFT= DFTmtx* k2F;% This is a 2D array after each iteration.
non_uniform_FFt= cat(3,non_uniform_FFT,non_uniform_FFT); % I intend to get (:,:,:) array
The first line above overwrites the previous because you didn't refer to a plane with a 3D indexing expression -- hence the LHS variable is simply a 2D array.
Preallocate the output array at the beginning, before the loop begins (and, btw, you can and should remove the size() call from the loop; a 3D array cannot change its spots...er, sizes...between planes so they will be the same every iteration.
Also, you're redefining n the loop variable inside the loop over n, DON'T DO THAT! I changed the loop index to indx
Finally, you can just clear j to ensure j is the builtin complex variable to be sure it hasn't been overwritten elsewhere
[no_a_scan_pixels,no_a_scans] = size(noisy_C_scan(:,:,1)); % determine size of plane
non_uniform_FFt=zeros(size(noisy_C_scan)); % preallocate the output array
clear j % ensure j is builtin complex value
for indx=1:10
[no_a_scan_pixels,no_a_scans] = size(noisy_C_scan(:,:,n));
N=no_a_scan_pixels;
% % %% High Pass Filter window % %
LPFwin_s=gausswin(no_a_scan_pixels,2);
LPFwin=fftshift(LPFwin_s);
HPFwin_s=1./LPFwin_s;
HPFwin=fftshift(HPFwin_s);
%
% %% Space-domain OCT image (Low pass filtered d2f data)
%
k2F = noisy_C_scan(:,:,n).*repmat(HPFwin,1,no_a_scans); % LPFwin
%% end
n=0 : 1 :N-1;
k=calib_interpolation( 100000 );
kmin=min(k);
kmax=max(k);% kmin=min(k);
delta_k=kmax-kmin;
k= (k-kmin)./ (delta_k);
k=k.*N;
nk=k'*n;
DFTmtx=exp (-j*2*pi*nk/N);
% %% DFT
non_uniform_FFT(:,:,indx)= DFTmtx* k2F; % Save in output array by plane
end
There undoubtedly is quite a lot more that could be done to streamline, but that should get you started, anyways...

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by