[ITK] image segmentation

Francois Budin francois.budin at kitware.com
Thu Mar 9 13:53:27 EST 2017


Great to hear that you were successful!

Francois

On Thu, Mar 9, 2017 at 11:32 AM, Giuseppe Amatulli <
giuseppe.amatulli at gmail.com> wrote:

> Hi All,
> after several try i was able to perform a good watershed delineation
>
> wget https://www.dropbox.com/s/hky66n5ilhpy9k2/impervius_cost.tif
> wget https://www.dropbox.com/s/vtumfmi9m5i9r4g/markers.tif
>
> python <<EOF
> import SimpleITK as sitk
>
> img  = sitk.ReadImage("impervius_cost.tif" , sitk.sitkFloat32  )  # 5
> '32-bit unsigned integer'  # to check img.GetPixelIDTypeAsString()
> core = sitk.ReadImage("markers.tif")
>
> marker_img  = sitk.ConnectedComponent(core, fullyConnected=True)
>
> ws_line   = sitk.MorphologicalWatershedFromMarkers( img, marker_img,
> markWatershedLine=True, fullyConnected=True)
> ws_poly  = sitk.MorphologicalWatershedFromMarkers( img, marker_img,
> markWatershedLine=False, fullyConnected=True)
>
> sitk.WriteImage( sitk.Cast( ws_line   ,  sitk.sitkFloat32  ),
> 'watershed_line.tif' )
> sitk.WriteImage( sitk.Cast( ws_poly  ,  sitk.sitkFloat32  ),
> 'watershed_poly.tif' )
>
> EOF
>
> Thanks for the help
> Giuseppe
>
> [image: Inline images 1]
>
>
>
>
> On 14 February 2017 at 17:14, Matt McCormick <matt.mccormick at kitware.com>
> wrote:
>
>> Hi Giuseppe,
>>
>> Not all file formats support all pixel types. One approach is to cast the
>> image to a different type.  See `help(sitk.Cast)`.
>>
>> HTH,
>> Matt
>>
>> On Tue, Feb 14, 2017 at 4:11 PM, Giuseppe Amatulli <
>> giuseppe.amatulli at gmail.com> wrote:
>>
>>> Hi,
>>> thanks for the input.
>>> I try to follow your suggestion to build up a watershed segmentation
>>> image starting from external markers, but i get something strange.
>>>
>>> These are the files that i used
>>>
>>> wget  https://dl.dropboxusercontent.com/u/29337496/small_core.tif
>>> wget  https://dl.dropboxusercontent.com/u/29337496/cost_Int32.tif
>>>
>>> python
>>>
>>> import SimpleITK as sitk
>>>
>>> img  = sitk.ReadImage("cost_Int32.tif")
>>> core = sitk.ReadImage("small_core.tif")
>>>
>>> feature_img = sitk.GradientMagnitude(img)
>>> marker_img = sitk.ConnectedComponent(core, fullyConnected=False)
>>>
>>> ws = sitk.MorphologicalWatershedFromMarkers(feature_img, marker_img,
>>> markWatershedLine=True, fullyConnected=False)
>>>
>>> sitk.WriteImage(ws,  'watershed.jpg' )
>>>
>>>
>>> Moreover, I also try to save the final image as tiff, but i get the
>>> following error.
>>>
>>> sitk.WriteImage(ws,  'watershed.tif' )
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>>   File "/usr/local/lib/python2.7/dist-packages/SimpleITK/SimpleITK.py",
>>> line 7942, in WriteImage
>>>     return _SimpleITK.WriteImage(*args)
>>> RuntimeError: Exception thrown in SimpleITK WriteImage:
>>> /tmp/SimpleITK-build/ITK/Modules/IO/TIFF/src/itkTIFFImageIO.cxx:544:
>>> itk::ERROR: TIFFImageIO(0x2e6d880): TIFF supports unsigned/signed char,
>>> unsigned/signed short, and float
>>>
>>> seams to me the tiff is not supported or i miss some modules of ITK
>>>
>>> May anyone help me
>>>
>>> Thank you
>>> Best
>>> Giuseppe
>>>
>>>
>>>
>>>
>>>
>>> On 13 February 2017 at 16:15, Francois Budin <francois.budin at kitware.com
>>> > wrote:
>>>
>>>> Hello Giuseppe,
>>>>
>>>> Yes it is possible to create this type of segmentation with ITK.
>>>> The first step would be to convert your RGB(A) image into a grayscale
>>>> image using RGBToLuminanceImageFilter [1]. The second step would be to run
>>>> a watershed filter such as MorphologicalWatershedImageFilter [2]. If
>>>> you want to keep the lines, use "MarkWatershedLineOn()".
>>>>
>>>> Hope this helps,
>>>> Francois
>>>>
>>>> [1] https://itk.org/Doxygen/html/classitk_1_1RGBToLuminanceImage
>>>> Filter.html
>>>> [2] https://itk.org/Doxygen/html/classitk_1_1MorphologicalWaters
>>>> hedImageFilter.html
>>>>
>>>> On Mon, Feb 13, 2017 at 3:56 PM, Giuseppe Amatulli <
>>>> giuseppe.amatulli at gmail.com> wrote:
>>>>
>>>>>
>>>>> Hi,
>>>>> I'm new in ITK <https://itk.org/> and would like to have some
>>>>> directions/suggestions.
>>>>>
>>>>> I'm trying to segment the image in Figure 1 and be able to identify
>>>>> "valleys" between each one of the blue point.  In other words I
>>>>> would like to obtain a red-line on the valleys like the one show in Figure
>>>>> 2.
>>>>>
>>>>> Is this possible with ITK and if yes which are the commands/libraries
>>>>> that should use?
>>>>> Is there any python-itk example that I can use to obtain something
>>>>> similar.
>>>>>
>>>>> Thanks
>>>>> Best Giuseppe
>>>>>
>>>>>
>>>>> FIGURE 1
>>>>> [image: Inline images 2]
>>>>>
>>>>> FIGURE 2
>>>>>
>>>>> [image: Inline images 1]
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Giuseppe Amatulli, Ph.D.
>>>>>
>>>>> Research scientist at
>>>>> Yale School of Forestry & Environmental Studies
>>>>> Yale Center for Research Computing
>>>>> Center for Science and Social Science Information
>>>>> New Haven, 06511
>>>>> Teaching: http://spatial-ecology.org
>>>>> Work:  https://environment.yale.edu/profile/giuseppe-amatulli/
>>>>>
>>>>> _______________________________________________
>>>>> Community mailing list
>>>>> Community at itk.org
>>>>> http://public.kitware.com/mailman/listinfo/community
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Giuseppe Amatulli, Ph.D.
>>>
>>> Research scientist at
>>> Yale School of Forestry & Environmental Studies
>>> Yale Center for Research Computing
>>> Center for Science and Social Science Information
>>> New Haven, 06511
>>> Teaching: http://spatial-ecology.org
>>> Work:  https://environment.yale.edu/profile/giuseppe-amatulli/
>>>
>>
>>
>
>
> --
> Giuseppe Amatulli, Ph.D.
>
> Research scientist at
> Yale School of Forestry & Environmental Studies
> Yale Center for Research Computing
> Center for Science and Social Science Information
> New Haven, 06511
> Teaching: http://spatial-ecology.org
> Work:  https://environment.yale.edu/profile/giuseppe-amatulli/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170309/b1b7af8c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 114561 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20170309/b1b7af8c/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 434420 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20170309/b1b7af8c/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 49430 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20170309/b1b7af8c/attachment-0005.png>


More information about the Community mailing list