[Insight-users] Re: RGBToLuminanceFilter

Luis Ibanez luis.ibanez@kitware.com
Tue May 11 02:54:18 EDT 2004


This is a multi-part message in MIME format.
--------------040103090505060105020903
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


Hi Michael,

You are simply missing to connect the input of the
filter.


The pipeline should look like:


    Reader ---> Filter ----> Writer


So far, you have connected the output of the filter
as input to the writer, but haven't connected the
output of the reader (or any other filter) as input
to the filter.

The filter is rightfully complaining since you are
requesting to process data but haven't provided any
input.

An example on the use of the RGBToLuminance image
filter has been added under:

      Insight/Examples/Filtering/
                    RGBToGrayscale.cxx

The same file is also attached to this email.


Please let us know if you have further questions,


    Thanks


       Luis



------------------------
Michael Hawrylycz wrote:
>  Hi Luis, 
> 
>   Thanks for the input on itkRGBToLuminanceFilter.  However when I call
> this as:
> 
> 
>   typedef itk::RGBPixel<unsigned char>   PixelType;
>   typedef itk::Image< PixelType, Dimension >  InputImageType;
>   typedef itk::Image<unsigned char, Dimension >  OutputMonoImageType;
>   
> 
>   typedef
> itk::RGBToLuminanceImageFilter<InputImageType,OutputMonoImageType >
> LumFilterType;
>   LumFilterType::Pointer lumfilter = LumFilterType::New();
> 
>   monowriter->SetFileName(outputMono);
>   monowriter->SetInput(lumfilter->GetOutput());
>   
>   try 
>    { 
>     monowriter->Update(); 
> 
>    } 
>   catch( itk::ExceptionObject & err ) 
>    { 
>     std::cout << "ExceptionObject caught !" << std::endl; 
>     std::cout << err << std::endl; 
>     return -1;
>    } 
> 
> I get the following run time error:
> 
>  UnaryFunctorImageFilter: At least 1 inputs are required but only 0 are
> specified.  
> I am obviously not setting the input image here,  but
> lumfilter->SetInput(reader->GetOutput()) won't compile.
> 
> Still a little confused by templates,
> 
> Mike
> 
> 
> 
> 
> Mike Hawrylycz, Ph.D.
> Director, Informatics
> Allen Institute of Brain Science
> mikeh@alleninstitute.org
> (206) 548-7011
>  
> 
===============================================




--------------040103090505060105020903
Content-Type: text/plain;
 name="RGBToGrayscale.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="RGBToGrayscale.cxx"

/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: RGBToGrayscale.cxx,v $
  Language:  C++
  Date:      $Date: 2004/05/11 01:47:05 $
  Version:   $Revision: 1.1 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

//  Software Guide : BeginLatex
//
//  This example illustrates how to convert an RGB image into a grayscale one.
//  The \doxygen{RGBToLuminanceImageFilter} is the central piece of this example.
//
//  \index{itk::RGBToLuminanceImageFilter!RGB Images}
//
//  Software Guide : EndLatex 


//  Software Guide : BeginLatex
//
//  The first step required to use this filter is to include its header file.
//
//  \index{itk::RGBToLuminanceImageFilter!header}
//
//  Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
#include "itkRGBToLuminanceImageFilter.h"
// Software Guide : EndCodeSnippet


#include "itkRGBPixel.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"


int main( int argc, char * argv[] )
{
  if( argc < 3 ) 
    { 
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "  inputRGBImageFile  outputGrayscaleImageFile " << std::endl;
    return 1;
    }

  const unsigned int Dimension = 2;

  typedef   itk::RGBPixel< unsigned char >            InputPixelType;
  typedef   itk::Image< InputPixelType, Dimension >   InputImageType;
  typedef   itk::Image< unsigned char,  Dimension >   OutputImageType;


  typedef itk::ImageFileReader< InputImageType >  ReaderType;

  ReaderType::Pointer reader = ReaderType::New();

  reader->SetFileName( argv[1] );


  typedef itk::RGBToLuminanceImageFilter< 
                                 InputImageType, 
                                 OutputImageType >  FilterType;

  FilterType::Pointer filter = FilterType::New();

  filter->SetInput( reader->GetOutput() );



  typedef itk::ImageFileWriter< OutputImageType >  WriterType;

  WriterType::Pointer writer = WriterType::New();

  writer->SetInput( filter->GetOutput() );

  writer->SetFileName( argv[2] );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Exception Thrown" << std::endl;
    std::cerr << excp << std::endl;
    }

  return 0;
}


--------------040103090505060105020903--





More information about the Insight-users mailing list