Page MenuHomePhabricator

The IsImageGeometry flag is not set when initializing an image with a plane geometry
Closed, ResolvedPublic

Description

Manually creating a planegeometry an initializing an mitk::Image with it will result into an image with a geometry for which the IsImageGeometry flag is false.

Code snippet:

mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New();
planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
planegeometry->SetOrigin(origin);  

//initialize image
imgMem->Initialize(pt, 40, *planegeometry);

This was found when creating test images for the ImageToItk test. The MITK_ASSERT_EQUAL( imgMem, imgAfterCast ) was failing because the geometry of the imgMem is marked as non-ImageGeometry.

Event Timeline

The question is, whether the mitkImage class should handle this case or whether the user is responsible for setting the flag on his own.

Solution proposal:

The different initialization methods for different geometry types are chained so that all calls end up in the

void mitk::Image::Initialize(const mitk::PixelType&, const mitk::TimeGeometry& ,unsigned int, int)

method. This calls the Initialize( pixeltype, dim, dimx, channel ) method, where the created default TimeGeometry is marked as ImageGeometry for each TimeStep.

However, the IsImageGeometry value (true) is reset to false for the calls:

l.882: TimeGeometry::Pointer cloned = geometry.Clone();

SetTimeGeometry(cloned.GetPointer());

l.886: Superclass::SetGeometry( geometry.GetGeometryForTimeStep(0) )

Taking the ImageGeometry flag value from the passed-in geometry.

Solution proposal:

insert
882 cloned->ImageGeometryOn() for each timestep

and create a clone and set ImageGeometryOn() in case of a single timestep

l. 886 Superclass::SetGeometry( cloned )

User hering has pushed new remote branch:

bug-19327-ImageWithoutImageGeometry

I don't get it from the description above. :)

Where exactly is the flag reset? Only when cloning? Why is the flag reset? Need that to be fixed in the image or in the geometry? I would expect that when cloning a geometry that its IsImageGeometry flag is cloned as well?

The flag is not reset. If the geometry with which the image is initialized is an image geometry, the flag is correctly propagated by the cloning in the Initialize methods.

However, if the geometry we use for the initialization has the flag set to false, the resulting geometry of the image will have the same flag. So actually there are two options:

(1) it is user's responsibility to use the Initialize methods with a geometry having IsImageGeometry == true, here a check for the flag could be introduced in the Initialize() methods

(2) we force the geometry passed to the Image::Initialize() methods to be an image geometry, as there should be no image with an non-image geometry.

Currently the solution (2) is implemented in the remote branch.

[92cd86]: Merge branch 'bug-19327-ImageWithoutImageGeometry'

Merged commits:

2015-09-23 13:25:24 Jan Hering [869654]
Add warning message when changing geometry

When initializing with non-image geometry, the clone (!) is set to IsImageGeometry==ON and the user is warned


2015-09-16 17:45:14 Jan Hering [7a2414]
Ensure a geometry used in images has always IsImageGeometry ON