f



Accessing multiple subvolumes from 3D Volume

Hi,
I have a 3D matrix/volume (let's assume Image3D) of size (x,y,z). 
I need to access elements from that 3D matrix "Image3D", on the basis of indices information stored in 6 different vectors in a single command, without using for loop.

x_start : column vector containing starting indices in x-dimension.
x_end  : column vector containing ending indices in x-dimension.

y_start : column vector containing starting indices in y-dimension.
y_end  : column vector containing ending indices in y-dimension.

z_start : column vector containing starting indices in z-dimension.
z_end  : column vector containing ending indices in z-dimension.

Further, assume that length of all the index vectors is same.

Example of what can be done using for loop:

C : cell array containing sub-volumes from Image3D indexed by index vectors.

C=cell(length(x_start ),1); % Initialize a cell array of length equal to that of index vector
for Idx=1:length(x_start )
C{Idx,1}=Image3D(x_start (Idx,1):x_end(Idx,1),y_start(Idx,1) :y_end(Idx,1),...
z_start(Idx,1) :z_end(Idx,1));
end

Instead, I want to avoid for loop or any other loop and do the same task in one command. 

Please help me to solve this problem. Thanks in advance.
Best Regards,
0
Qazi
12/21/2016 2:39:04 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

4 Replies
727 Views

Similar Articles

[PageSpeed] 35

"Qazi Muhammad Hamza" wrote in message <o3e468$n7t$1@newscl01ah.mathworks.com>...
> Hi,
> I have a 3D matrix/volume (let's assume Image3D) of size (x,y,z). 
> I need to access elements from that 3D matrix "Image3D", on the basis of indices information stored in 6 different vectors in a single command, without using for loop.
> 
> x_start : column vector containing starting indices in x-dimension.
> x_end  : column vector containing ending indices in x-dimension.
> 
> y_start : column vector containing starting indices in y-dimension.
> y_end  : column vector containing ending indices in y-dimension.
> 
> z_start : column vector containing starting indices in z-dimension.
> z_end  : column vector containing ending indices in z-dimension.
> 
> Further, assume that length of all the index vectors is same.
> 
> Example of what can be done using for loop:
> 
> C : cell array containing sub-volumes from Image3D indexed by index vectors.
> 
> C=cell(length(x_start ),1); % Initialize a cell array of length equal to that of index vector
> for Idx=1:length(x_start )
> C{Idx,1}=Image3D(x_start (Idx,1):x_end(Idx,1),y_start(Idx,1) :y_end(Idx,1),...
> z_start(Idx,1) :z_end(Idx,1));
> end
> 
> Instead, I want to avoid for loop or any other loop and do the same task in one command. 
> 
> Please help me to solve this problem. Thanks in advance.
> Best Regards,

Is there a particular reason why you want to avoid this loop?  The loop, as written, is very easy to read as a programmer and gets the job done.  Any type of one-liner that gets the job done will likely have a loop in the background anyway, so why try to avoid it?

James Tursa
0
James
12/21/2016 6:43:03 PM
"James Tursa" wrote in message <o3eifn$noh$1@newscl01ah.mathworks.com>...
> "Qazi Muhammad Hamza" wrote in message <o3e468$n7t$1@newscl01ah.mathworks.com>...
> > Hi,
> > I have a 3D matrix/volume (let's assume Image3D) of size (x,y,z). 
> > I need to access elements from that 3D matrix "Image3D", on the basis of indices information stored in 6 different vectors in a single command, without using for loop.
> > 
> > x_start : column vector containing starting indices in x-dimension.
> > x_end  : column vector containing ending indices in x-dimension.
> > 
> > y_start : column vector containing starting indices in y-dimension.
> > y_end  : column vector containing ending indices in y-dimension.
> > 
> > z_start : column vector containing starting indices in z-dimension.
> > z_end  : column vector containing ending indices in z-dimension.
> > 
> > Further, assume that length of all the index vectors is same.
> > 
> > Example of what can be done using for loop:
> > 
> > C : cell array containing sub-volumes from Image3D indexed by index vectors.
> > 
> > C=cell(length(x_start ),1); % Initialize a cell array of length equal to that of index vector
> > for Idx=1:length(x_start )
> > C{Idx,1}=Image3D(x_start (Idx,1):x_end(Idx,1),y_start(Idx,1) :y_end(Idx,1),...
> > z_start(Idx,1) :z_end(Idx,1));
> > end
> > 
> > Instead, I want to avoid for loop or any other loop and do the same task in one command. 
> > 
> > Please help me to solve this problem. Thanks in advance.
> > Best Regards,
> 
> Is there a particular reason why you want to avoid this loop?  The loop, as written, is very easy to read as a programmer and gets the job done.  Any type of one-liner that gets the job done will likely have a loop in the background anyway, so why try to avoid it?
> 
> James Tursa

Hi James,

Thanks for your reply. I should've put the question more appropriately. The thing is half an hour is taken by the above method to access all the sub-volumes from the big matrix/volume Image3D and store it in the cell array "C". What I want is a fast/efficient way to do the above job. Do you think there is any possibility to do that? Something may be doing the job in some kind of parallel for loop or parallel for each loop instead of simple for loop?
My main motive is to reduce the time needed to do this job.

Thanks.

Best Regards,
Mansoor
0
Qazi
12/22/2016 9:45:02 AM
"Qazi Muhammad Hamza" wrote in message <o3g7au$gnj$1@newscl01ah.mathworks.com>...

(snip)

> 
> Hi James,
> 
> Thanks for your reply. I should've put the question more appropriately. The thing is half an hour is taken by the above method to access all the sub-volumes from the big matrix/volume Image3D and store it in the cell array "C". What I want is a fast/efficient way to do the above job. Do you think there is any possibility to do that? Something may be doing the job in some kind of parallel for loop or parallel for each loop instead of simple for loop?
> My main motive is to reduce the time needed to do this job.

What are the variable sizes involved?
0
James
12/22/2016 11:37:03 PM
"Qazi Muhammad Hamza" wrote in message <o3g7au$gnj$1@newscl01ah.mathworks.com>...

> 
> Hi James,
> 
> Thanks for your reply. I should've put the question more appropriately. The thing is half an hour is taken by the above method to access all the sub-volumes from the big matrix/volume Image3D and store it in the cell array "C". What I want is a fast/efficient way to do the above job. Do you think there is any possibility to do that? Something may be doing the job in some kind of parallel for loop or parallel for each loop instead of simple for loop?
> My main motive is to reduce the time needed to do this job.

There is no calculation here, so parallel calculation won't help (much).
Might be the PC doesn't have enough RAM to handle duplication of the matrix.

The question is what do you do will all the block downstream ? May be you can keep the original matrix and store the corners, and do smart calculation with it.
0
Bruno
12/23/2016 6:23:03 AM
Reply: