Skip to content
Snippets Groups Projects
Commit 7837e498 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

Correction ExtractROI (ajout methode SetROI()).

parent 3b283523
No related branches found
No related tags found
No related merge requests found
......@@ -79,20 +79,17 @@ public:
itk::ImageToImageFilterDetail::ExtractImageFilterRegionCopier<itkGetStaticConstMacro(InputImageDimension),
itkGetStaticConstMacro(OutputImageDimension)> ExtractROIBaseRegionCopierType;
/** Set/Get the output image region.
* If any of the ExtractionRegion.Size = 0 for any particular dimension dim,
* we have to collapse dimension dim. This means the output image will have
* 'c' dimensions less than the input image, where c = # of
* ExtractionRegion.Size = 0. */
void SetExtractionRegion(InputImageRegionType extractRegion);
itkGetMacro(ExtractionRegion, InputImageRegionType);
itkGetMacro(ExtractionRegion, InputImageRegionType);
/** Give the region to extract, same effect as given m_StartX/Y and m_SizeX/Y*/
void SetROI(InputImageRegionType roi);
/** Set/Get Start methode */
/** Set/Get Start methods */
itkSetMacro(StartX,unsigned long);
itkGetConstMacro(StartX,unsigned long);
itkSetMacro(StartY,unsigned long);
itkGetConstMacro(StartY,unsigned long);
/** Set/Get Size methods */
itkSetMacro(SizeX,unsigned long);
itkGetConstMacro(SizeX,unsigned long);
itkSetMacro(SizeY,unsigned long);
......@@ -150,6 +147,15 @@ protected:
{
};
/** Set/Get the output image region.
* If any of the ExtractionRegion.Size = 0 for any particular dimension dim,
* we have to collapse dimension dim. This means the output image will have
* 'c' dimensions less than the input image, where c = # of
* ExtractionRegion.Size = 0. */
void SetExtractionRegion(InputImageRegionType extractRegion);
InputImageRegionType m_ExtractionRegion;
OutputImageRegionType m_OutputImageRegion;
......@@ -157,10 +163,10 @@ private:
ExtractROIBase(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Coordonnees X/Y du premier point de la rgion extraire */
/** X/Y coordinates of the first point of the region to extract. */
unsigned long m_StartX;
unsigned long m_StartY;
/** Nombre de pixels en X/Y de la rgion extraire */
/** Number of X/Y pixels of the region to extract. */
unsigned long m_SizeX;
unsigned long m_SizeY;
......
......@@ -112,6 +112,21 @@ ExtractROIBase<TInputImage,TOutputImage>
m_OutputImageRegion.SetSize(outputSize);
m_OutputImageRegion.SetIndex(outputIndex);
this->Modified();
}
template <class TInputImage, class TOutputImage>
void
ExtractROIBase<TInputImage,TOutputImage>
::SetROI(InputImageRegionType roi)
{
m_SizeX = roi.GetSize()[0];
m_SizeY = roi.GetSize()[1];
m_StartX = roi.GetIndex()[0];
m_StartY = roi.GetIndex()[1];
this->Modified();
}
......@@ -142,7 +157,6 @@ ExtractROIBase<TInputImage,TOutputImage>
}
/**
* ExtractROIBase can produce an image which is a different resolution
* than its input image. As such, ExtractROIBase needs to provide an
......
......@@ -961,7 +961,7 @@ ADD_EXECUTABLE(otbBasicFiltersTests2 otbBasicFiltersTests2.cxx ${BasicFilters_SR
TARGET_LINK_LIBRARIES(otbBasicFiltersTests2 OTBBasicFilters OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
ADD_EXECUTABLE(otbBasicFiltersTests3 otbBasicFiltersTests3.cxx ${BasicFilters_SRCS3})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests3 OTBBasicFilters OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
TARGET_LINK_LIBRARIES(otbBasicFiltersTests3 OTBBasicFilters otbossim OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
ADD_EXECUTABLE(otbBasicFiltersTests4 otbBasicFiltersTests4.cxx ${BasicFilters_SRCS4})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests4 OTBBasicFilters OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
......
......@@ -26,67 +26,53 @@
int otbExtractROI2( int argc, char * argv[] )
{
try
{
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
unsigned int startX((unsigned int)::atoi(argv[3]));
unsigned int startY((unsigned int)::atoi(argv[4]));
unsigned int sizeX((unsigned int)::atoi(argv[5]));
unsigned int sizeY((unsigned int)::atoi(argv[6]));
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef otb::ExtractROI< InputPixelType,
OutputPixelType > FilterType;
typedef FilterType::InputImageType InputImageType;
typedef FilterType::OutputImageType OutputImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileWriter< OutputImageType > WriterType;
FilterType::Pointer filter = FilterType::New();
typedef otb::Image<InputPixelType,2> ImageType;
ImageType::IndexType start;
start[0] = startX;
start[1] = startY;
ImageType::SizeType size;
size[0] = sizeX;
size[1] = sizeY;
ImageType::RegionType region;
region.SetSize( size );
filter->SetExtractionRegion(region);
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
unsigned int startX((unsigned int)::atoi(argv[3]));
unsigned int startY((unsigned int)::atoi(argv[4]));
unsigned int sizeX((unsigned int)::atoi(argv[5]));
unsigned int sizeY((unsigned int)::atoi(argv[6]));
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef otb::ExtractROI< InputPixelType,
OutputPixelType > FilterType;
typedef FilterType::InputImageType InputImageType;
typedef FilterType::OutputImageType OutputImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileWriter< OutputImageType > WriterType;
FilterType::Pointer filter = FilterType::New();
typedef otb::Image<InputPixelType,2> ImageType;
ImageType::IndexType start;
start[0] = startX;
start[1] = startY;
ImageType::SizeType size;
size[0] = sizeX;
size[1] = sizeY;
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
filter->SetROI(region);
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
filter->SetInput( reader->GetOutput() );
writer->SetInput( filter->GetOutput() );
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Exception levee inconnue !" << std::endl;
return EXIT_FAILURE;
}
filter->SetInput( reader->GetOutput() );
writer->SetInput( filter->GetOutput() );
writer->Update();
return EXIT_SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment