convert 3d matrix to 4d matrix using matlab -


i have 2d matrixs of dimensions 400 x 500,each of these matrixs show image. process contain 2 steps:

1) have partition these images (split matrix equal sized sub-matrices)

2) have save each of these split in 1 matrix

first step done , dimention of matrix change 2d-->3d (the last index shows index of splits)

now step 2 have 100 images , want have matrix 4 dimensions last index show number of images

sample : accessing split 3 of image 40 : [:,:,3,40]

i try using permut , reshape not successful

here code

ncol = 10; nrow = 4; k=dir(p); len=length(k);  i=3:len     x1=imread(strcat(p,'\',k(i).name));     [m,n,d1]=size(x1);     if d1==1         x=double(x1);     else         x=double(rgb2gray(x1));     end     x=imresize(x,nn);     %% determined width , height of divided matrix %%%%%%%%%%%%%%%%%%%%%%%%%%      m = size(x,1)/nrow;    n = size(x,2)/ncol;     t = permute(reshape(permute(reshape(x, size(x, 1), n, []), [2 1 3]), n, m, []), [2 1 3]);     im=[im t(:,:,:,i-2)]; end 

any idea appreciated.

reshape picks elements in column major ordering might have write convoluted code work. rather going way of using permute , reshape create 4d matrices , potentially running out of memory issue advice use of mat2cell split matrix cell array because mat2cell splits matrix want split image.

here show example image

rgb = imread('peppers.png'); x = rgb2gray(rgb); % x 384 x 512 matrix, want split in 3 rows , 2 columns x2 = mat2cell(x,384*ones(3,1)/3,512*ones(2,1)/2); % 2d cell array, each cell holds part of image imshow(x2{1,1}) % top left part of image 

you loop on images , create 3d cell array each layer in array represents each image split pieces. suggest preallocate array , assign matrix in correct layer within loop rather incrementally increasing size of matrix.

also there seems image processing toolbox specific function trying : check : how divide image blocks in matlab?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -