[ITK] [ITK-users] Merging segmentation masks in different region of interests
Bradley Lowekamp
brad at lowekamp.net
Tue Jan 26 09:33:32 EST 2016
Hello,
In general You can not efficiently iterate on pixel on an Image in Python or another scripting language. There are however filters which can efficiently accomplish similar things.
You should look into the ResampleImageFilter[1], and the PasteImageFilter[2].
The most logical way to is to use the ResampleImageFilters’s SetReferenceImage parameter. Use an image to represent the domain of the composite images you have ( or the original image). Then resample each segmentation on the reference image. Then you can use the AndImageFilter or overloaded operators to compose the images together.
It’s also possible to convert your segmented images into LabelMaps, so that they are represented as run-length-encoded elements. This can be more efficient for some operations, but it’s a bit more tricky.
HTH,
Brad
[1] http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ResampleImageFilter.html
[2] http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1PasteImageFilter.html
> On Jan 26, 2016, at 9:21 AM, Alberto Bert <bert.alberto at gmail.com> wrote:
>
> Thanks Tim,
>
> according to the documentation, RegionOfInterestImageFilter should do what you say, that is why I tried to used it. Unfortunately, it seems not to keep the original logical references...
>
> I am not sure I can efficiently do what you suggest with SimpleITK, but if it turns out to be the only way, I guess I will need to switch to the original ITK. I hoped there was a way to do it without a pixel by pixel copy…
>
> Any other suggestions?
>
> Thanks!
> Alberto
>
>> On 26 Jan 2016, at 11:31, Timothee Evain <tevain at telecom-paristech.fr <mailto:tevain at telecom-paristech.fr>> wrote:
>>
>> Hello Alberto,
>>
>> If I remember well, the RegionOfInterestImageFilter keeps the subparts in the same physical space, i.e. a same index will get you the same pixel/voxel in the ROI as in the original. So I would use an iterator to create your full mask image. Something like :
>>
>> itk::Image<Type,Dim>::Pointer FullMask=itk::Image<Type,Dim>::New();
>> FullMask->SetRegions(OriginalImage->GetLargestPossibleRegion());
>> FullMask->Allocate();
>>
>> itk::ImageRegionIteratorWithIndex<itk::Image<Type,Dim>> Iter(FullMask,FullMask->GetLargestPossibleRegion());
>> Iter.GoToBegin();
>>
>> while(!Iter.IsAtEnd())
>> {
>> itk::Index<Dim> CurrentPoint=Iter.GetIndex();
>> if(//There you test the index to know from which subimage it belong//)
>> {
>> Iter.Set(SubImage->GetPixel(CurrentPoint));
>> }
>> ++Iter;
>> }
>>
>> HTH,
>>
>> Tim
>>
>> ----- Mail original -----
>> De: "Alberto Bert" <bert.alberto at gmail.com <mailto:bert.alberto at gmail.com>>
>> À: "ITK Users" <insight-users at itk.org <mailto:insight-users at itk.org>>
>> Envoyé: Mardi 26 Janvier 2016 11:07:49
>> Objet: [ITK] [ITK-users] Merging segmentation masks in different region of interests
>>
>> Hi,
>>
>> I have several rectangular regions of interest from a single image (extracted using RegionOfInterestImageFilter), and I am processing one at a time to extract from each of them a segmentation masks (image of labels with 0 or 1). Finally, I would need to “merge” (i.e. “combine” or “and”) the various ROI masks (different size and origin) in a single mask having the same size and origin of the original image. Let’s say I would need to “put back in the right place” the ROI masks.
>>
>> The AndImageFilter does not allow me to combine the various ROI masks ("Inputs do not occupy the same physical space!”). I browsed the documentation but I could not find a viable solution...
>>
>> I am currently using SimpleITK.
>>
>> Can you help me please?
>>
>> Thanks a lot!
>> Best
>> Alberto
>> _____________________________________
>> Powered by www.kitware.com <http://www.kitware.com/>
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/insight-users
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160126/4bf2dbdf/attachment.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list