Use part of each cell of 3D cell matrix

on 22 Oct 2015

2one (view profile)

on 23 Oct 2015
Hi I have used mat2cell to create a 12 x 13 x 5 cell matrix where each cell contains a 29 x 29 x 29 cube. How do I generate a new 3D cell matrix containing only the central 21 x 21 x 21 cube of each 29 x 29 x 29 cube? i.e. so the new matrix is still 12 x 13 x 5 but each one contains a 21 x 21 x 21 cube?
thanks.

2one (view profile)

on 23 Oct 2015

%e.g. im=VolStack(:,:,:,1);
%xsrh=100
%ysrh=100
%zsrh=100
%xref=90
%yref=90
%zref=90
%define search blocks
%make srh odd
xmod = mod(xsrh,2);
if xmod == 0
xsrh = xsrh-1;
end
ymod = mod(ysrh,2);
if ymod == 0
ysrh = ysrh-1;
end
zmod = mod(zsrh,2);
if zmod == 0
zsrh = zsrh-1;
end
% Get the size of the matrix
[n1, n2, n3] = size(im); %yxz
%Pad the images to make them equally divide into rectangles
%MPrime = zeros(k - mod(n1, k) + n1, k - mod(n2, k) + n2, k - mod(n3, k) + n3);
MPrime = zeros(ysrh - mod(n1, ysrh) + n1, xsrh - mod(n2, xsrh) + n2, zsrh - mod(n3, zsrh) + n3);
%Put the image into the padded storage
MPrime(1:n1, 1:n2, 1:n3) = im;
%Split up the voxels into their rectangles
MBoxed = mat2cell(MPrime, ysrh*ones(size(MPrime, 1)/ysrh, 1), xsrh*ones(size(MPrime, 2)/xsrh, 1), zsrh*ones(size(MPrime, 3)/zsrh, 1));
%Assign search blocks
srhblocks=(MBoxed(:,:,:));
%srhblocksAll=cell2mat(MBoxed(:,:,:));
%define reference blocks
refblocks=srhblocks;
cx=fix((xsrh-xref)/2); % cut of c rows on each side.
cy=fix((ysrh-yref)/2);
cz=fix((zsrh-zref)/2);
for ix=1:numel(refblocks)
refblocks{ix}=refblocks{ix}(1+cy:end-cy,1+cx:end-cx,1+cz:end-cz);
end