[Insight-users] Black output images (again)

Christian Marshall Rieck rieck at stud.ntnu.no
Wed Feb 7 05:34:08 EST 2007


> 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
> 
> 


More information about the Insight-users mailing list