<div dir="ltr">
Hi,<div style> I am looking for some pointers of what I can do to speed up the following: I am extracting the mean of a 3D ROI in each of the frames of a 4D image (so in each )</div><div>Background: objlabelstatsfilter has float3dimage as feature image and a uchar (label) as inputs. In the below code I iterate over the frames (by changing the pointer of a 3D feature image) and then extract the label stats. Each filter update takes about 22 ms which is on the long side as I have more than 100 frames. (each frame is 128x128x22). </div>
<div style>It seems long to me next I was going to dump the indices of the ROI and simply use buffer arithmetic to get the values out. But before getting my hands dirty, is there something I am missing? Is LabelImageToStatisticsLabelMapFilter recreating the objectmap from labelimage each time the filter updates, even if this input is unchanged? (that would be expensive and wasteful for this particular purpose as it only needs to do this once, since the label does not change between these 100 frames).</div>
<div style>Any other suggestions appreciated!</div><div style><br></div><div style>LabelStatisticsImageFilter is giving me the same performance.<br></div><div style><br></div><div style>Thanks</div><div style>Soren</div>
<div>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><font color="#c0c0c0">//iterate dim4 in 4D image</font></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(128,128,0)">for</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,128)">size_t</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">iframe</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(0,0,0)">iframe</span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">3</span><span style="color:rgb(0,0,0)">];</span><span style="color:rgb(0,0,0)">iframe</span><span style="color:rgb(0,0,0)">++)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">{</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(0,0,0)"> //make the floatimage pointer point to the next frame (I guess I could do this with SetRegion too??) </span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">float3dimage</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">GetPixelContainer</span><span style="color:rgb(0,0,0)">()-></span><span style="color:rgb(0,0,0)">SetImportPointer</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">static_cast</span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(128,128,0)">float</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*>(</span><span style="color:rgb(128,0,0)">imgbuffers</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(0,0,0)">Buffer</span><span style="color:rgb(0,0,0)">()+</span><span style="color:rgb(0,0,128)">4</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">]*</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">]*</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">2</span><span style="color:rgb(0,0,0)">]*</span><span style="color:rgb(0,0,0)">iframe</span><span style="color:rgb(0,0,0)">),</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">]*</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">]*</span><span style="color:rgb(128,0,0)">xydims</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">2</span><span style="color:rgb(0,0,0)">]);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">float3dimage</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">Modified</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">objlabelstatsfilter</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">Update</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">for</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">unsigned</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">objlabelstatsfilter</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">GetOutput</span><span style="color:rgb(0,0,0)">()-></span>GetNumberOfLabelObjects<span style="color:rgb(0,0,0)">();</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">++</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">objlabelstatsfiltertype</span><span style="color:rgb(0,0,0)">::</span>OutputImageType<span style="color:rgb(0,0,0)">::</span>LabelObjectType<span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">labelObject</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">objlabelstatsfilter</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">GetOutput</span><span style="color:rgb(0,0,0)">()-></span>GetNthLabelObject<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>cout<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">labelObject</span><span style="color:rgb(0,0,0)">-></span>GetMean<span style="color:rgb(0,0,0)">()</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>endl<span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">}</span></pre></div></div>