[Insight-users] Question about ManagedITK/TIF format/ SharpImage ...

Dan Mueller dan.muel at gmail.com
Sat May 14 01:04:31 EDT 2011


Hi Christian,

Thanks for the detailed email. (You would be surprised how many people
write emails saying "it says an error, how do I fix it" :S)

I don't think the issue you encountered is with the patch -- you get
other errors if the patch is not applied properly (but these errors
are further along in the process).

The error seems to be related to finding the files in the ITK Review folder.

Here are a few suggestions:
1. Did you compile ITK and ManagedITK in the same mode? i.e. both in
Debug or Release mode? (For performance reasons I suggest compiling in
Release mode, and only creating a Debug build if you encounter issues
within ManagedITK which you need to debug).

2. Please open C:/../InsightToolkit-3.20.0-Binaries/CMakeCache.txt and
confirm you have the following values:
BUILD_SHARED_LIBS:BOOL=OFF
ITK_USE_REVIEW:BOOL=ON
(I always build with shared libraries off, but I'm not sure if this is
the problem).

3. Please compile a simple test application to see if other programs
can use the review folder.
For example:
(a) Save these files to a temp folder
=== CMakeLists.txt ==============================
PROJECT(Test)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

# Find and use required packages
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

# Add this as include directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${SOURCE_PATH})

# Executables
ADD_EXECUTABLE(Test test.cxx)
TARGET_LINK_LIBRARIES(Test ${ITK_LIBRARIES})
=============================================
=== test.cxx ===================================
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkFlatStructuringElement.h"

int main (int argc, char *argv[])
{
  itk::FlatStructuringElement<2>::RadiusType radius;
  radius.Fill(2);
  itk::FlatStructuringElement<2> kernel =
    itk::FlatStructuringElement<2>::Ball(radius);
  return EXIT_SUCCESS;
}
=============================================
(b) Open CMake, set the source folder to the temp location, set the
binary folder somewhere else, configure, generate
(c) Open the generated solution file, compile in the same mode (Debug,
Release) as you compiled ITK.
(d) Let me know if it works. If a simple test application like this
does not work, then it is a problem with your ITK configuration.

Please let me know if any of these suggestions help.

Good luck.

Cheers, Dan

On 13 May 2011 23:21, christian.herrera at gmail.com
<christian.herrera at gmail.com> wrote:
> Dan,
>
> I tried to recompile the ManagedITK from Source following the instructions
> at Page 7 of IJ_151_ManagedITK-3.6.0.2.pdf article. I did the following:
>
> 1. Download ITK (Original) and Managed ITK both versioned as 3.20.0
>
> 2. Unzip them; Original to -> "C:/itk_2/InsightToolkit-3.20.0" and Managed
> to -> "ManagedITK-src-3.20.0.0
> "
> 3. Patch ITK (Original) with the Patch instructions at the ManagedITK folder
> (Eg. C:\itk_2\ManagedITK-src-3.20.0.0\Patch>patch
> C:\itk_2\InsightToolkit-3.20.0\Code
> \Common\itkShapedNeighborhoodIterator.h <
> itkShapedNeighborhoodIterator.h.patch), I did this for the 3  files to
> patch.
>
> 4. Open CMAKE and Configure ITK (Original) with ITK_USE_REVIEW = ON. For
> "Where to build the binaries" I set another folder called
> "InsightToolkit-3.20.0-Binaries". I press configure and generate...
> everything works fine. See picture attached..
>
> 5. I open Visual Studio 2005 and open the ITK.sln located at
> "InsightToolkit-3.20.0-Binaries". It compiles withour problem after ~15
> minutes.
>
> 6. Open CMAKE again but now configure ManagedITK (located at
> ".../ManagedITK-src-3.20.0.0"). I set the "Where to build binaries" to
> ".../ManagedITK-src-3.20.0.0-Binaries" similar to what I did for ITK
> previously.  It automatically sets the ITK_DIR to ->
> "C:/itk_2/InsightToolkit-3.20.0-Binaries" . I press configure and
> generate... everything works fine. See picture attached...
>
> 7. Before opening the "ManagedITK.sln" I run FinishCMake.bat file located in
> the "C:/itk_2/InsightToolkit-3.20.0-Binaries" folder. The bat program runs
> as expected.
>
> 8. I open the "ManagedITK.sln" and start Building all the projects. A few
> seconds later the following errors appear repeateadly (See picture
> attached):
>
> 1>itkManagedFlatStructuringElement_2.cxx
> 1>.\Common\itkManagedFlatStructuringElement_2.cxx(47) : fatal error C1083:
> Cannot open include file: 'itkFlatStructuringElement.h': No such file or
> directory1>itkManagedImage_VIF3.cxx
> 1>c:\itk_2\manageditk-src-3.20.0.0-binaries\source\common\itkManagedTypes.cxx(64)
> : fatal error C1083: Cannot open include file: 'itkQuadEdgeMeshPoint.h': No
> such file or directory
>
> 9. I searched on the web and in the Mailing list I found something related
> to ITK_USE_REVIEW, but I used this option as indicated, even I tried using
> when configuring ManagedITK, none of them worked.
>
> Do you have any suggestions?
>
> I suspect about the Patch you mentioned, which comes in ManagedITK and I
> applied to ITK according to the Patch's Readme instructions. This patch just
> run, apparently,  and it didn't give any feedback, I had to close the black
> window that remained in my screen..... :-S
>
> Thank you very much... for your support....
>
>
>
> ---------------------------------------------------------------------------------------------
>
> Hi Christian,
>
> You are correct: ManagedITK does not support US2 out-of-the-box.
>
> However, the good (and bad) news is that ManagedITK can support US2 if
> you recompile from source. To do this you need to follow the
> instructions on page 7 of the ManagedITK article here:
>   http://manageditk.googlecode.com/files/ManagedITK-article.pdf
> At step 5 (Configure ManagedITK) you need to select the "unsigned
> short" pixel type. If you are not familiar with Visual Studio + CMake
> + ITK, this process can be quite difficult. Good luck.
>
> You may be able to get US2 support in SharpImage by replacing the
> vanilla ManagedITK.Common.dll with the custom one you compile yourself
> (no guarantees this will work though).
>
> Let me know how you get on.
>
> Cheers, Dan
>
>
>
> christian.herrera at gmail.com wrote:
>>
>> Hello,
>>
>> I am a "newcomer"on the ITK area; I have been working tryng to execute
>> some algorithms to a TIF image, and then display the TIF image output.
>> When I re-create the Image to display it, the output is not good. It seems
>> that I am loosing some data because of the way I use ManagedITK to
>> read/write this format.
>>
>>  All these in an application I developed. When I try to open the TIF image
>> using the SharpImage 0.9.5, I get the following error message:
>>
>>  "Unable to open image file." itk.itkInvalidWrappedTypeException: Could
>> not create an instance of 'itk.itkImage_US2'. The given type may not be
>> supported or may be invalid.--->System.NullReferenceException: The type
>> 'itk.itkImage_US2' could not be found in ManagedITKCommon,
>> Version=3.4.0.1, Culture=neutral, PublicKeyToken=null at
>> itk.itkImage.CreateInstance() --- End of inner exception stack trace ---
>> ar itk.itkImage.CreateInstance() at itk.itkImage.New(itkPixelType
>> pixelTypr, UInt32 dim) at SharpImage.Main.siFormMain.OpenImage(Boolean
>> display, itkPixelType pixelType, Int32 dim, String fullPath) at
>> SharpImage.Main.siFormMain.OpenImage(Boolean display, String title).
>>
>> So my understanding is that ManagedITK doesn't suport this type of Image
>> (US2).  I would appreciate if you could tell me a "workaround" for this. I
>> am using C# for my development I would like to continue using it .... :-)
>>
>> Regards,
>>
>> Christian Herrera,
>>
>
> christian.herrera at gmail.com wrote:
>>
>> Hello,
>>
>> I am a "newcomer"on the ITK area; I have been working tryng to execute
>> some algorithms to a TIF image, and then display the TIF image output.
>> When I re-create the Image to display it, the output is not good. It seems
>> that I am loosing some data because of the way I use ManagedITK to
>> read/write this format.
>>
>>  All these in an application I developed. When I try to open the TIF image
>> using the SharpImage 0.9.5, I get the following error message:
>>
>>  "Unable to open image file." itk.itkInvalidWrappedTypeException: Could
>> not create an instance of 'itk.itkImage_US2'. The given type may not be
>> supported or may be invalid.--->System.NullReferenceException: The type
>> 'itk.itkImage_US2' could not be found in ManagedITKCommon,
>> Version=3.4.0.1, Culture=neutral, PublicKeyToken=null at
>> itk.itkImage.CreateInstance() --- End of inner exception stack trace ---
>> ar itk.itkImage.CreateInstance() at itk.itkImage.New(itkPixelType
>> pixelTypr, UInt32 dim) at SharpImage.Main.siFormMain.OpenImage(Boolean
>> display, itkPixelType pixelType, Int32 dim, String fullPath) at
>> SharpImage.Main.siFormMain.OpenImage(Boolean display, String title).
>>
>> So my understanding is that ManagedITK doesn't suport this type of Image
>> (US2).  I would appreciate if you could tell me a "workaround" for this. I
>> am using C# for my development I would like to continue using it .... :-)
>>
>> Regards,
>>
>> Christian Herrera,
>>
> http://itk-insight-users.2283740.n2.nabble.com/file/n6361284/CMAKE_ITK.jpg
> http://itk-insight-users.2283740.n2.nabble.com/file/n6361284/CMAKE_MANAGEDITK.jpg
> http://itk-insight-users.2283740.n2.nabble.com/file/n6361284/VS_ERRORS.jpg


More information about the Insight-users mailing list