[Insight-users] Problems with ImageMaskSpatialObject

Julien Jomier julien.jomier at kitware.com
Wed Mar 7 09:28:20 EST 2007


Markus,

> I use the ExtractImageFilter but saving the resulting image will remove 
> me all information about the position of this ROI. So thats the reasion 
> why I tried to use the ImageMaskSpatialObject because it stores also an 
> offset.

You can always set the origin of the output image of the 
ExtractImageFilter to be the origin of your requested region (at some 
point I thought that's what the ExtractImageFilter was doing...)

> I set an offset for the object to world transform, compute it and write 
> out the resulting object and there the offsets (both, object to world 
> and index to object) are still 0. That was what I ment with the cite you 
> copied. Is this just a problem of the output or is it realy ignored?

I see. You should set the ObjectToParentTransform (instead of the 
ObjectToWorldTransform) and call the ComputeObjectToWorldTransform(). 
Basically the ComputeObjectToWorldTransform() recompute the 
ObjectToWorldTransform with the current information stored in the 
SpatialObject (IndexToObject and ObjectToParent transforms).

Let me know if you are still having some issues,

Julien

> Regards,
> Markus
> 
> Julien Jomier schrieb:
>> Hi Markus,
>>
>> The index of the RequestedRegion cannot be used to set the initial 
>> offset of the image because the requested region can change but should 
>> not affect how the image is represented in the scene.
>> Moreover, ImageSpatialObject does not support the concept of streaming 
>> and regions. This should be handled at the Image level.
>>
>> That's in part why the ImageMaskSpatialObject is used, i.e. to define 
>> a region of interest.
>>
>> You can use the ExtractImageFilter beforehand to extract your region 
>> of interest or you can "paint" the appropriate region of your 
>> ImageMaskSpatialObject.
>>
>> What do you mean by "the offset to compute ObjectToWorldTransform is
>> completely ignored"? When requested if the value at a physical point 
>> or if a point IsInside() the image, the full ObjectToWorldTransform is 
>> used.
>>
>> Hope that helps,
>>
>> Julien
>>
>> Markus Mehrwald wrote:
>>> In addition to that the offset to compute ObjectToWorldTransform is 
>>> completely ignored. Maybe I am wrong with the origin and the offset 
>>> but I thing ignoring the offset for world transform should not 
>>> happen, should it?
>>>
>>> Markus Mehrwald schrieb:
>>>> Hi,
>>>>
>>>> I just had a look at the code of the ImageSpatialObject. In the 
>>>> method SetImage there is code to compute the offset of the spatial 
>>>> object. In my mind it should be better to use the index of the 
>>>> RequestedRegion instead of the origin because in my case this is the 
>>>> image I want the spatial object from. In case of having the whole 
>>>> image origin and the index of the RequestedRegion are the same anyway.
>>>>
>>>> Regards,
>>>> Markus Mehrwald
>>>>
>>>> Markus Mehrwald schrieb:
>>>>> Hi Julien,
>>>>>
>>>>> I do not really need ValueAt() at the moment. I used this code just 
>>>>> for debug reasons. As I wrote before I have created my binary image 
>>>>> first and than want it as spatial object to save it because if I 
>>>>> only save the image the translation information is gone. At the 
>>>>> moment I need ValueAt() I do not have the translation information 
>>>>> anymore (after a restart of the application and without calculating 
>>>>> everything again).
>>>>> I have tried some other things with transform and offsets but the 
>>>>> only case in which I get the correct result (but without 
>>>>> translation) is if the image passed to the ImageMaskSpatialObject 
>>>>> has its origin at 0,0.
>>>>>
>>>>> Greetings,
>>>>> Markus
>>>>>
>>>>> Julien Jomier schrieb:
>>>>>> Hi Markus,
>>>>>>
>>>>>> Can you take into account the origin of your image when you 
>>>>>> request the ValueAt()?
>>>>>> If you are using the SpatialObjectToImageFilter to create your 
>>>>>> binary image you can set the origin of the output image, if you 
>>>>>> set it to the same origin as the input image then it should work.
>>>>>>
>>>>>> One other option is to reset the IndexToObjectTransform of your 
>>>>>> ImageMaskSpatialObject with an offset of zero:
>>>>>>
>>>>>>   myImageSO->GetIndexToObjectTransform()->SetOffset( offset );
>>>>>>   myImageSO->ComputeObjectToParentTransform();
>>>>>>
>>>>>> This will not modify the origin of the image passed using the 
>>>>>> SetImage() function so you can use it later.
>>>>>>
>>>>>> Hope that helps,
>>>>>>
>>>>>> Julien
>>>>>>
>>>>>> Markus Mehrwald wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I found the problem. The image starts at 180, 130 and that is the 
>>>>>>> problem. If I translate the image to 0, 0 the code from my last 
>>>>>>> mail works correct. The problem now: I need the information of 
>>>>>>> the translation for further calculations.
>>>>>>> Any suggestions how to keep the translation? I tried
>>>>>>>
>>>>>>> ImageMaskSpatialObjectType::TransformType::OffsetType offset;
>>>>>>> offset[0] = 
>>>>>>> thresholder->GetOutput()->GetRequestedRegion().GetIndex()[0];
>>>>>>> offset[1] = 
>>>>>>> thresholder->GetOutput()->GetRequestedRegion().GetIndex()[1];
>>>>>>> imageMaskSpatialObject->GetObjectToParentTransform()->SetOffset(offset); 
>>>>>>>
>>>>>>> imageMaskSpatialObject->ComputeObjectToParentTransform();
>>>>>>>
>>>>>>> but this leads to the same problem I had before. Also with 
>>>>>>> WorldTransform.
>>>>>>>
>>>>>>> Greetings,
>>>>>>> Markus
>>>>>>>
>>>>>>> Markus Mehrwald schrieb:
>>>>>>>> Hi,
>>>>>>>> I just implemented some code which uses a 
>>>>>>>> ImageMaskSpatialObject. I created a binary image in my filter 
>>>>>>>> chain and want this now to be a spatial object so I use the 
>>>>>>>> SetImage method of the spatial object but nothing happens. The 
>>>>>>>> output of the object looks good. Coordinates (, ...) are correct 
>>>>>>>> but at every point of the so created object ValueAt gives me 0. 
>>>>>>>> The code looks like the following:
>>>>>>>>
>>>>>>>> thresholder->Update();
>>>>>>>> ImageMaskSpatialObjectType::PointType point;
>>>>>>>> imageMaskSpatialObject = ImageMaskSpatialObjectType::New();
>>>>>>>> imageMaskSpatialObject->SetImage(thresholder->GetOutput());
>>>>>>>> imageMaskSpatialObject->SetRequestedRegion(thresholder->GetOutput()->GetRequestedRegion()); 
>>>>>>>>
>>>>>>>> imageMaskSpatialObject->Update();
>>>>>>>> imageMaskSpatialObject->UpdateOutputInformation();
>>>>>>>> imageMaskSpatialObject->ComputeObjectToWorldTransform();
>>>>>>>> double ret;
>>>>>>>> for (int i = 0; i < 640; i++)
>>>>>>>> {
>>>>>>>>    for (int j = 0; j < 512; j++)
>>>>>>>>    {
>>>>>>>>        point[0] = i;
>>>>>>>>        point[1] = j;
>>>>>>>>        imageMaskSpatialObject->ValueAt(point, ret);
>>>>>>>>        if (ret != 0)
>>>>>>>>            std::cout << "ret: " << ret << std::endl;
>>>>>>>>    }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> The image coming from the thresholder has indeed a size of 
>>>>>>>> 300x280 but changing the for-loops has no consequence on the 
>>>>>>>> outcome.
>>>>>>>> I took a look at the image coming from the thresholder and it is 
>>>>>>>> what it should be, a binary image with white areas too. The code 
>>>>>>>> above never writes anything to the standard output because it 
>>>>>>>> does not find any values differing to 0.
>>>>>>>> Did I anything wrong or is it a problem of the 
>>>>>>>> ImageMaskSpatialObject?
>>>>>>>>
>>>>>>>> Thanks in advance,
>>>>>>>> Markus
>>>>>>>> _______________________________________________
>>>>>>>> Insight-users mailing list
>>>>>>>> Insight-users at itk.org
>>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
> 
> 



More information about the Insight-users mailing list