MATLAB: Subtracting velues in cell

image processing

I have a code
for xx = 1:length(dirlist(1))
x = imread([pathname, dirlist(xx).name]);
x=rgb2gray(x);
x=imresize(x,[256 256]);
C = mat2cell(x,[128 128],[128 128]);
end
for xx = 1:length(dirlist)
x = imread([pathname, dirlist(xx).name]);
x=rgb2gray(x);
x=imresize(x,[256 256]);
C1 = mat2cell(x,[128 128],[128 128]);
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
end
I want to subtract values in C and C1,in dirlist I have 50 Images..I have taken reference frame and subtracted with other frames ..after C1 ,i want to subtract C with C1,please help

Best Answer

The best thing would be to subtract first and do MAT2CELL second:
for xx = 1:length(dirlist(1))
x = imread([pathname, dirlist(xx).name]);
x=rgb2gray(x);
C=imresize(x,[256 256]);
end
for xx = 1:length(dirlist)
x = imread([pathname, dirlist(xx).name]);
x=rgb2gray(x);
C1=imresize(x,[256 256]);
end
D=mat2cell(C-C1,[128,128],[128,128]);
Alternatively, you can use CELLFUN:
D=cellfun(@(a,b) a-b, C1, C2, 'uni',0);