MATLAB: Store severals matrix M by N by 3 in one 4D matrix-Demosaicing image Raw data

4d matrixfor loopimage processingmatrix manipulationraw data

Hello, I can't save the result of each loop in a 4D matrix, to have a result like matrix (M by N by 3 by i) where i= 6 images.
This is my code : warning off MATLAB:tifflib:TIFFReadDirectory:libraryWarning;
for i=1:numOfImages
img=strcat(imageSet, subDirectory, 'Image-',int2str(i),'.dng');
t = Tiff(img,'r');
% clear img
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
clear offsets
I=read(t); % Creation de la matrice des intensités I
M = size(I, 1);
N = size(I, 2);
%---------Masque R G B--------------------
red_mask = uint16(repmat([1 0; 0 0], M/2, N/2));
green_mask = uint16(repmat([0 1; 1 0], M/2, N/2));
blue_mask = uint16(repmat([0 0; 0 1], M/2, N/2));
clear M N
%---------Dematriçage en 3 sous images--------------------
R=I.*red_mask;
G=I.*green_mask;
B=I.*blue_mask;
clear red_mask green_mask blue_mask
%---------Interpolation Bilineaire-4 pixels de voisinage --------------------
%Calucl de la composante verte manquante au niveau de notre matrice G
G= G + imfilter(G, [0 1 0; 1 0 1; 0 1 0]/4); % Masque de convolution
% Interpolation pour le bleu manquant
% Calculer les pixels bleus manquants à l'emplacement rouge
B1 = imfilter(B,[1 0 1; 0 0 0; 1 0 1]/4);
% Second, calculate the missing blue pixels at the green locations
% by averaging the four neighouring blue pixels
B2 = imfilter(B+B1,[0 1 0; 1 0 1; 0 1 0]/4);
B = B + B1 + B2;
clear B1 B2
% Interpolation for the red at the missing points
% First, calculate the missing red pixels at the blue location
R1 = imfilter(R,[1 0 1; 0 0 0; 1 0 1]/4);
% Second, calculate the missing red pixels at the green locations
R2 = imfilter(R+R1,[0 1 0; 1 0 1; 0 1 0]/4);
R = R + R1 + R2;
clear R1 R2
*I=cat(3,R,G,B);*%
I(:,:,:,i)=I;% création de la matrice ou on va stocker nos intensité
end
Think you for your help

Best Answer

I am confused about why you are apparently using the same variable name "I" for the individual images and your stacked images:
*I=cat(3,R,G,B);*%
I(:,:,:,i)=I;
Shouldn't you be using a different name for the stacked images? E.g.,
Istacked(:,:,:,i)=I;