How do you apply FOR loop to cell arrays?

I've a large 512x512 matrix which I've divided into 1024 16x16 matrices, and again these 1024 16x16 matrices I've further divided into 4x4 matrix. I've used mat2tiles function for this division.
Then I've applied a function to a 4x4 matrix. Now I want to apply this same function to all the 4x4 matrices present in the cell.
Any idea how to proceed further from this?
Thank you.

2 件のコメント

Rik
Rik 2020 年 11 月 24 日
What have you tried?
You can show exactly what you did either with your actual data, or with data=rand(512,512);.
Abhishek Baba
Abhishek Baba 2020 年 11 月 24 日
編集済み: Rik 2020 年 11 月 24 日
function outCell=mat2tiles(inArray,varargin)
tileSizes=[varargin{:}];
N=length(tileSizes);
Nmax=ndims(inArray);
if N<Nmax
tileSizes=[tileSizes,inf(1,Nmax-N)];
elseif N>Nmax
tileSizes=tileSizes(1:Nmax);
end
N=Nmax;
C=cell(1,N);
for ii=1:N %loop over the dimensions
dim=size(inArray,ii);
T=min(dim, tileSizes(ii));
if T~=floor(T) || T<=0
error 'Tile dimension must be a strictly positive integer or Inf'
end
nn=( dim / T );
nnf=floor(nn);
resid=[];
if nnf~=nn
nn=nnf;
resid=dim-T*nn;
end
C{ii}=[ones(1,nn)*T,resid];
end
outCell=mat2cell(inArray,C{:});
This above function converts my 512x512 matrix into 16x16 matrix and again that 16x16 matrix into 4x4 matrix.
My code is:
RGB = imread('Lenna.png'); % Original image loaded
GRAY = rgb2gray(RGB); % Image turned into single channel
Y = double(GRAY);
luma = Y - 128; % 128 is subtracted from each pixel values to produce a data range that is centered around zero
M = mat2tiles(mat2tiles(luma,[4,4]),[4,4]);
(Lenna.png is my 512x512 image)

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 24 日

1 投票

その他の回答 (0 件)

質問済み:

2020 年 11 月 24 日

編集済み:

Rik
2020 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by