From 720fcdeecccf5e78879e28e5c6c2ffebf36bdf64 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Thu, 10 Oct 2013 14:29:18 +0200 Subject: [PATCH] LSMS integration (moving from nbtiles parameters to tilsize parameters) --- .../Segmentation/otbLSMSSegmentation.cxx | 40 +++++++++--------- .../otbLSMSSmallRegionsMerging.cxx | 40 +++++++++--------- .../Segmentation/otbLSMSVectorization.cxx | 42 +++++++++---------- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Applications/Segmentation/otbLSMSSegmentation.cxx b/Applications/Segmentation/otbLSMSSegmentation.cxx index 232be3e7d2..c5efe22d24 100644 --- a/Applications/Segmentation/otbLSMSSegmentation.cxx +++ b/Applications/Segmentation/otbLSMSSegmentation.cxx @@ -221,17 +221,15 @@ private: SetMinimumParameterIntValue("minsize", 0); MandatoryOff("minsize"); - AddParameter(ParameterType_Int, "nbtilesx", "Number of Tiles (X-axis)"); - SetParameterDescription("nbtilesx", "Number of Tiles along the X-axis."); - SetDefaultParameterInt("nbtilesx", 10); - SetMinimumParameterIntValue("nbtilesx", 1); - MandatoryOff("nbtilesx"); - - AddParameter(ParameterType_Int, "nbtilesy", "Number of Tiles (Y-axis)"); - SetParameterDescription("nbtilesy", "Number of Tiles along the Y-axis."); - SetDefaultParameterInt("nbtilesy", 10); - SetMinimumParameterIntValue("nbtilesy", 1); - MandatoryOff("nbtilesy"); + AddParameter(ParameterType_Int, "tilesizex", "Size of tiles in pixel (X-axis)"); + SetParameterDescription("tilesizex", "Size of tiles along the X-axis."); + SetDefaultParameterInt("tilesizex", 500); + SetMinimumParameterIntValue("tilesizex", 1); + + AddParameter(ParameterType_Int, "tilesizey", "Size of tiles in pixel (Y-axis)"); + SetParameterDescription("tilesizey", "Size of tiles along the Y-axis."); + SetDefaultParameterInt("tilesizey", 500); + SetMinimumParameterIntValue("tilesizey", 1); AddParameter(ParameterType_Directory,"tmpdir","Directory where to write temporary files"); SetParameterDescription("tmpdir","This applications need to write some temporary files for each tile. This parameters allows to choose the path where to write those files. If disabled, the current path will be used."); @@ -250,8 +248,8 @@ private: SetDocExampleParameterValue("ranger","15"); SetDocExampleParameterValue("spatialr","5"); SetDocExampleParameterValue("minsize","0"); - SetDocExampleParameterValue("nbtilesx","4"); - SetDocExampleParameterValue("nbtilesy","4"); + SetDocExampleParameterValue("tilesizex","256"); + SetDocExampleParameterValue("tilesizey","256"); } @@ -265,13 +263,13 @@ private: clock_t tic = clock(); - const float ranger = GetParameterFloat("ranger"); - const float spatialr = GetParameterFloat("spatialr"); + const float ranger = GetParameterFloat("ranger"); + const float spatialr = GetParameterFloat("spatialr"); - unsigned int minRegionSize = GetParameterInt("minsize"); + unsigned int minRegionSize = GetParameterInt("minsize"); - unsigned int nbTilesX = GetParameterInt("nbtilesx"); - unsigned int nbTilesY = GetParameterInt("nbtilesy"); + unsigned long sizeTilesX = GetParameterInt("tilesizex"); + unsigned long sizeTilesY = GetParameterInt("tilesizey"); // Ensure that temporary directory exists if activated: @@ -305,7 +303,11 @@ private: unsigned long sizeImageY = imageIn->GetLargestPossibleRegion().GetSize()[1]; unsigned int nbComp = imageIn->GetNumberOfComponentsPerPixel(); - unsigned long sizeTilesX = (sizeImageX+nbTilesX-1)/nbTilesX, sizeTilesY = (sizeImageY+nbTilesY-1)/nbTilesY; + unsigned int nbTilesX = sizeImageX/sizeTilesX + (sizeImageX%sizeTilesX > 0 ? 1 : 0); + unsigned int nbTilesY = sizeImageY/sizeTilesY + (sizeImageY%sizeTilesY > 0 ? 1 : 0); + + otbAppLogINFO(<<"Number of tiles: "<<nbTilesX<<" x "<<nbTilesY); + unsigned long regionCount = 0; //Segmentation by the connected component per tile and label diff --git a/Applications/Segmentation/otbLSMSSmallRegionsMerging.cxx b/Applications/Segmentation/otbLSMSSmallRegionsMerging.cxx index 2a28e02974..90c17b0389 100644 --- a/Applications/Segmentation/otbLSMSSmallRegionsMerging.cxx +++ b/Applications/Segmentation/otbLSMSSmallRegionsMerging.cxx @@ -104,27 +104,24 @@ private: SetDefaultParameterInt("minsize", 50); SetMinimumParameterIntValue("minsize", 0); MandatoryOff("minsize"); - - AddParameter(ParameterType_Int, "nbtilesx", "Number of Tiles (X-axis)"); - SetParameterDescription("nbtilesx", "Number of Tiles along the X-axis."); - SetDefaultParameterInt("nbtilesx", 10); - SetMinimumParameterIntValue("nbtilesx", 1); - MandatoryOff("nbtilesx"); - AddParameter(ParameterType_Int, "nbtilesy", "Number of Tiles (Y-axis)"); - SetParameterDescription("nbtilesy", "Number of Tiles along the Y-axis."); - SetDefaultParameterInt("nbtilesy", 10); - SetMinimumParameterIntValue("nbtilesy", 1); - MandatoryOff("nbtilesy"); + AddParameter(ParameterType_Int, "tilesizex", "Size of tiles in pixel (X-axis)"); + SetParameterDescription("tilesizex", "Size of tiles along the X-axis."); + SetDefaultParameterInt("tilesizex", 500); + SetMinimumParameterIntValue("tilesizex", 1); + AddParameter(ParameterType_Int, "tilesizey", "Size of tiles in pixel (Y-axis)"); + SetParameterDescription("tilesizey", "Size of tiles along the Y-axis."); + SetDefaultParameterInt("tilesizey", 500); + SetMinimumParameterIntValue("tilesizey", 1); // Doc example parameter settings SetDocExampleParameterValue("in","smooth.tif"); SetDocExampleParameterValue("inseg","segmentation.tif"); SetDocExampleParameterValue("out","merged.tif"); SetDocExampleParameterValue("minsize","20"); - SetDocExampleParameterValue("nbtilesx","4"); - SetDocExampleParameterValue("nbtilesy","4"); + SetDocExampleParameterValue("tilesizex","256"); + SetDocExampleParameterValue("tilesizey","256"); } @@ -136,11 +133,10 @@ private: { clock_t tic = clock(); - unsigned int minSize = GetParameterInt("minsize"); + unsigned int minSize = GetParameterInt("minsize"); - unsigned int nbTilesX = GetParameterInt("nbtilesx"); - unsigned int nbTilesY = GetParameterInt("nbtilesy"); - + unsigned long sizeTilesX = GetParameterInt("tilesizex"); + unsigned long sizeTilesY = GetParameterInt("tilesizey"); //Acquisition of the input image dimensions ImageType::Pointer imageIn = GetParameterImage("in"); @@ -166,13 +162,15 @@ private: defaultValue.Fill(0); std::vector<ImageType::PixelType>sum(regionCount+1,defaultValue); - + + unsigned int nbTilesX = sizeImageX/sizeTilesX + (sizeImageX%sizeTilesX > 0 ? 1 : 0); + unsigned int nbTilesY = sizeImageY/sizeTilesY + (sizeImageY%sizeTilesY > 0 ? 1 : 0); + + otbAppLogINFO(<<"Number of tiles: "<<nbTilesX<<" x "<<nbTilesY); + //Sums calculation per label otbAppLogINFO(<<"Sums calculation ..."); - unsigned long sizeTilesX = (sizeImageX+nbTilesX-1)/nbTilesX; - unsigned long sizeTilesY = (sizeImageY+nbTilesY-1)/nbTilesY; - for(unsigned int row = 0; row < nbTilesY ; row++) for(unsigned int column = 0; column < nbTilesX ; column++) { diff --git a/Applications/Segmentation/otbLSMSVectorization.cxx b/Applications/Segmentation/otbLSMSVectorization.cxx index 3355573903..90750caaa2 100644 --- a/Applications/Segmentation/otbLSMSVectorization.cxx +++ b/Applications/Segmentation/otbLSMSVectorization.cxx @@ -91,24 +91,22 @@ private: AddParameter(ParameterType_OutputFilename, "out", "Output GIS vector file"); SetParameterDescription( "out", "The output GIS vector fie, representing the vectorized version of the segmented image where the features of the polygones are the radiometric means and variances." ); - AddParameter(ParameterType_Int, "nbtilesx", "Number of Tiles (X-axis)"); - SetParameterDescription("nbtilesx", "Number of Tiles along the X-axis."); - SetDefaultParameterInt("nbtilesx", 10); - SetMinimumParameterIntValue("nbtilesx", 1); - MandatoryOff("nbtilesx"); - - AddParameter(ParameterType_Int, "nbtilesy", "Number of Tiles (Y-axis)"); - SetParameterDescription("nbtilesy", "Number of Tiles along the Y-axis."); - SetDefaultParameterInt("nbtilesy", 10); - SetMinimumParameterIntValue("nbtilesy", 1); - MandatoryOff("nbtilesy"); + AddParameter(ParameterType_Int, "tilesizex", "Size of tiles in pixel (X-axis)"); + SetParameterDescription("tilesizex", "Size of tiles along the X-axis."); + SetDefaultParameterInt("tilesizex", 500); + SetMinimumParameterIntValue("tilesizex", 1); + + AddParameter(ParameterType_Int, "tilesizey", "Size of tiles in pixel (Y-axis)"); + SetParameterDescription("tilesizey", "Size of tiles along the Y-axis."); + SetDefaultParameterInt("tilesizey", 500); + SetMinimumParameterIntValue("tilesizey", 1); // Doc example parameter settings SetDocExampleParameterValue("in","avions.tif"); SetDocExampleParameterValue("inseg","merged.tif"); SetDocExampleParameterValue("out","vecto.shp"); - SetDocExampleParameterValue("nbtilesx","4"); - SetDocExampleParameterValue("nbtilesy","4"); + SetDocExampleParameterValue("tilesizex","256"); + SetDocExampleParameterValue("tilesizey","256"); } void DoUpdateParameters() @@ -119,10 +117,11 @@ private: { clock_t tic = clock(); - const char * shapefile = GetParameterString("out").c_str(); + const char * shapefile = GetParameterString("out").c_str(); - unsigned int nbTilesX = GetParameterInt("nbtilesx"); - unsigned int nbTilesY = GetParameterInt("nbtilesy"); + unsigned long sizeTilesX = GetParameterInt("tilesizex"); + unsigned long sizeTilesY = GetParameterInt("tilesizey"); + LabelImageType::Pointer labelIn = GetParameterUInt32Image("inseg"); labelIn->UpdateOutputInformation(); @@ -130,6 +129,11 @@ private: unsigned long sizeImageX = labelIn->GetLargestPossibleRegion().GetSize()[0]; unsigned long sizeImageY = labelIn->GetLargestPossibleRegion().GetSize()[1]; + unsigned int nbTilesX = sizeImageX/sizeTilesX + (sizeImageX%sizeTilesX > 0 ? 1 : 0); + unsigned int nbTilesY = sizeImageY/sizeTilesY + (sizeImageY%sizeTilesY > 0 ? 1 : 0); + + otbAppLogINFO(<<"Number of tiles: "<<nbTilesX<<" x "<<nbTilesY); + StatisticsImageFilterType::Pointer stats = StatisticsImageFilterType::New(); stats->SetInput(labelIn); stats->Update(); @@ -187,10 +191,6 @@ private: layer.CreateField(field, true); } - unsigned long sizeTilesX = (sizeImageX+nbTilesX-1)/nbTilesX; - unsigned long sizeTilesY = (sizeImageY+nbTilesY-1)/nbTilesY; - - //Vectorization per tile otbAppLogINFO(<<"Vectorization ..."); for(unsigned int row = 0; row < nbTilesY ; row++) @@ -273,7 +273,7 @@ private: otb::ogr::Feature firstFeature = layerTmp.ogr().GetNextFeature(); //Geometry fusion - otbAppLogINFO("Fusion of polygons accross tiles ..."); + otbAppLogINFO("Merging polygons accross tiles ..."); while(firstFeature.addr()) { LabelImagePixelType curLabel = firstFeature.ogr().GetFieldAsInteger("label"); -- GitLab