1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "itkLabelMapToLabelImageFilter.h"
#include "otbImageFileWriter.h"
#include "otbSpatialisationFilter.h"
#include "otbAttributesMapLabelObject.h"
int otbSpatialisationTest(int itkNotUsed(argc), char* argv[])
{
const char* outfilename = argv[1];
typedef unsigned short LabelType;
const unsigned int Dimension = 2;
typedef otb::Image<LabelType, Dimension> ImageType;
typedef otb::AttributesMapLabelObject<LabelType, Dimension, std::string> LabelObjectType;
typedef itk::LabelMap<LabelObjectType> LabelMapType;
typedef otb::ImageFileWriter<ImageType> ImageWriterType;
typedef otb::SpatialisationFilter<LabelMapType> FilterType;
typedef itk::LabelMapToLabelImageFilter<LabelMapType, ImageType> LabelMapToLabelImageFilterType;
/** Instantiation of pointer objects*/
ImageWriterType::Pointer writer = ImageWriterType::New();
FilterType::Pointer filter = FilterType::New();
LabelMapToLabelImageFilterType::Pointer labelMapToLabelImageFilter = LabelMapToLabelImageFilterType::New();
FilterType::SizeType objectSize;
objectSize[0] = 300;
objectSize[1] = 300;
FilterType::SizeType nbOjects;
nbOjects[0] = 3;
nbOjects[1] = 3;
std::vector<std::string> pathVector(9);
pathVector[0] = "path1";
pathVector[1] = "path2";
pathVector[2] = "path3";
pathVector[3] = "path4";
pathVector[4] = "path5";
pathVector[5] = "path6";
pathVector[6] = "path7";
pathVector[7] = "path8";
pathVector[8] = "path9";
std::vector<std::string> areaVector(9);
areaVector[0] = "moutains";
areaVector[1] = "plants";
areaVector[2] = "roads";
areaVector[3] = "forest";
areaVector[4] = "vegetables";
areaVector[5] = "cars";
areaVector[6] = "water";
areaVector[7] = "rocks";
areaVector[8] = "lunar";
std::vector<LabelType> labels(9);
labels[0] = 1;
labels[1] = 2;
labels[2] = 3;
labels[3] = 4;
labels[4] = 5;
labels[5] = 6;
labels[6] = 7;
labels[7] = 8;
labels[8] = 9;
filter->SetObjectSize(objectSize);
filter->SetNumberOfObjects(nbOjects);
filter->SetPathVector(pathVector);
filter->SetAreaVector(areaVector);
filter->SetLabels(labels);
filter->Update();
//
//
// std::cout<<"nb labels : "<<filter->GetOutput()->GetNumberOfLabelObjects()<<std::endl;
// filter->GetOutput()->PrintLabelObjects();
labelMapToLabelImageFilter->SetInput(filter->GetOutput());
labelMapToLabelImageFilter->Update();
//
writer->SetFileName(outfilename);
writer->SetInput(labelMapToLabelImageFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
|