Hi,
I am using simple code which I found in ITK Example.
I need to display nifti image, but all I got is black box. And when I hover the mouse over the window, the color changes from black to white, and I can’t see the image.
I think I am doing something wrong, because the code is very trivial. Any help is much appreciated. Thank you!
Because you declare your image as 2D, only the first slice is read. And if it only contains zero-values (black) pixels, you can’t see anything else when you visualize it.
@mabou give it a try if you use ITK from master.
If not, you can still try it copying the files itkViewImage.h and itkViewImage.hxx from here
to your include directory.
You can see an example of usage here, but basically would be:
// Change QuickView.h for itkViewImage.h
#include "itkViewImage.h"
...
reader->Update();
itk::ViewImage<ImageType>::View(reader->GetOutput());
And let us know! And as @dzenanz said, if your image is 3D, change the dimension of ImageType.
Thanks all for your help.
I have copied itkViewImage.h and itkViewImage.hxx and used the code of runViewImage.cxx and I think it works better now, because when moving the mouse cursor, I can see the coordinates changes, but the third coordinate is always zero, which means it is always the first slice (which is black of course).
Now my question: how I can move between slices? It should be done from the code or by moving the cursor?
You don’t need to change the code. From the top of my head (not in front of computer right now) try to press the right click button with the cursor in the slice you want to move, then move the mouse. You might need to first reorient the camera a little to do this in the Z slice. To orient the camera do the same (hold right-click) but with the cursor outside the image. Easier to play with it than to explain!
Okay, I could play with the camera orientation as you said (hold right-click outside the cursor). But, still I only see black frame, and the coordinates changed from (0,0,0) to (230,230,0), which means the Z slice is always zero!
The image values are probably being cast to unsigned char, which has a range 0-255. So all your voxels get converted to 0 (black) or 1 (less deep black). To have non-black visualization, try rescaling your image to pixel type unsigned char using RescaleIntensity filter.
Hi Pablo,
I am new to ITK/VTK. I tried exactly the same code and CMakeList. It compiles fine. But I get seg fault whenever I ran the code. I have included my code below. I really want to get it working. Any help is much appreciated. Thank you so much!
Chang
cmake_minimum_required(VERSION 3.10)
project(HelloITK)
set(ITK_DIR "/home/chang2/c2dev/ITK-Build")
set(VTK_DIR "/home/chang2/c2dev/VTK-Build")
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
# Add executable called "HelloITK" that is built from the source file "HelloITKWorld.cxx".
# Any number of source files can be listed here.
add_executable(HelloITK HelloITK.cxx)
# Link the executable "HelloITK" to the libraries.
target_link_libraries(HelloITK ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})