Page MenuHomePhabricator

Segmentation module causes crash on using wipe with 2d image
Closed, ResolvedPublic

Description

When using the wipe tool of the segmentation bundle on a 2d image, mitk crashes with the following message:
Dimension 1 is not in ::itk::GetImageDimension<ItkOutputImageType>::ImageDimension)

Event Timeline

it only crashes on a freshly started mitk (no 3d images have previously been loaded)

The same error occurs with the paint tool

Crashes are always critical due to potential loss of data.

Results from last bug squashing:

  1. Segmentation image has a different dimension from the original image

How to reproduce:

  • Load 2D Image (be sure the loaded image has a dimension of 2)
  • Open segmentation plugin
  • Create new segmentation: Image has a dimension of 3
  1. Described crash did not occur during Debug mode

3.Crash occurs during CastToItkImage in mitk::PaintbrushTool::UpdateContour

CastToItkImage(m_WorkingSlice, correctPixelTypeImage );

However, in our opinion the weird casting loop (mitk->itk->mitk) makes no sense and/or has no effect on the next processing steps. So, the code could be reduced as follows:

[OLD VERSION]

void mitk::PaintbrushTool::UpdateContour(const StateEvent* stateEvent)
{

const PositionEvent* positionEvent = [..];
if (!positionEvent) return;

itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer correctPixelTypeImage;
CastToItkImage(m_WorkingSlice, correctPixelTypeImage );
assert (correctPixelTypeImage.IsNotNull() );

itk::Image< ipMITKSegmentationTYPE, 2 >::DirectionType imageDirection;
imageDirection.SetIdentity();
correctPixelTypeImage->SetDirection(imageDirection);

Image::Pointer temporarySlice = Image::New();
CastToMitkImage( correctPixelTypeImage, temporarySlice );

mitkIpPicDescriptor* stupidClone = mitkIpPicNew();
CastToIpPicDescriptor( temporarySlice->GetSliceData(), stupidClone );

[..]

[PROPOSED VERSION]

void mitk::PaintbrushTool::UpdateContour(const StateEvent* stateEvent)
{

const PositionEvent* positionEvent = [..];
if (!positionEvent) return;

mitkIpPicDescriptor* stupidClone = mitkIpPicNew();
CastToIpPicDescriptor( m_WorkingSlice->GetSliceData(), stupidClone );

[..]
  1. After implementing the solution proposed in point 3, we noticed another crash which occurs for 2D and 3D images:

The application crashes or throws an error message when the size of the brush tool is bigger than the dimension [x,y] of the stupidClone image. Proposed Solution: set maximal size of the brushTool to the smallest dimension of the stupidClone image.

if( stupidClone->n[0]-1 < pixelWidth )
  pixelWidth = stupidClone->n[0]-1;

if( stupidClone->n[1]-1 < pixelHeight )
  pixelHeight = stupidClone->n[1]-1;

Further, when moving the mouse cursor to a different view (e.g. transversal to coronal) the image dimension of stupidClone is not updated. The dimension and tool size should always be adapted to the current view. Hence, the method PaintbrushTool::UpdateContour should be called when the user switches with the mouse to another view.

We took a look at it:

  • Problem also occurs in Debug
  • Brush size is not causing a problem as far as we could see.
  • Your proposed solution (without the casting) is missing the "SetIdentity" call!

We made a few changes. Work in progress. Still a problem remaining:
at the moment
SegTool2D::GetAffectedImageSliceAs2DImage(event, image)
is returning a 2D image with extent yMax=1.

Have a look at:
mitkExtractSliceFilter.cpp line 382:

vtkImageData* reslicedImage;
reslicedImage = m_Reslicer->GetOutput();

the vtk output has in extents ymax = 1

in line 395 it is used to iniitalize an MITK image

resultImage->Initialize(reslicedImage);

Here suddently the mitk Image has a yMax of 2.
The reason lies in

mitkImage.cpp line 858

vtkimagedata->GetDimensions()[i] is returning 2! The call will do the following calculations:

this->Dimensions[1] = extent[3] - extent[2] + 1;

.. it increments by 1 ... the question is why???
Propably the understanding of VTK Extent and MITK extent is different..
Do more reserach here next time

Pushed a temporary solution to branch bug-13161-wipe2D.

Using this solution ,the extractSliceFilter will make sure that a 2D mitk image is returned, even if the VTK Data is 1D (line).

Another problem now occurred: Changing the brush size is not working anymore now. Have to check that in next bugsquashing.

for this issue, start checking at mitkPaintbrushTool.cpp line 117

Hm.. apparently only works in debug mode.
In release modethe feedback contour is not visible

Granted release fix flag since master is already locked due to upcoming release

Changed Target Milestone to upcoming release

New remote branch pushed: bug-13161-WipeTool-Integration

[517e9a]: Merge branch 'bug-13161-WipeTool-Integration'

Merged commits:

2012-11-07 18:27:33 Jan Hering [4d066d]
Corrected mirroring of computed points for even sizes

  • the mirrored positions have to be shifted by +1 because the central
  • point of the contour is the position [+0.5,+0.5] (the upper right
  • corner of the current pixel) and not the midpoint [0,0] of the pixel

2012-11-07 18:26:32 Jan Hering [fe3e98]
Enhanced radius computation

  • works now correct also for even contour sizes

2012-10-31 18:31:37 Jan Hering [b2aeb9]
Fixed circle contour computation

  • fixed upperLeft() method
  • comparing the distance to the 'outer_radius'
  • fixed reverse vector traversal when inserting points into contour

2012-10-31 17:34:23 Bastian Graser [91494c]
Changed Square shape to circle shape. STill something is wrong, it crashes.


2012-10-31 15:48:48 Bastian Graser [a43cae]
First solution with square contour


2012-10-24 16:58:42 Bastian Graser [611056]
work in progress: got rid of all image handling stuff in update contour.


2012-10-24 16:26:32 Bastian Graser [527b68]
works so far, but method to make contour image is really bad


2012-10-24 14:36:56 Bastian Graser [4a6fa0]
temp changes


2012-10-17 17:30:47 Bastian Graser [22430e]
Fixed bug where ExtracedSliceFilter is giving back a 1D mitk Image. But now, the brushsize of the painttool is not working anymore.


2012-10-10 17:41:30 Bastian Graser [60ae02]
work in progress

[38567b]: Merge branch 'bug-13161-WipeTool-RemoveComments'

Merged commits:

2012-11-28 16:40:37 Jan Hering [c944cc]
Removed redundant std::cout messages

Fix manually verified after merge into master. Nightly builds without errors. Closing bug.