[Insight-users] Connected Threshold Image Filter and RAW images

Diego R. Medaglia diegomedaglia at terra.com.br
Wed Feb 8 10:34:35 EST 2006


Hi!
    I am trying to segment 2D numbered (.1, .2, .3 ,...) raw medical images with ConnectedThresholdImageFilter, but for whatever upper and lower threshold values I use, the resulting image is a tottaly BLACK one...  I'm using unsigned short for the pixel type, don't know if that's correct. The images are 64x64 pixels in dimension, and all index adjustments, file names and threshold values seem to be just right. Any ideas on this one?

Here's the code:
//(mscVolumeProperties is a class for storing height, width, file names, etc... through the entire app)

// rgSeg.h
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRawImageIO.h"
#include "itkVTKImageExport.h"
#include "itkVTKImageExportBase.h"
#include "itkImage.h"
#include "itkConnectedThresholdImageFilter.h"
#include <string>
using std::string;

class mscVolumeProperties;

class RegionGrowingSeg
{
private:
    typedef unsigned short PixelType;
    typedef itk::Image< PixelType > ImageType;
    typedef itk::RawImageIO<PixelType > IOType;
    typedef itk::ImageFileReader< ImageType > ReaderType;
    typedef itk::ImageFileWriter< ImageType > WriterType;
    typedef itk::ConnectedThresholdImageFilter< ImageType, ImageType > ConnectedFilterType;

    string inputFile;
    string outputFile;
    mscVolumeProperties* vp;
    ReaderType::Pointer reader;
    WriterType::Pointer writer;
    IOType::Pointer io;
    ConnectedFilterType::Pointer connectedThreshold ;
    PixelType lowerThreshold;
    PixelType upperThreshold;
    ImageType::IndexType index;

public:
    RegionGrowingSeg(mscVolumeProperties* v){vp = v;}
    RegionGrowingSeg(){ vp = NULL;}
    static RegionGrowingSeg* New(mscVolumeProperties* v){return new RegionGrowingSeg(v);}
    static RegionGrowingSeg* New(){return new RegionGrowingSeg();}
    void setVP(mscVolumeProperties* v) {vp = v;}
    void setInputFileName(const char* ifn){inputFile.assign(ifn);}
    void setOutputFileName(const char* ofn){outputFile.assign(ofn);}
    void setLowerThreshold(unsigned short lt){lowerThreshold = lt;}
    void setUpperThreshold(unsigned short ut){upperThreshold = ut;}

    void setIndex(int* in)
    {
        index[0]=in[0];
        index[1]=in[1];
    }

    void segment();
    const char* getInputFileName() const {return inputFile.c_str();}
    const char* getOutputFileName() const {return outputFile.c_str();}
    unsigned short getLowerThreshold(){return lowerThreshold;}
    unsigned short getUpperThreshold(){return upperThreshold;}
    int* getIndex()
    {
        int ri[2];
        ri[0] = index[0];
        ri[1] = index[1];
        return ri;
    }
};


// rgSeg.cpp:
#include "rgSeg.h"
void RegionGrowingSeg::segment()
{
    reader = ReaderType::New();
    writer = WriterType::New();
    io = IOType::New();
    //Sets para as dimensões da imagem raw:

    io->SetDimensions(0,vp->GetHeight());
    io->SetDimensions(1,vp->GetWidth() );
    reader->SetImageIO( io );
    writer->SetImageIO( io );

    reader->SetFileName( inputFile.c_str() );
    connectedThreshold = ConnectedFilterType::New();
    connectedThreshold->SetInput( reader->GetOutput() );

    connectedThreshold->SetReplaceValue( 1 );
    connectedThreshold->SetSeed( index );
    connectedThreshold->SetLower( lowerThreshold );
    connectedThreshold->SetUpper( upperThreshold );

    writer->SetInput( connectedThreshold->GetOutput() );
    writer->SetFileName( outputFile.c_str() );
    try{
        writer->Update();
        }
    catch( itk::ExceptionObject & err ){
    std::cerr<<"Excecao capturada!";
    std::cout << err << std::endl;
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060208/1f2896f8/attachment.html


More information about the Insight-users mailing list