help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: octave vectorization


From: PetrSt
Subject: Re: octave vectorization
Date: Mon, 25 Mar 2013 07:51:13 -0700 (PDT)

You are right, using of sub2ind is not a big deal and it could be rewritten
as:
        % idx1 = [i;i;i]+([j;j;j]-1).*siz(1)+kk.*(siz(1).*siz(2));
        idx1 = sub2ind(siz,[i;i;i],[j;j;j],kk+1);
        % idx2 = ii  + (jj-1).*siz(1) + repmat(kk,[1,8]).*(siz(1).*siz(2));
        idx2 = sub2ind(siz,ii,jj,repmat(kk+1,[1,8]));
or kk can be based on vector 1:3 (instead of 0:2) and in sub2ind it could be
only kk (instead of kk+1).
In calculation of idx2 I forgot to expand kk into 8 columns, but it was
handled by an automatic broadcasting.

Maybe it is clear to you now, but I'll try to explain a bit more
construction if idx1 and 2. Indices i and j are column vectors defined for
2D matrix. Introduction of kk and their 3x repetition is due to transfering
of indices from 2D /mask / to 3D /rgb / matrix, so that row and column
indices i,j are the same for all three layers of /rgb/ and each row of idx1
refers to single wrong pixel of certain color layer. It is similar for
indices ii and jj. Concerning the calculation, for given subscripts [x,y,z]
in 3D matrix of size [nx,ny,nz], the linear index equals (z-1)*(nx*ny) +
(y-1)*nx + x, i.e. number of complete layers multiplied by the "area" of
layer + number of complete columns in incomplete layer times length of
column + number of rows in incomplete column.




--
View this message in context: 
http://octave.1599824.n4.nabble.com/octave-vectorization-tp4651161p4651200.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]