diff --git a/Code/Common/otbVectorImageToASPixelAccessor.h b/Code/Common/otbVectorImageToASPixelAccessor.h index d0c6ac76565f42427993b9d16597bd9a8bbad3ea..09d77843d662c55f3bb9c9d5f6f0b3472be43bf9 100644 --- a/Code/Common/otbVectorImageToASPixelAccessor.h +++ b/Code/Common/otbVectorImageToASPixelAccessor.h @@ -76,7 +76,7 @@ private: }; } // end namespace Accessor -} // end namespace itk +} // end namespace otb #endif diff --git a/Code/Visu/otbGLVectorImageViewClick.h b/Code/Visu/otbGLVectorImageViewClick.h index 4a45a7cbd24de1556fe389b65d7b5c5e0a6cf4e7..f4001a8cc529db134d2f166ac0f57a971940d56c 100755 --- a/Code/Visu/otbGLVectorImageViewClick.h +++ b/Code/Visu/otbGLVectorImageViewClick.h @@ -30,7 +30,7 @@ #include <string> #include "itkColorTable.h" -#include "itkImage.h" +#include "otbImage.h" #include "itkMacro.h" #include "otbVectorImageView.h" @@ -89,7 +89,7 @@ public: typedef VectorImageView<TPixel> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - typedef itk::Image<TPixelOverlay,2> OverlayType; + typedef otb::Image<TPixelOverlay,2> OverlayType; typedef typename OverlayType::Pointer OverlayPointer; typedef itk::ColorTable<float> ColorTableType; typedef typename ColorTableType::Pointer ColorTablePointer; @@ -282,10 +282,18 @@ public: bool cViewOverlayData; /*! Specify the 3D image to view as an overlay */ - void SetInputOverlay(OverlayType * newOverlayData); + void SetInputOverlay( OverlayPointer newOverlayData, + OverlayPointer newOverlayDataClassRed, + OverlayPointer newOverlayDataClassBlue); /*! Return a pointer to the overlay data */ const OverlayPointer & GetInputOverlay(void) const; + + /*! Return a pointer to the overlay data for the Red Class*/ + const OverlayPointer & GetInputOverlayRed(void) const; + + /*! Return a pointer to the overlay data for the Blue Class*/ + const OverlayPointer & GetInputOverlayBlue(void) const; /*! Turn on/off the viewing of the overlay */ void ViewOverlayData(bool newViewOverlayData); @@ -328,8 +336,13 @@ protected: //M�thodes utilis�es pour l'overlay de l'image bool cValidOverlayData; float cOverlayOpacity; - + // Overlay utilis� pour afficher le r�sultat de la classification OverlayPointer cOverlayData; + // Overlay utilis� pour afficher le r�sultat de la classe #Rouge + OverlayPointer cOverlayDataClassRed; + // Overlay utilis� pour afficher le r�sultat de la classe #Bleu + OverlayPointer cOverlayDataClassBlue; + void (* cViewOverlayCallBack)(void); ImageModeType cImageMode; diff --git a/Code/Visu/otbGLVectorImageViewClick.txx b/Code/Visu/otbGLVectorImageViewClick.txx index febc15e15ebf4a4bbee2b7f5bc2091ab0b287a11..66d51aec04887ba76d610aafe48170daed973829 100755 --- a/Code/Visu/otbGLVectorImageViewClick.txx +++ b/Code/Visu/otbGLVectorImageViewClick.txx @@ -276,19 +276,6 @@ BuildWithImageRegion() //Termine l'initialisation FinalizeInitialisation(); - // Initialise l'overlay - if (cOverlay) - { - const char* inputFilename = "maskrom.png" ; - - typedef otb::ImageFileReader< OverlayType > VolumeReaderType; - typename VolumeReaderType::Pointer lReader = VolumeReaderType::New(); - lReader->SetFileName(inputFilename); - lReader->Update(); - - SetInputOverlay(lReader->GetOutput()); - ViewOverlayData(true); - } //PrintInfos(); } @@ -388,7 +375,6 @@ update() { this->cWinMaxX = (int)this->cDimSize[0] - 1; } - this->cWinSizeY = (int)(this->cDimSize[1]); this->cWinMinY = 0; this->cWinMaxY = (int)( (int)(this->cDimSize[1]) - 1 ); @@ -455,94 +441,7 @@ update() //if(j-this->cWinMinX >= (int)this->cWinDataSizeX) // continue; - - /*l = (j-this->cWinMinX) + (k-this->cWinMinY)*this->cWinDataSizeX; - //this->cWinImData[l] = (unsigned char)tf; - unsigned int overlayColorIndex = 0; - otbMsgDevMacro( << "l : " << l ); - - if( this->cValidOverlayData ) - { - l = l * 4; - - if( sizeof( TPixelOverlay ) == 1 || - sizeof( TPixelOverlay ) == 2 ) - { - - if (sizeof( TPixelOverlay ) == 1) - { - m = (int)*((unsigned char *)&(cOverlayData->GetPixel(ind))); - } - else - { - m = (int)*((unsigned short *)&(cOverlayData->GetPixel(ind))); - } - //if (m!=255) otbMsgDevMacro( << "m : " << m ) ; - - if( m >= (int)cColorTable->GetNumberOfColors() ) - { - m = cColorTable->GetNumberOfColors() - 1; - } - - if( m > 0 ) - { - overlayColorIndex = m-1; - if( static_cast<unsigned int>(m) > cOverlayColorIndex ) - { - overlayColorIndex = cOverlayColorIndex; - } - otbMsgDevMacro( << "hu ?" ); - cWinOverlayData[l+0] = - (unsigned char)(cColorTable->GetColorComponent(overlayColorIndex, - 'r') * 255); - - cWinOverlayData[l+1] = - (unsigned char)(cColorTable->GetColorComponent(overlayColorIndex, - 'g') * 255); - cWinOverlayData[l+2] = - (unsigned char)(cColorTable->GetColorComponent(overlayColorIndex, - 'b') * 255); - cWinOverlayData[l+3] = - (unsigned char)(cOverlayOpacity*255); - } - } - else - { - if(((unsigned char *)&(cOverlayData->GetPixel(ind)))[0] - + ((unsigned char *)&(cOverlayData->GetPixel(ind)))[1] - + ((unsigned char *)&(cOverlayData->GetPixel(ind)))[2] > 0) - { - if( sizeof( TPixelOverlay ) == 3 ) - { - otbMsgDevMacro( << "ho ?" ); - cWinOverlayData[l+0] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[0]; - cWinOverlayData[l+1] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[1]; - cWinOverlayData[l+2] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[2]; - cWinOverlayData[l+3] = - (unsigned char)(cOverlayOpacity*255); - } - else - { - if( sizeof( TPixelOverlay ) == 4 ) - { - otbMsgDevMacro( << "ha ?" ); - cWinOverlayData[l+0] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[0]; - cWinOverlayData[l+1] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[1]; - cWinOverlayData[l+2] = - ((unsigned char *)&(cOverlayData->GetPixel(ind)))[2]; - cWinOverlayData[l+3] = - (unsigned char)(((unsigned char *) - &(cOverlayData->GetPixel(ind)))[3]*cOverlayOpacity); - } - } - } - } - }*/ + } } } @@ -565,7 +464,7 @@ void GLVectorImageViewClick<TPixel,TPixelOverlay>:: resize(int x, int y, int w, int h) { - VectorImageView<TPixel>::resize(x, y, w, h); + VectorImageView<TPixel>::resize(x, y, w, h); Fl_Gl_Window::resize(x, y, w, h); this->update(); this->redraw(); @@ -876,7 +775,9 @@ ViewClickedPoints() template <class TPixel, class TPixelOverlay> void GLVectorImageViewClick<TPixel, TPixelOverlay> -::SetInputOverlay( OverlayType * newOverlayData ) +::SetInputOverlay( OverlayPointer newOverlayData, + OverlayPointer newOverlayDataClassRed, + OverlayPointer newOverlayDataClassBlue) { RegionType newoverlay_region = newOverlayData->GetLargestPossibleRegion(); @@ -888,7 +789,9 @@ GLVectorImageViewClick<TPixel, TPixelOverlay> && (newoverlay_size[1] == this->cDimSize[1]) ) { - this->cOverlayData = newOverlayData; + this->cOverlayData = newOverlayData; + this->cOverlayDataClassRed = newOverlayDataClassRed; + this->cOverlayDataClassBlue = newOverlayDataClassBlue; //this->cViewOverlayData = true; this->cValidOverlayData = true; diff --git a/Code/Visu/otbImageViewerAS.h b/Code/Visu/otbImageViewerAS.h index 4a9f75bda7980f29068ee81dc2d9afb64d359a57..97d755600c850a6e2147dfc09f56cdd09fa9c9e4 100755 --- a/Code/Visu/otbImageViewerAS.h +++ b/Code/Visu/otbImageViewerAS.h @@ -172,8 +172,8 @@ private: std::string m_Label; static const std::string m_SuffixPrincipalTitle; - /** Informations for left image */ - int m_LeftNbDim; + /** Informations for left image */ + int m_LeftNbDim; int m_LeftRedChannel; int m_LeftGreenChannel; int m_LeftBlueChannel; @@ -181,8 +181,8 @@ private: ModeViewType m_LeftModeView; ChannelsType m_LeftChannelsWorks; - /** Informations for right image */ - int m_RightNbDim; + /** Informations for right image */ + int m_RightNbDim; int m_RightRedChannel; int m_RightGreenChannel; int m_RightBlueChannel; diff --git a/Code/Visu/otbImageViewerAS.txx b/Code/Visu/otbImageViewerAS.txx index b31a028b2d79001fb23da7ece54330501a63605e..f8a6566f00d4a62d909fa5a260718ad444d0174e 100755 --- a/Code/Visu/otbImageViewerAS.txx +++ b/Code/Visu/otbImageViewerAS.txx @@ -451,7 +451,7 @@ template <class TPixel> void ImageViewerAS<TPixel>::ClassificationAlgorythm() { - m_PrincipalViewAfterClassif->ClassificationStep(); + m_PrincipalViewBeforeClassif->ClassificationStep(); } template <class TPixel> diff --git a/Code/Visu/otbPrincipalImageViewAS.h b/Code/Visu/otbPrincipalImageViewAS.h index bbd542e44c001fed446a461ae34a618d1f325ffa..d96c4290c60535c6c491d9aabfa624cbf08df306 100755 --- a/Code/Visu/otbPrincipalImageViewAS.h +++ b/Code/Visu/otbPrincipalImageViewAS.h @@ -50,18 +50,24 @@ public: typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; + /* typdef for the image*/ + typedef typename Superclass::ImageType ImageType; + typedef typename Superclass::ImagePointer ImagePointer; + typedef typename Superclass::ImageConstPointer ImageConstPointer; + typedef typename Superclass::RegionType RegionType; + typedef typename Superclass::SizeType SizeType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::PixelType PixelType; + /* typedef for learning and classification */ + typedef float InputPixelType; + typedef std::vector<InputPixelType> InputVectorType; + typedef int LabelPixelType; + typedef itk::PointSet< InputVectorType, 2> MeasurePointSetType; + typedef itk::PointSet< LabelPixelType, 2> LabelPointSetType; - /*! typedef for learning and classification */ - - typedef char InputPixelType; - typedef std::vector<InputPixelType> InputVectorType; - typedef int LabelPixelType; - typedef itk::PointSet< InputVectorType, 3> MeasurePointSetType; - typedef itk::PointSet< LabelPixelType, 3> LabelPointSetType; - - typedef otb::SVMPointSetModelEstimator< MeasurePointSetType, - LabelPointSetType > EstimatorType; + typedef otb::SVMPointSetModelEstimator< MeasurePointSetType, + LabelPointSetType > EstimatorType; /*! Method for creation through the object factory. */ @@ -71,13 +77,6 @@ public: itkTypeMacro(PrincipalImageViewAS,GLVectorImageViewClick); - typedef typename Superclass::ImageType ImageType; - typedef typename Superclass::ImagePointer ImagePointer; - typedef typename Superclass::ImageConstPointer ImageConstPointer; - typedef typename Superclass::RegionType RegionType; - typedef typename Superclass::SizeType SizeType; - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::PixelType PixelType; virtual int handle(int event); diff --git a/Code/Visu/otbPrincipalImageViewAS.txx b/Code/Visu/otbPrincipalImageViewAS.txx index f36313ee1357bb81ca74db04de77761509774cae..96308ea6f3bec2e807822128cb95a18aeb6798e6 100755 --- a/Code/Visu/otbPrincipalImageViewAS.txx +++ b/Code/Visu/otbPrincipalImageViewAS.txx @@ -22,11 +22,18 @@ #include "itkPointSet.h" #include "otbSVMPointSetModelEstimator.h" #include "itkListSample.h" +//#include "otbVectorImageToASImageAdaptor.h" +#include "otbVectorImage.h" +#include "otbImage.h" #include "itkImageToListAdaptor.h" -#include "otbVectorImageToASImageAdaptor.h" +#include "itkScalarToArrayCastImageFilter.h" +#include "itkVectorCastImageFilter.h" + //#include "itkPointSetToListAdaptor.h" #include "otbSVMClassifier.h" -//#include "itkVectorToRGBImageAdaptor.h" +#include "itkVectorToRGBImageAdaptor.h" +#include "itkVectorCastImageFilter.h" +#include "itkCastImageFilter.h" namespace otb { @@ -35,6 +42,7 @@ template <class TPixel, class TPixelOverlay> PrincipalImageViewAS<TPixel, TPixelOverlay>:: PrincipalImageViewAS() : GLVectorImageViewClick<TPixel, TPixelOverlay>() { + //cEstimator = EstimatorType::New(); } @@ -228,14 +236,10 @@ template <class TPixel, class TPixelOverlay> void PrincipalImageViewAS<TPixel, TPixelOverlay>::LearnStep() { - cEstimator = EstimatorType::New(); // Declaration for input image values ImagePointer lInpuPtr = this->GetInput(); - PixelType pixelInput; - IndexType ind; - int nbChannels(0); - int channelIn(0); + IndexType ind; // Scale calcul for correspondance between real image and displayed image double zoomBase = (double)this->cW / (this->cDimSize[0]); @@ -251,7 +255,7 @@ PrincipalImageViewAS<TPixel, TPixelOverlay>::LearnStep() // Conversion from ClickedPoint structure to PointSet structure MeasurePointSetType::Pointer mPSet = MeasurePointSetType::New(); - LabelPointSetType::Pointer lPSet = LabelPointSetType::New(); + LabelPointSetType::Pointer lPSet = LabelPointSetType::New(); typedef MeasurePointSetType::PointType MeasurePointType; typedef LabelPointSetType::PointType LabelPointType; @@ -260,118 +264,158 @@ PrincipalImageViewAS<TPixel, TPixelOverlay>::LearnStep() typedef LabelPointSetType::PointsContainer LabelPointsContainer; MeasurePointsContainer::Pointer mCont = MeasurePointsContainer::New(); - LabelPointsContainer::Pointer lCont = LabelPointsContainer::New(); + LabelPointsContainer::Pointer lCont = LabelPointsContainer::New(); int pointId=0, indiceIm = 0; - MeasurePointType mP; - LabelPointType lP; - InputVectorType measure; - LabelPixelType label; - - for (it=this->cClickedPoints.begin(); it!=this->cClickedPoints.end(); it++) + MeasurePointType mP; + LabelPointType lP; + LabelPixelType label; + PixelType pixelInput; + int noChannels(0); + int nbChannels(0); + int channelIn(0); + + InputVectorType measure(this->m_ChannelsWorks.size() ); + + + it=this->cClickedPoints.begin(); + while(it!=this->cClickedPoints.end() ) { - // ClickPoint is a point + + // ClickPoint is a point if (!(it->isForBox)) { + // index position for the measured point mP[0]=it->x; mP[1]=it->y; + mP[0]=(int)((it->x)*zoomBase); + mP[1]=(int)((it->y)*zoomBase); + + // index position for the label point lP[0]=it->x; lP[1]=it->y; + + lP[0]=(int)((it->x)*zoomBase); + lP[1]=(int)((it->y)*zoomBase); - // Recuperation of real values in input image, not display values ind[0]=(int)((it->x)*zoomBase); ind[1]=(int)((it->y)*zoomBase); + + /* + std::cout <<" points : "<< ind[0] << " , " << ind[1] << std::endl; + */ // Traitement sur les canaux selectionnes. pixelInput = lInpuPtr->GetPixel(ind); - for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++) - { - channelIn = this->m_ChannelsWorks[nbChannels] - 1; - measure.push_back(static_cast<InputPixelType>(pixelInput[channelIn])); - } + + for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++) + { + channelIn = this->m_ChannelsWorks[nbChannels] - 1; + measure[nbChannels] = static_cast<InputPixelType>(pixelInput[channelIn]); + } if (it->color == COLOR_BLUE) - label= -1; - else if (it->color == COLOR_RED) + label= -1; + else if (it->color == COLOR_RED) label = 1; else itkExceptionMacro(<< "Unknown color"); mCont->InsertElement( pointId , mP ); - mPSet->SetPointData( pointId, measure ); + mPSet->SetPointData( pointId, measure ); lCont->InsertElement( pointId , lP ); - lPSet->SetPointData( pointId, label ); + lPSet->SetPointData( pointId, label ); pointId++; - indiceIm+=3; } // ClickPoint is a box else { - int startX = (int)it->x; - int endX = (int)(it->x+it->w); - int startY = (int)it->y; - int endY = (int)(it->y+it->h); + int startX = (int)((it->x)*zoomBase); + int endX = (int)((it->x+it->w)*zoomBase); + int startY = (int)((it->y)*zoomBase); + int endY = (int)((it->y+it->h)*zoomBase); + int temp; - for (int i=startX; i<endX; i++) + if(startX > endX ) { - for (int j=startY; j<endY; j++) - { - - mP[0]=i; - mP[1]=j; - - lP[0]=i; - lP[1]=j; + temp = endX; + endX = startX; + startX = temp; + } + if(startY > endY ) + { + temp = endY; + endY = startY; + startY = temp; + } + + for (int i=startX; i<=endX; i++) + { + for (int j=startY; j<=endY; j++) + { + // index position for the measured point + mP[0]=i; + mP[1]=j; + + // index position for the label point + lP[0]=i; + lP[1]=j; - // Recuperation of real values in input image, not display values - ind[0]=(int)(i*zoomBase); - ind[1]=(int)(j*zoomBase); + // Recuperation of real values in input image, not display values + ind[0]=i; + ind[1]=j; - // Traitement sur les canaux selectionnes. - pixelInput = lInpuPtr->GetPixel(ind); + /* + std::cout <<" box : "<< ind[0] << " , " << ind[1] << std::endl; + */ + + // Traitement sur les canaux selectionnes. + pixelInput = lInpuPtr->GetPixel(ind); for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++) { - channelIn = this->m_ChannelsWorks[nbChannels] - 1; - measure.push_back(static_cast<InputPixelType>(pixelInput[channelIn])); - } + channelIn = this->m_ChannelsWorks[nbChannels] - 1; + measure[nbChannels] = static_cast<InputPixelType>(pixelInput[channelIn]); + } - if (it->color == COLOR_BLUE) + if (it->color == COLOR_BLUE) label = -1; else if (it->color == COLOR_RED) - label = 1; - else - itkExceptionMacro(<< "Unknown color"); + label = 1; + else + itkExceptionMacro(<< "Unknown color"); - mCont->InsertElement( pointId , mP ); + mCont->InsertElement( pointId , mP ); mPSet->SetPointData( pointId, measure ); - lCont->InsertElement( pointId , lP ); + lCont->InsertElement( pointId , lP ); lPSet->SetPointData( pointId, label ); - pointId++; - indiceIm+=3; - } + pointId++; + } } } + ++it; } - std::cout << "Nb de points : " << pointId << std::endl ; - mPSet->SetPoints( mCont ); - lPSet->SetPoints( lCont ); + lPSet->SetPoints( lCont ); - cEstimator->SetInputPointSet( mPSet ); - cEstimator->SetTrainingPointSet( lPSet ); - cEstimator->SetNumberOfClasses( 2 ); + EstimatorType::Pointer learningEstimator = EstimatorType::New(); - cEstimator->Update(); + learningEstimator->SetInputPointSet( mPSet ); + learningEstimator->SetTrainingPointSet( lPSet ); + learningEstimator->SetNumberOfClasses( 2 ); + learningEstimator->Modified(); - std::cout << "Saving model" << std::endl; + learningEstimator->Update(); + + cEstimator = learningEstimator; + std::cout << "End learning model" << std::endl; } @@ -379,40 +423,34 @@ template <class TPixel, class TPixelOverlay> void PrincipalImageViewAS<TPixel, TPixelOverlay>::ClassificationStep() { - // TODO : - // Erreur de compil pour le passage de v2im au sample->SetImage() - // Regarder l'objet cr�� par le nouvel adaptor VectorImageToASImageAdaptor - - // Image conversion from reader to classification - /*typedef itk::VectorImage<TPixel,2> ImageType; - typedef otb::VectorImageToASImageAdaptor<ImageType> InputTType; - - typename InputTType::Pointer v2im = InputTType::New(); - - v2im->SetImage(this->GetInput()); - - // Image definition for classification - typedef itk::Image< itk::FixedArray<InputPixelType,3>, 2 > InputClassifImageType; - typedef itk::Statistics::ImageToListAdaptor< InputClassifImageType > SampleType; - - SampleType::Pointer sample = SampleType::New(); - - sample->SetImage(v2im); - std::cout << "Sample set to Adaptor" << std::endl; + // Image conversion from reader to classification + typedef otb::VectorImage<TPixel,2> ReaderImageType; + typedef itk::FixedArray< float, 3 > MeasurementVectorType; + typedef otb::Image< MeasurementVectorType, 2 > InputClassifImageType; + + typename ReaderImageType::Pointer inputImage; + inputImage = this->GetInput(); + typedef itk::VectorCastImageFilter<ReaderImageType,InputClassifImageType> CasterType; + typename CasterType::Pointer caster = CasterType::New(); + caster->SetInput(inputImage); + caster->Update(); + + // Image definition for classification + typedef itk::Statistics::ImageToListAdaptor< InputClassifImageType > SampleType; + SampleType::Pointer sample = SampleType::New(); + sample->SetImage( caster->GetOutput() ); + + std::cout << "Sample set to Adaptor" << std::endl; // preparing classifier and decision rule object typedef otb::SVMModel< SampleType::MeasurementVectorType::ValueType, LabelPixelType > ModelType; - ModelType::Pointer model = cEstimator->GetModel(); - + ModelType::Pointer model = cEstimator->GetModel(); int numberOfClasses = model->GetNumberOfClasses(); - - std::cout << "Classification for " << numberOfClasses << " classes " << std::endl; typedef otb::SVMClassifier< SampleType, LabelPixelType > ClassifierType ; - ClassifierType::Pointer classifier = ClassifierType::New() ; classifier->SetNumberOfClasses(numberOfClasses) ; @@ -421,52 +459,92 @@ PrincipalImageViewAS<TPixel, TPixelOverlay>::ClassificationStep() classifier->Update() ; // Build the class map - std::cout << "Output image creation" << std::endl; + std::cout << "Generating classify map" << std::endl; - std::cout << "classifier get output" << std::endl; ClassifierType::OutputType* membershipSample = classifier->GetOutput() ; - std::cout << "Sample iterators" << std::endl; - ClassifierType::OutputType::ConstIterator m_iter = + ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin() ; ClassifierType::OutputType::ConstIterator m_last = membershipSample->End() ; + const unsigned int Dimension = 2; + typedef ClassifierType::ClassLabelType OutputPixelType; + typedef otb::Image< TPixelOverlay, Dimension > OutputImageType; - double error = 0.0; - unsigned int pointId = 0; - while (m_iter != m_last) - { - ClassifierType::ClassLabelType label = m_iter.GetClassLabel(); - - InputVectorType measure; - - tPSet->GetPointData(pointId, &measure); + typename OutputImageType::Pointer outputImage = OutputImageType::New(); + typename OutputImageType::Pointer ImageClassBlue = OutputImageType::New(); + typename OutputImageType::Pointer ImageClassRed = OutputImageType::New(); - ClassifierType::ClassLabelType expectedLabel; - if(measure[0] < measure[1]) - expectedLabel= -1; - else - expectedLabel = 1; + typedef itk::Index<Dimension> myIndexType; + typedef itk::Size<Dimension> mySizeType; + typedef itk::ImageRegion<Dimension> myRegionType; - double dist = fabs(measure[0] - measure[1]); - - if(label != expectedLabel ) - error++; + mySizeType size; + size[0] = inputImage->GetRequestedRegion().GetSize()[0]; + size[1] = inputImage->GetRequestedRegion().GetSize()[1]; + + myIndexType start; + start[0] = 0; + start[1] = 0; + + myRegionType region; + region.SetIndex( start ); + region.SetSize( size ); + + outputImage->SetRegions( region ); + outputImage->Allocate(); + + ImageClassBlue->SetRegions( region ); + ImageClassBlue->Allocate(); - std::cout << int(label) << "/" << int(expectedLabel) << " --- " << dist << std::endl; + ImageClassRed->SetRegions( region ); + ImageClassRed->Allocate(); + + + + std::cout << "Image iterator" << std::endl; + typedef itk::ImageRegionIterator< OutputImageType> OutputIteratorType; + OutputIteratorType outIt( outputImage, outputImage->GetBufferedRegion() ); + OutputIteratorType classRedIt( ImageClassRed, outputImage->GetBufferedRegion() ); + OutputIteratorType classBlueIt( ImageClassBlue,outputImage->GetBufferedRegion() ); + + outIt.GoToBegin(); + classRedIt.GoToBegin(); + classBlueIt.GoToBegin(); + + TPixelOverlay MaxValue = static_cast<TPixelOverlay>(255); + TPixelOverlay MinValue = static_cast<TPixelOverlay>(0); + + + while (m_iter != m_last && !outIt.IsAtEnd()) + { + ClassifierType::ClassLabelType label = m_iter.GetClassLabel(); + if( label == -1 ) + { + classBlueIt.Set(MaxValue); + classRedIt.Set(MinValue); + } + if( label == 1 ) + { + classBlueIt.Set(MinValue); + classRedIt.Set(MaxValue); + } + outIt.Set(m_iter.GetClassLabel()); - ++pointId; ++m_iter ; - } - - std::cout << "Error = " << error/pointId << std::endl;*/ - - + ++outIt; + ++classRedIt; + ++classBlueIt; + } + +// cOverlayData .... + this->SetInputOverlay(outputImage,ImageClassRed, ImageClassBlue); +//ViewOverlayData(true); - +std::cout << "End Classif" << std::endl; } diff --git a/Code/Visu/otbVectorImageView.h b/Code/Visu/otbVectorImageView.h index c1e602545b404a191ff33b94a24a0f6554d58617..024a48a66c3a99d3c5b256a97ccfc9811e4bafa9 100755 --- a/Code/Visu/otbVectorImageView.h +++ b/Code/Visu/otbVectorImageView.h @@ -25,7 +25,7 @@ */ #include <itkProcessObject.h> -#include <itkVectorImage.h> +#include <otbVectorImage.h> #include <list> #include <fstream> @@ -52,7 +52,7 @@ class ITK_EXPORT VectorImageView : public itk::ProcessObject itkTypeMacro(VectorImageView,itk::ProcessObject); // some typedefs - typedef itk::VectorImage<TPixel,2> ImageType; + typedef otb::VectorImage<TPixel,2> ImageType; typedef typename ImageType::Pointer ImagePointer; typedef typename ImageType::ConstPointer ImageConstPointer; typedef typename ImageType::RegionType RegionType;