[Insight-users] help with itkUnaryFunctorImageFilter
David Gavilan
david.gavilan at pucp.edu.pe
Wed Mar 2 12:10:58 EST 2011
Hello,
My name is David. I have RGB images taken from a microscope with a dynamic
range of 2^16. I worked in an algorithm in Matlab and now I have been trying
to use ITK. I have successfully obtained the gray image using the
itkRGBtoLuminanceFilter but now I have problems trying to perform the next
pixel to pixel operation . I want to obtain a binary image that is the
result of this comparison GRAY< RED. For that I have to obtain the red layer
of my image but this is the part where I have been struggling. I am using
the UnaryFunctorImageFilter to get this layer and then use another
procedure to perform the comparison. When I compile my code I don't get any
errors but when I see my red layer all I see is a entirely black image. I
will thank you a lot if you could help me. I believe I am not understanding
very well the UnaryFunctorImageFilter and it will help me a lot if you have
more examples about this filter.
Thank you so much in advance,
David.
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------------------
#ifndef OPERACIONES_H_
#define OPERACIONES_H_
template <class TInput,class TOutput>
class operaciones {
public:
TOutput operator()( const TInput & A ) const
{
return PixelTub.GetRed();
}
bool operator!=(const operaciones & operacion) const
{
return (PixelTub!=operacion.PixelTub)?true:false;
}
bool operator==(const operaciones & operacion) const
{
return !(*this!=operacion);
}
operaciones() {}
virtual ~operaciones() {}
private:
TInput PixelTub;
};
#endif /* OPERACIONES_H_ */
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------------------
#include <iostream>
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkGradientMagnitudeImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkRGBPixel.h"
#include "itkRGBToLuminanceImageFilter.h"
#include "operaciones.h"
#include "itkUnaryFunctorImageFilter.h"
int main( int , char * argv[])
{
using namespace std;
const unsigned int Dimension = 2;
typedef unsigned short PixelType;
typedef itk::RGBPixel< unsigned short> RGBPixelType;
typedef itk::Image< RGBPixelType, Dimension > RGBImageType;
typedef itk::ImageFileReader< RGBImageType > ReaderType;
typedef operaciones<RGBPixelType,PixelType> TOperaciones;
typedef itk::Image< PixelType, Dimension > GrayImageType;
typedef
itk::UnaryFunctorImageFilter<RGBImageType,GrayImageType,TOperaciones>
TFiltroFunctor;
ReaderType::Pointer lectordeimagen = ReaderType::New();
lectordeimagen->SetFileName("C:\\Documents and
Settings\\David1\\Desktop\\Tuberculosis\\Prueba1\\Foto003_1.TIF");
lectordeimagen->Update();
cout<<"Imagen Leida .\n";
RGBImageType::Pointer imagen=lectordeimagen->GetOutput();
RGBImageType::RegionType region=imagen->GetLargestPossibleRegion();
RGBImageType::SizeType size=region.GetSize();
int f,c;
f=size[0];
c=size[1];
cout<<"La imagen tiene "<<f<<" pixeles por " << c<< " pixeles .\n";
typedef itk::RGBToLuminanceImageFilter<RGBImageType,GrayImageType>
GrayRescaleFilterType;
GrayRescaleFilterType::Pointer filter=GrayRescaleFilterType::New();
filter->SetInput(lectordeimagen->GetOutput());
typedef itk::ImageFileWriter<GrayImageType> WriterType;
WriterType::Pointer escritordeimagen = WriterType::New();
WriterType::Pointer escritordeimagen2 = WriterType::New();
escritordeimagen->SetInput( filter->GetOutput());
escritordeimagen->SetFileName("C:\\Documents and
Settings\\David1\\Desktop\\Tuberculosis\\Prueba1\\Foto003_1gray2.tif");
escritordeimagen->Update();
cout<<"Imagen en Grises hecha .\n";
//CREAMOS UNA IMAGEN Y RECORREMOS LLENANDOLA CON EL RED
GrayImageType::Pointer capaR= GrayImageType::New();
GrayImageType::IndexType comienzo;
GrayImageType::SizeType tamano;
GrayImageType::RegionType region2;
comienzo.Fill(0);
tamano[0]=f;
tamano[1]=c;
capaR->SetRegions(region2);
capaR->Allocate();
cout<<"Listo para capa roja.\n";
TFiltroFunctor::Pointer filtro=TFiltroFunctor::New();
filtro->SetInput(lectordeimagen->GetOutput());
escritordeimagen->SetInput(filtro->GetOutput());
escritordeimagen->SetFileName("C:\\Documents and
Settings\\David1\\Desktop\\Tuberculosis\\Prueba1\\Foto003_1Rojo.tif");
escritordeimagen->Update();
cout<<"capa roja lista.\n";
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110302/2a811fb9/attachment.htm>
More information about the Insight-users
mailing list