Page MenuHomePhabricator

mitkImageWriter does not support .png files correctly
Closed, ResolvedPublic

Description

I wanted to save a 2D mitkImage and/or a 3D with just one slice mitkImage as .png, which does not work correctly.

I used the following code to save the image:
mitk::ImageWriter::Pointer imageWriter = mitk::ImageWriter::New();
imageWriter->SetInput(image);
imageWriter->SetFileName("/path/name");
imageWriter->SetExtension(".png");
imageWriter->Update();
imageWriter->Write();

I figured out that the line 42 (int numberOfSlices = itkImage->GetLargestPossibleRegion().GetSize()[2];) in mitkItkPictureWrite.cpp does not result in the correct number of slices, when you input a 2D image or a 3D image with just one slice.

Furthermore, if you don't set the extension in the SetFileName() method (like i did), the code behind line 62 in the mitkImageWriter will never be reached. I didn't have a detailed look at the logic there, but either the "if" seems wrong or the code behind is dead. In general, the logic saving the different formats (.nrrd, .pic, or whatever) seems complicated and could need some refactoring. In my opition the code to save images as .png is inside the "if condition" in line 62 and so I think the "if" is just wrong. (It checks: fileName.find(".png") != std::string::npos).

Additionally, the mitkImageWriterTest does not support the .png format (or different dimensions) at all.

Event Timeline

(In reply to comment #0)

(It checks:
fileName.find(".png") != std::string::npos).

This looks good to me.

Additionally, the mitkImageWriterTest does not support the .png format (or
different dimensions) at all.

I think extending the test first would be the best approach in this case.

(In reply to comment #1)

(In reply to comment #0)

(It checks:
fileName.find(".png") != std::string::npos).

This looks good to me.

Ahhhh I'm sorry I didn't unterstand the expression at the first time. It is correct, yet I think we check for the extension via m_Extension and not via the fileName, don't we?

Additionally, the mitkImageWriterTest does not support the .png format (or
different dimensions) at all.

I think extending the test first would be the best approach in this case.

I agree ;)

Since the first issue was not a bug and the test seems to be adapted, although not within the setting of this bug, this bug is resolved.