[Insight-users] Black output images (again) [ not any more ]

Luis Ibanez luis.ibanez at kitware.com
Wed Feb 7 09:35:43 EST 2007



Hi Christian,



     Your imaging pipeline works fine.



The problem in your code is related to some very
basic mistakes on the management of arguments.


    Your use of argv is utterly complicated.



Your method for converting strings into integers
can be replaced by the simple call to atoi().


Also, you are using argv[0] as the source of the
string for the lower threshold. But argv[0] actually
contains the *name* of your application.

The first command line argument is stored in argv[1],
the second in argv[2] and so on.

Please find attached the modified version of your code
that now works fine for me.


The changes were only related to the management
of the command line arguments.





If you run this in the command line with the following
arguments you will get the segmentation of the ventricles.

./RegionGrowing.exe brainweb165a10f17.mhd output.mhd 10 60 255


Note that in the source code, the position of the seed
point was modified too in order to match the actual
position of the ventricles in the brainweb165a10f17.mhd
dataset.



You can download this dataset (and other BrainWeb datasets)
from:

http://public.kitware.com/pub/itk/Data/BrainWeb/

(note that you will have to decompress
   and untar the .tgz files).




    Regards,


       Luis



=============
Christian Marshall Rieck wrote:
>>maybe you could post your code here, which would allow us to look out for the actual error.
>>
> 
> 
> The code is below. As someone pointed out, it might be hard to see what I 
> am actually trying to do. I want to segment out the ventricles. This 
> pipeline is influenced by one I saw in the documentation. If someone has a 
> better pipeline, hints or tips, please let me know. 
> 
> 
>>On a first glance, I would assume you forgot to call the Update() method of your reader at the right point of your pipeline.
> 
> 
> This code works if the neighborhoodFilter is removed. (commented in the 
> code). Then the result will be a blurred version of the input image.
> With the step, it will be black. Strangely enough, setting the seed to 
> 0,0,0 produces a single white pixel at that location in the output image.
> Is this because 0,0,0 satisfies something in the neighborhood-filter the 
> other seeds does not? ImageJ says the input image has a range of 0-32K. 
> Setting the lower and upper values to 0 and 32K should allow everything if 
> i understand correctly, but a black output it is. (i have tried some 
> debugging before asking you..)
> 
> 
> If you wish to compile, rename itkStuff to main and use neighFilter.lower nf.upper nf.replaceValue as arguments.
> 
> Here is the code:
> 
> #include <itkImageFileReader.h>
> #include <itkImageFileWriter.h>
> #include <itkCastImageFilter.h>
> #include <itkImage.h>
> #include <itkCurvatureFlowImageFilter.h> 
> #include <itkDataObject.h>
> #include <itkNeighborhoodConnectedImageFilter.h>
> #include <itkRescaleIntensityImageFilter.h>
> 
> 
> //COPIED FROM INTERNET --- START
> // http://www.codeguru.com/forum/showthread.php?s=&threadid=231054
> template <class T>
> bool from_string(T& t, 
>                  const std::string& s, 
>                  std::ios_base& (*f)(std::ios_base&))
> {
>   std::istringstream iss(s);
>   return !(iss >> f >> t).fail();
> }
>  // COPIED FOR INTERNET --- END
> 
> int itkStuff(int argc, char* argv[]) {
> 
> const unsigned int Dimension = 3;
> 
> typedef unsigned char OutputPixelType;
> typedef float InternalPixelType;
> 	
> typedef itk::Image<InternalPixelType, Dimension> InternalImageType;
> typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
> 
> typedef itk::CurvatureFlowImageFilter<InternalImageType, 
> InternalImageType> SmoothingFilterType;
> typedef itk::NeighborhoodConnectedImageFilter<InternalImageType, 
> InternalImageType> NeighborFilterType;
> typedef itk::ImageFileReader< InternalImageType > ReaderType;
> typedef itk::ImageFileWriter< OutputImageType  > WriterType;
> typedef itk::CastImageFilter< InternalImageType, OutputImageType > 
> CastingFilterType;
> typedef itk::RescaleIntensityImageFilter<InternalImageType> 
> RescaleFilterType;
> 
> 
> //instantiate
> SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
> NeighborFilterType::Pointer neigh = NeighborFilterType::New();
> ReaderType::Pointer reader = ReaderType::New();
> CastingFilterType::Pointer caster = CastingFilterType::New();
> WriterType::Pointer writer = WriterType::New();
> RescaleFilterType::Pointer rescale = RescaleFilterType::New();
> 
> 
> //set up pipeline
> smoothing->SetInput(reader->GetOutput());
> 
> //remove this step and it works (also fix rescale setInput)
> neigh->SetInput(smoothing->GetOutput());
> 
> rescale->SetInput(neigh->GetOutput());
> caster->SetInput(rescale->GetOutput());
> writer->SetInput(caster->GetOutput());
> 
> rescale->SetOutputMinimum(0);
> rescale->SetOutputMaximum(255);
> 
> smoothing->SetNumberOfIterations( 5 );
> smoothing->SetTimeStep( 0.125 );
> 
> InternalImageType::SizeType radius;
> radius[0] = 2;
> radius[1] = 2;
> radius[2] = 2;
> 
> InternalImageType::IndexType  index;
> index[0] = 143;
> index[1] = 99;
> index[2] = 171;
> 
> /*
> // testing
> index[0] = 0;
> index[1] = 0;
> index[2] = 0;
> */
> neigh->SetRadius(radius);
> neigh->SetSeed(index);
> int replace = 0;
> from_string<int>(replace, argv[2], std::hex);
> int upper = 0;
> from_string<int>(upper, argv[1], std::hex);
> int lower = 0;
> from_string<int>(lower, argv[0], std::hex);
> 
> neigh->SetReplaceValue( replace );
> neigh->SetUpper(upper);
> neigh->SetLower(lower);
> 
> char inn[] = 
> "D:\\Diplom\\20Normals_T1_analyze\\20Normals_T1_8bit\\11_3.hdr"; 
> reader->SetFileName(inn);
> char ut[] = "d:\\ut.hdr"; 
> writer->SetFileName(ut);
> 
> 
> try{
>     writer->Update();
> }
> catch(itk::ExceptionObject &  exep) {
>     std::cerr << "Exception caught";
> }
> 
> return 0;
> }
> 
> 
> Christian.
> 
> 
> 
> 
>>Regards
>> Hendrik
>>
>>
>>>I realize this problem with black output images are a recurring problem 
>>>but google could not help me, so I turn to you. (I had a very similar 
>>>question some months ago that was caused by a wrong seed, as far as my 
>>>probing can tell, this is not the case here)
>>>
>>>The pipeline is pretty basic:
>>>1. read  (float 16-bit, 3D)
>>>2. curvatureFlowImageFilter
>>>3. neighborhoodConnectedImageFilter
>>>4. cast (float, unsigned char)
>>>5. write (unsign. char, 3D)
>>>
>>>Things i have tried:
>>>
>>>-Added a step between 3 and 4 to rescale values in range 0...255. 
>>>-Kept the output as float and did not rescale
>>>-Kept the output as float and did rescale
>>>
>>>(When using float as output imageJ reported 32-bit, can 32000 as replace 
>>>value be to low in this case?)
>>>
>>>The input image is an analyze image from IBSR. See 
>>>http://www.idi.ntnu.no/~rieck/bilde/itk/input.PNG for details. The red dot 
>>>is where ImageJ is reporting coordinates and value. (screen shot 
>>>removes the mouse cursor) This coordinate is 
>>>used as the seed-point for the threshold. 
>>>
>>>I have tried different values for upper and lower limits on the 
>>>connectedThresholdFilter. But a lower value of 0 and upper of 32000 and 
>>>replace value 32000 still gives a black output image. (as everything 
>>>else) I tried 0,255 as well, in case I somehow was using values of out 
>>>range.  
>>>
>>>
>>>regards,
>>>Christian Marshall Rieck
>>>----------------------------------------
>>>All the good things in life are
>>>fattening, cancer-causing or NP-complete.
>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>
>>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RegionGrowing.cxx
Type: text/x-c++src
Size: 3402 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20070207/4da8fa83/RegionGrowing-0001.cxx
-------------- next part --------------
# This project is designed to be built outside the Insight source tree.
PROJECT(RegionGrowing)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)

ADD_EXECUTABLE(RegionGrowing RegionGrowing.cxx )

TARGET_LINK_LIBRARIES(RegionGrowing ITKCommon ITKIO ITKBasicFilters)


More information about the Insight-users mailing list