matlab: optimizing code for computing statistics in multi-scale circular neighborhoods

后端 未结 1 682
南旧
南旧 2020-12-21 11:00

I\'ve a stack of images (imgstack) over which I would like to compute some statistics (e.g. mean, std, median) in multi-scale circular neighborhood

相关标签:
1条回答
  • 2020-12-21 11:14

    You can replace all operations using filters, which should be significantly faster.
    For each imagestack_radii, first create a circular mask:

    n = getnhood( strel('disk', imagestack_radii(s), 0 ) );
    
    • mean: use imfilter with double(n)/sum(n(:)) as filter

      imgstack_feats{ss}(:,:,1) = imfilter( imgstack(:,:,ss), double(n)/sum(n(:)), 'symmetric' );
      
    • std: once you have the mean, you can compute the second moment using

      tmp = imfilter( imgstack(:,:,ss).^2, double(n)/sum(n(:)), 'symmetric' );
      imgstack_feats{ss}(:,:,2) = sqrt( tmp - imgstack_feats{ss}(:,:,1) );
      
    • median: use ordfilt2

      imgstack_feats{ss}(:,:,3) = ordfilt2( imgstack(:,:,ss), ceil( sum(n(:))/2 ), n );
      
    0 讨论(0)
提交回复
热议问题