# Failing Slicer Extension Test - ITK cannot load test image

**URL:** <https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115>\
**Category:** Development\
**Created:** [September 25, 2017, 3:11pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115 "2017-09-25T15:11:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 25, 2017, 3:11pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/1 "2017-09-25T15:11:40Z")

</div>

System: Win 10 64 Bit Visual Studio 2013

Dear all,

I’m trying to debug a test executable of a Slicer Extension (PkModeling). The problem is that running the test, which processes an image, fails in itkImageFileReader.hxx with this error:

```
File: d:\sd\itkv4\modules\io\imagebase\include\itkImageFileReader.hxx
Line: 143
Description: Could not create IO object for reading file 
D:/Dev/Repos/PkModeling/CLI/Testing/Cxx/../../../Data/SampledPhantoms/QINProstate001/Input/QINProstate001-phantom.nrrd
  Tried to create one of the following:
    MRMLIDImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

```

The project is set up as superbuild and can be build Standalone and as Slicer Extension. The test works fine in standalone but fails when build as extension (build against the ITK in Slicer). I have no idea what’s going on, and why ITK thinks it cannot load a nrrd file.

Debugging into it confirmed that in _ImageIOFactory::CreateImageIO_ the call to _ObjectFactoryBase::CreateAllInstance(“itkImageIOBase”)_ doesn’t return any ImageIOBase object that could handle an “nrrd” file.

I’m suspecting I am missing smth in my cmake configuration, since other extensions (e.g. DCMQI) built as Slicer Extension against the same ITK doesn’t have this problem 😕

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 25, 2017, 4:09pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/2 "2017-09-25T16:09:11Z")

</div>

MRMLIDImageIO is a special IO class that allows passing images between Slicer and CLI modules without writing them to file. One way of disabling it is to only create executable CLI by adding `EXECUTABLE_ONLY` in your CMakeLists.txt file:

```
SEMMacroBuildCLI(
  NAME ${MODULE_NAME}
  LOGO_HEADER ${Slicer_SOURCE_DIR}/Resources/NAMICLogo.h
  TARGET_LIBRARIES ${${MODULE_NAME}_TARGET_LIBRARIES}
  INCLUDE_DIRECTORIES
    ${vtkITK_INCLUDE_DIRS}
    ${MRMLCore_INCLUDE_DIRS}
  EXECUTABLE_ONLY
  )

```

You may also temporarily disable the mechanism by enabling `Prefer executable CLIs` option in Application settings / Modules.

---

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 25, 2017, 4:16pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/3 "2017-09-25T16:16:21Z")

</div>

Hi Andras,

Both options are already active (EXECUTABLE\_ONLY in SEMMacroBuildCLI and “Prefer executable CLIs” in Slicer itslef).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 25, 2017, 7:42pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/4 "2017-09-25T19:42:15Z")

</div>

If you don’t use MRMLIDImageIO then it means that standard ITK image IO factory classes are not registered. Compare CMakeLists.txt and source code of your CLI to other CLIs that can read images, there are probably 1-2 lines missing from your code.

---

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 25, 2017, 10:01pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/5 "2017-09-25T22:01:10Z")

</div>

Thx, I think I found it Apparently these lines in the cmake for the test did the trick:

```
if(TARGET ITKFactoryRegistration)
  target_compile_definitions(${CLP}Test PUBLIC HAS_ITK_FACTORY_REGISTRATION)
endif()

```

However I don’t completely understand why this didn’t cause an issue for the standalone build (i.e. not as slicer extension)?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 25, 2017, 10:21pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/6 "2017-09-25T22:21:35Z")

</div>

Hi @mschwier,

The `ITKFactoryRegistration` is a library specific to Slicer that was used to workaround a limitation of ITK. For some background info, read [here](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=21592)

That said, when building Slicer against Slicer, these extra lines should not be needed. The variable `ITK_LIBRARIES` is automatically updated …

> <https://github.com/Slicer/Slicer/blob/1cc0d9405f282bea47f932b0c58a288608ba014b/CMake/UseSlicer.cmake.in#L117-L121>

Also, a specific command line wrapper is used:

> <https://github.com/Slicer/Slicer/blob/eefeac9286f48552e8418a11f412b2823a09b407/Base/CLI/CMakeLists.txt#L47-L50>

> <https://github.com/Slicer/Slicer/blob/1cc0d9405f282bea47f932b0c58a288608ba014b/CMake/SlicerConfig.cmake.in#L403>

> <https://github.com/Slicer/SlicerExecutionModel/blob/983d2112ec431af20cafa49ca6cf7bd1a777869a/CMake/SEMMacroBuildCLI.cmake#L65-L69>

---

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 26, 2017, 1:44pm UTC](https://discourse.slicer.org/t/failing-slicer-extension-test-itk-cannot-load-test-image/1115/7 "2017-09-26T13:44:58Z")

</div>

Thanks for the explanation @jcfr

But does this

> [@jcfr](#):
>
> That said, when building Slicer against Slicer, these extra lines should not be needed. The variable ITK\_LIBRARIES is automatically updated …

mean, that there must be something else fishy about my setup, since I needed to add these lines to make it work? 😕
