<div dir="ltr"><div>Thanks Christina for taking care of this problem! The patch you submitted looks good to me. It would be perfect if you could create a test using the images your generate to ensure that the problem does not appear again in the future.<br><br></div>Francois<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 3, 2017 at 3:18 PM, Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Christina,<br>
<span class=""><br>
> 2nd attempt using approach 1)  (see below). What about typos in comments I<br>
> removed during bug fixing? Include into this patch as well or keep them<br>
> separate?<br>
<br>
</span>Thanks! This patch has been uploaded:<br>
<br>
  <a href="http://review.source.kitware.com/#/c/22149/3" rel="noreferrer" target="_blank">http://review.source.kitware.<wbr>com/#/c/22149/3</a><br>
<br>
<br>
The typos could go in a different patch (ideally), but it is OK, if<br>
they are included.<br>
<br>
Thanks,<br>
Matt<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> Additionally you find a small application creating an image with a bright<br>
> square on dark background which displays the image together with the result<br>
> of ApproximateSignedDistanceMapIm<wbr>ageFilter. The pixel value of the square is<br>
> 1 by default but can be changed via command line.<br>
><br>
> Regards,<br>
> Christina<br>
><br>
><br>
> On 29.03.2017 15:12, Francois Budin wrote:<br>
><br>
> Hello Christina,<br>
><br>
> I see different paths to try to solve this issue and I am not sure which one<br>
> is the best one:<br>
> 1) You could modify the itkIsoContourDistanceImageFilt<wbr>er class so that<br>
> m_LevelSetValue is of some real type. When looking in the implementation of<br>
> this filter,  you can see that sometimes, m_LevelSetValue is casted to a<br>
> real type [1], so maybe it makes sense to do that.<br>
> 2) Casting is one solution, but you have to be careful if you want to cast<br>
> to float or double. If you cast to float, and the input is of type double,<br>
> you will loose precision. If you always cast to double, you might use a lot<br>
> of memory. Sadly, in the itkNumericTraits, there is no way of asking for<br>
> "the smallest floating type that contains my current type". You can call<br>
> "RealType" which will be "double", or "FloatType" which will be float. One<br>
> strength of casting, is that if you perform it in place, it can actually not<br>
> do anything if it doesn't need to [2].<br>
> 3) To avoid casting when you don't need to (your type is float or double),<br>
> you could use the SFINAE concept like it is used here [3]. This is more<br>
> complex and may not be worth it.<br>
><br>
> Beware that images may contain pixels that are not only scalar values, but<br>
> also RGB, RGBA, vectors. I am not sure if the ApproximateDistance filter<br>
> supports these types, but it is good to be careful, when modifying the code,<br>
> to not restrict the usage of a filter to scalar if not required. To avoid<br>
> that kind of issues, and to answer your original question, you can use the<br>
> Rebind structure [4].<br>
><br>
> I hope this helps.<br>
> I will be out of town for a week, and most likely will have limited to no<br>
> access to the internet, so don't be surprised if I do not answer your next<br>
> message within the next week.<br>
><br>
> Thanks for helping!<br>
> Francois<br>
><br>
> [1]<br>
> <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/DistanceMap/include/itkIsoContourDistanceImageFilter.hxx#L314" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/ITK/<wbr>blob/master/Modules/Filtering/<wbr>DistanceMap/include/<wbr>itkIsoContourDistanceImageFilt<wbr>er.hxx#L314</a><br>
> [2]<br>
> <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/ImageFilterBase/include/itkCastImageFilter.hxx#L42" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/ITK/<wbr>blob/master/Modules/Filtering/<wbr>ImageFilterBase/include/<wbr>itkCastImageFilter.hxx#L42</a><br>
> [3]<br>
> <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkConvertPixelBuffer.h#L153-L161" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/ITK/<wbr>blob/master/Modules/IO/<wbr>ImageBase/include/<wbr>itkConvertPixelBuffer.h#L153-<wbr>L161</a><br>
> [4]<br>
> <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/Smoothing/include/itkSmoothingRecursiveGaussianImageFilter.h#L84-L85" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/ITK/<wbr>blob/master/Modules/Filtering/<wbr>Smoothing/include/<wbr>itkSmoothingRecursiveGaussianI<wbr>mageFilter.h#L84-L85</a><br>
><br>
> On Wed, Mar 29, 2017 at 7:10 AM, Chr. Rossmanith<br>
> <<a href="mailto:cr@neuro.ma.uni-heidelberg.de">cr@neuro.ma.uni-heidelberg.de</a><wbr>> wrote:<br>
>><br>
>> Hi Francois,<br>
>><br>
>> I'm getting back to this issue. I'll introduce an intermediate image in<br>
>> the mini pipeline used in ApproximateSignedDistanceMapIm<wbr>ageFilter which has<br>
>> a floating type for pixel values. Given<br>
>><br>
>>   /** Type for input image. */<br>
>>   typedef TInputImage InputImageType;<br>
>><br>
>> how can I define a corresponding image type FloatImageType replacing the<br>
>> unknown pixel type by float? I can't write itk::Image< float, xxx > because<br>
>> I don't know xxx.<br>
>><br>
>> Is there a way to query the pixel type to avoid applying the<br>
>> CastImageFilter in case we already get floating valued pixels?<br>
>><br>
>> Christina<br>
>><br>
>><br>
>><br>
>> On 03.03.2017 14:58, Francois Budin wrote:<br>
>><br>
>> Hi Christina,<br>
>><br>
>> Maybe your idea was good but needs more work (e.g. cast the input image to<br>
>> the output type? at least if input is not a float, or maybe something else).<br>
>> I am glad you found a solution that works for you. If you need your software<br>
>> to be faster, you can also replace the SignedDanielssonDistanceMap with the<br>
>> SignedMauerDistanceMap [1].<br>
>><br>
>> Hope this helps, and thanks for your contribution. Do not hesitate to<br>
>> submit a new patch to solve your original problem if you find a solution.<br>
>><br>
>> Francois<br>
>> [1]<br>
>> <a href="https://itk.org/Doxygen/html/classitk_1_1SignedMaurerDistanceMapImageFilter.html" rel="noreferrer" target="_blank">https://itk.org/Doxygen/html/<wbr>classitk_1_<wbr>1SignedMaurerDistanceMapImageF<wbr>ilter.html</a><br>
>><br>
>> On Fri, Mar 3, 2017 at 8:23 AM, Chr. Rossmanith<br>
>> <<a href="mailto:cr@neuro.ma.uni-heidelberg.de">cr@neuro.ma.uni-heidelberg.de</a><wbr>> wrote:<br>
>>><br>
>>> Hi Francois,<br>
>>><br>
>>> really strange, on Wednesday changing the data type made my application<br>
>>> work as expected (but obviously there must have been an additional change<br>
>>> which really made the application work...). When trying to build a small<br>
>>> example for you, I failed. I still think that feeding a 0/1 image into<br>
>>> ApproximateSignedDistanceMapIm<wbr>ageFilter makes sense.<br>
>>><br>
>>> Originally I'm interested in ContourExtractor2D, which operates on a<br>
>>> distance map using 0 as contour level. Unlike in the  ContourExtractor2D<br>
>>> example I've decided to use SignedDanielssonDistanceMap which works fine<br>
>>> without any patches.<br>
>>><br>
>>> So send the patch to /dev/null for the moment...<br>
>>><br>
>>> Christina<br>
>>><br>
>>><br>
>>>  On 02.03.2017 16:17, Francois Budin wrote:<br>
>>><br>
>>> Hello Christina,<br>
>>><br>
>>> I just reviewed you patch. You are changing the type of the variable<br>
>>> levelSetValue to OutputPixelType which is suppose to be a floating point<br>
>>> value.<br>
>>> However, the computation is done with InputPixelType variables<br>
>>> (m_InsideValue and m_OutsideValue) and divided by an integer. Additionally,<br>
>>> the resulting value is used in:<br>
>>>   m_IsoContourFilter-><wbr>SetLevelSetValue(<wbr>levelSetValue);<br>
>>><br>
>>> which accepts values of InputPixelType [1] since IsoContourType is<br>
>>> defined as:<br>
>>>   typedef IsoContourDistanceImageFilter< InputImageType, OutputImageType<br>
>>> >   IsoContourType;<br>
>>><br>
>>> I am not sure if your patch solves the problem that you mentioned. Do you<br>
>>> have a test that would verify that the new behavior corresponds to your<br>
>>> expectations? Based on the code review I have done, I would not expect the<br>
>>> behavior of the filter to change.<br>
>>><br>
>>> Let me know if I missed a detail. Thank you for your contribution!<br>
>>> Francois<br>
>>><br>
>>> [1]<br>
>>> <a href="https://itk.org/Doxygen/html/classitk_1_1IsoContourDistanceImageFilter.html" rel="noreferrer" target="_blank">https://itk.org/Doxygen/html/<wbr>classitk_1_<wbr>1IsoContourDistanceImageFilter<wbr>.html</a><br>
>>><br>
>>> On Wed, Mar 1, 2017 at 8:12 AM, Chr. Rossmanith<br>
>>> <<a href="mailto:cr@neuro.ma.uni-heidelberg.de">cr@neuro.ma.uni-heidelberg.de</a><wbr>> wrote:<br>
>>>><br>
>>>> For binary images with 0 for background and 1 for objects with an<br>
>>>> integer input pixel type there is a problem representing the average of 0<br>
>>>> and 1 = 0.5 with the input pixel type. The output pixel type is required to<br>
>>>> be a floating pixel type (filter documentation), so it should be safe to<br>
>>>> change the type of levelSetValue to OutputPixelType.<br>
>>>><br>
>>>> Regards,<br>
>>>> Christina<br>
>>>><br>
>>>><br>
>>>> ______________________________<wbr>_______<br>
>>>> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
>>>><br>
>>>> Visit other Kitware open-source projects at<br>
>>>> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
>>>><br>
>>>> Kitware offers ITK Training Courses, for more information visit:<br>
>>>> <a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
>>>><br>
>>>> Please keep messages on-topic and check the ITK FAQ at:<br>
>>>> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
>>>><br>
>>>> Follow this link to subscribe/unsubscribe:<br>
>>>> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
>>>><br>
>>><br>
>>><br>
>><br>
>><br>
><br>
><br>
><br>
> ______________________________<wbr>_______<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
><br>
______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br></div>