Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Vectorizing imcrop on an image stack
Replies: 2   Last Post: Apr 25, 2013 4:13 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bjorn Gustavsson

Posts: 411
Registered: 12/7/04
Re: Vectorizing imcrop on an image stack
Posted: Apr 25, 2013 4:13 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Scott" wrote in message <klae14$bvv$1@newscl01ah.mathworks.com>...
> I'd like to do the following but make it more efficient by vectorizing it or using cellfun:
>
> I have a time series of microscopy images that are stored in a 3D matrix (the z axis represents time). Each image has many bacteria in it and I have done some image segmentation so I can extract the centroid or boundingbox or other useful feature that belong to each bacterium using regionprops(). I can track the bacteria over time.
>
> So effectively I have an imageStack and a 2D cell array (call it bacData) where each entry of the array holds the centroid (for illustration here).
>
> I'd like to make a new cell array where each bacterium has an entry that contains a 3D matrix of its little area of the image (say 21x21 pixels) over time. If the bacteria just stayed in the same place, then I could just figure out the appropriate coordinates and slice appropriately the whole image stack. But the problem is that they move, so the centroid (and hence the sub image) for a bacterium is going to differ from z-slice to z-slice.
>
> This is straightforward to do with for loops, but I would love a solution that is more vectorized. Here is a possible for loop version making use of the centroid:
>
> cellIms=cell(size(bacData));
> for iBac=1:size(bacData,1)
> for iTime=1:size(bacData,2)
> lowerLeftCorner = bacData{iBac,iTime}-20;
> regionToCrop=[lowerLeftCorner 21 21];
> cellIms{iBac,iTime} = imcrop(imageStack(:,:,iTime),regionToCrop);
> end;
> end;
>
>
> Thanks for any suggestions.
>

I wonder if you'd gain anything by using the arrayfun/cellfun/bsxfun wrapping of the loops compared to writing the loops explicitly, I'd worry that the overhead in that function call would outweight the gains. I'd guess proper pre-allocation is the most important thing to do - allocate the entire cropped image-stack.

Interested to hear about the outcome.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.