<div dir="ltr"><div><div><div><div>Hello,<br><br></div>This does not look like a bug. It seems that the origin and spacing of your mask and of your input image are different. Have you tried to run your function only on the one (or few) images that fail?<br></div>Make sure that your mask and your image actually match in the physical space.<br></div><br>Hope this helps,<br></div>Francois<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 24, 2017 at 12:44 AM, Vishwanathan Shreyas <span dir="ltr"><<a href="mailto:shreyas122011@gmail.com" target="_blank">shreyas122011@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>SimpleITK on python gives me a weird bug, after running successfully a few times. I'm using the MICCAI BRATS database. Here's my code:<br><pre style="color:rgb(0,0,0);background:rgb(255,255,255) none repeat scroll 0% 0%"><span style="color:rgb(128,0,0);font-weight:bold">def</span> N43D<span style="color:rgb(128,128,48)">(</span>fl<span style="color:rgb(128,128,48)">)</span><span style="color:rgb(128,128,48)">:</span>
im <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>ReadImage<span style="color:rgb(128,128,48)">(</span>fl<span style="color:rgb(128,128,48)">)</span>
msk <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>BinaryThreshold<span style="color:rgb(128,128,48)">(</span>im<span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,140,0)">0</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,140,0)">0</span><span style="color:rgb(128,128,48)">)</span>
msk <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>BinaryNot<span style="color:rgb(128,128,48)">(</span>msk<span style="color:rgb(128,128,48)">)</span>
msk <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>Cast<span style="color:rgb(128,128,48)">(</span>msk<span style="color:rgb(128,128,48)">,</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>sitkUInt8<span style="color:rgb(128,128,48)">)</span>
im <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>Cast<span style="color:rgb(128,128,48)">(</span>im<span style="color:rgb(128,128,48)">,</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>sitkFloat32<span style="color:rgb(128,128,48)">)</span>
im_n4 <span style="color:rgb(128,128,48)">=</span> SimpleITK<span style="color:rgb(128,128,48)">.</span>N4BiasFieldCorrectio<wbr>n<span style="color:rgb(128,128,48)">(</span>im<span style="color:rgb(128,128,48)">,</span> msk<span style="color:rgb(128,128,48)">)</span>
SimpleITK<span style="color:rgb(128,128,48)">.</span>WriteImage<span style="color:rgb(128,128,48)">(</span>im_n4<span style="color:rgb(128,128,48)">,</span> os<span style="color:rgb(128,128,48)">.</span>path<span style="color:rgb(128,128,48)">.</span>splitext<span style="color:rgb(128,128,48)">(</span>fl<span style="color:rgb(128,128,48)">)</span><span style="color:rgb(128,128,48)">[</span><span style="color:rgb(0,140,0)">0</span><span style="color:rgb(128,128,48)">]</span><span style="color:rgb(68,170,221)">+</span><span style="color:rgb(0,0,230)">'_n4.<wbr>mha'</span><span style="color:rgb(128,128,48)">,</span> useCompression<span style="color:rgb(128,128,48)">=</span><span style="color:rgb(7,71,38)">True</span><span style="color:rgb(128,128,48)">)</span></pre><br><br>Also, I'm using multiple cores for a list of files:<br><pre style="color:rgb(0,0,0);background:rgb(255,255,255) none repeat scroll 0% 0%">dview<span style="color:rgb(128,128,48)">.</span>map_sync<span style="color:rgb(128,128,48)">(</span>N43D<span style="color:rgb(128,128,48)">,</span> fl<span style="color:rgb(128,128,48)">)</span></pre><br><br>The program runs fine for about 40 files. Then I get this error on all my engines:<br><pre style="color:rgb(0,0,0);background:rgb(255,255,255) none repeat scroll 0% 0%"><span style="color:rgb(128,128,48)">[</span><span style="color:rgb(0,140,0)">0</span><span style="color:rgb(128,128,48)">:</span>apply<span style="color:rgb(128,128,48)">]</span><span style="color:rgb(128,128,48)">:</span>
RuntimeErrorTraceback <span style="color:rgb(128,128,48)">(</span>most recent call last<span style="color:rgb(128,128,48)">)</span><span style="color:rgb(68,170,221)"><</span>string<span style="color:rgb(68,170,221)">></span> <span style="color:rgb(128,0,0);font-weight:bold">in</span> <span style="color:rgb(68,170,221)"><</span>module<span style="color:rgb(68,170,221)">></span><span style="color:rgb(128,128,48)">(</span><span style="color:rgb(128,128,48)">)</span>
<span style="color:rgb(68,170,221)"><</span>ipython<span style="color:rgb(68,170,221)">-</span><span style="color:rgb(64,0,0)">input</span><span style="color:rgb(68,170,221)">-</span>56<span style="color:rgb(68,170,221)">-</span>03a02a993653<span style="color:rgb(68,170,221)"><wbr>></span> <span style="color:rgb(128,0,0);font-weight:bold">in</span> N43D<span style="color:rgb(128,128,48)">(</span>fl<span style="color:rgb(128,128,48)">)</span>
c<span style="color:rgb(128,128,48)">:</span>\users\shreyas_v\anaconda2\<wbr>lib\site<span style="color:rgb(68,170,221)">-</span>packages\SimpleITK\<wbr>SimpleITK<span style="color:rgb(128,128,48)">.</span>pyc <span style="color:rgb(128,0,0);font-weight:bold">in</span> N4BiasFieldCorrection<span style="color:rgb(128,128,48)">(</span><span style="color:rgb(68,170,221)">*</span>args<span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(68,170,221)">**</span>kwargs<span style="color:rgb(128,128,48)">)</span>
<span style="color:rgb(0,140,0)">43368</span>
<span style="color:rgb(0,140,0)">43369</span> <span style="color:rgb(105,105,105)">"""</span>
<span style="color:rgb(105,105,105)">> 43370 return _SimpleITK.<wbr>N4BiasFieldCorrection(*args, **kwargs)</span>
<span style="color:rgb(105,105,105)"> 43371 class NaryAddImageFilter(<wbr>ImageFilter_3):</span>
<span style="color:rgb(105,105,105)"> 43372 """</span>
<span style="color:rgb(7,71,38)">RuntimeError</span><span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(7,71,38)">Exception</span> thrown <span style="color:rgb(128,0,0);font-weight:bold">in</span> SimpleITK N4BiasFieldCorrection<span style="color:rgb(128,128,48)">:</span> c<span style="color:rgb(128,128,48)">:</span>\d\vs9<span style="color:rgb(68,170,221)">-</span>pkg\simpleitk<span style="color:rgb(68,170,221)">-</span>build\<wbr>itk\modules\core\common\<wbr>include\itkImageToImageFilter<span style="color:rgb(128,128,48)">.</span><wbr>hxx<span style="color:rgb(128,128,48)">:</span><span style="color:rgb(0,140,0)">248</span><span style="color:rgb(128,128,48)">:</span>
itk<span style="color:rgb(128,128,48)">:</span><span style="color:rgb(128,128,48)">:</span>ERROR<span style="color:rgb(128,128,48)">:</span> SubtractImageFilter<span style="color:rgb(128,128,48)">(</span>0000000006<wbr>5D8220<span style="color:rgb(128,128,48)">)</span><span style="color:rgb(128,128,48)">:</span> Inputs do <span style="color:rgb(128,0,0);font-weight:bold">not</span> occupy the same physical space!
InputImage Origin<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(128,128,48)">[</span><span style="color:rgb(0,128,0)">0.0000000e+000</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(68,170,221)">-</span><span style="color:rgb(0,128,0)">2.3900000e+002</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,128,0)">0.0000000e+000</span><span style="color:rgb(128,128,48)">]</span><span style="color:rgb(128,128,48)">,</span> InputImage_1 Origin<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(128,128,48)">[</span><span style="color:rgb(68,170,221)">-</span><span style="color:rgb(0,128,0)">5.9750000e+001</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(68,170,221)">-</span><span style="color:rgb(0,128,0)">5.9750000e+001</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(68,170,221)">-</span><span style="color:rgb(0,128,0)">3.8500000e+001</span><span style="color:rgb(128,128,48)">]</span>
Tolerance<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(0,128,0)">1.0000000e-006</span>
InputImage Spacing<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(128,128,48)">[</span><span style="color:rgb(0,128,0)">1.0000000e+000</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,128,0)">1.0000000e+000</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,128,0)">1.0000000e+000</span><span style="color:rgb(128,128,48)">]</span><span style="color:rgb(128,128,48)">,</span> InputImage_1 Spacing<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(128,128,48)">[</span><span style="color:rgb(0,128,0)">5.9750000e+001</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,128,0)">5.9750000e+001</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(0,128,0)">3.8500000e+001</span><span style="color:rgb(128,128,48)">]</span>
Tolerance<span style="color:rgb(128,128,48)">:</span> <span style="color:rgb(0,128,0)">1.0000000e-006</span></pre><br></div>Has anyone faced this issue before?<br><br></div>Regards,<br></div>Shreyas<br></div>
<br>______________________________<wbr>_________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/mailman/listinfo/community" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/community</a><br>
<br></blockquote></div><br></div>