diff --git a/app/otbLSGRM.cxx b/app/otbLSGRM.cxx index 667adecd499581ebd91c99427e37c59fdd524831..d0fcf50da39e150ec3fd0fcab8eceada14fb4f16 100644 --- a/app/otbLSGRM.cxx +++ b/app/otbLSGRM.cxx @@ -44,7 +44,8 @@ private: "Full Lambda Schedule and Baatz & Schape criterion."); AddParameter(ParameterType_InputImage, "in", "Input Image"); -// AddParameter(ParameterType_OutputImage, "out", "Ouput Label Image"); + AddParameter(ParameterType_OutputImage, "out", "Ouput Label Image"); + SetDefaultOutputPixelType("out", ImagePixelType_uint32); // AddParameter(ParameterType_Choice, "criterion", "Homogeneity criterion to use"); // AddChoice("criterion.bs", "Baatz & Schape"); @@ -71,9 +72,13 @@ private: // For large scale AddParameter(ParameterType_Directory, "tmpdir", "temporary directory for tiles and graphs"); - AddParameter(ParameterType_Int, "tsizex", "tile width"); - AddParameter(ParameterType_Int, "tsizey", "tile height"); - AddParameter(ParameterType_Int, "nfirstiter", "number of first iterations"); + AddParameter(ParameterType_Choice, "tiling", "Tiling layout for the large scale segmentation"); + AddChoice("tiling.auto", "Automatic tiling layout"); + AddChoice("tiling.user", "User tiling layout"); + AddParameter(ParameterType_Int, "tiling.user.sizex", "Tiles width"); + AddParameter(ParameterType_Int, "tiling.user.sizey", "Tiles height"); + AddParameter(ParameterType_Int, "tiling.user.nfirstiter", "Number of first iterations"); + AddParameter(ParameterType_Int, "tiling.user.memory", "Available memory"); } void DoUpdateParameters() @@ -95,18 +100,24 @@ private: using SegmenterType = lsrm::BaatzSegmenter<ImageType>; using ControllerType = lsgrm::Controller<SegmenterType>; + ImageType::Pointer inputImage = GetParameterFloatVectorImage("in"); ControllerType controller; - controller.SetInputImage(GetParameterFloatVectorImage("in")); - controller.SetTileDirectory(GetParameterAsString("tmpdir")); + controller.SetInputImage(inputImage); controller.SetTemporaryDirectory(GetParameterAsString("tmpdir")); - controller.SetOutputGraphDirectory(GetParameterAsString("tmpdir")); // Memory configuration - controller.SetInternalMemoryAvailable(0); // 0 = automatic - controller.SetTileWidth(GetParameterInt("tsizex")); - controller.SetTileHeight(GetParameterInt("tsizey")); - controller.SetNumberOfFirstIterations(GetParameterInt("nfirstiter")); + if (GetParameterInt("tiling") == 0) + { + controller.SetInternalMemoryAvailable(0); // 0 = automatic + } + else + { + controller.SetTileWidth(GetParameterInt("tiling.user.sizex")); + controller.SetTileHeight(GetParameterInt("tiling.user.sizey")); + controller.SetNumberOfFirstIterations(GetParameterInt("tiling.user.nfirstiter")); + controller.SetInternalMemoryAvailable(GetParameterInt("tiling.user.memory")); + } // MPI configuration #ifdef OTB_USE_MPI @@ -124,8 +135,18 @@ private: float thres = GetParameterFloat("threshold"); controller.SetThreshold(thres*thres); + // Run the segmentation controller.RunSegmentation(); + // Output images + UInt32ImageType::Pointer labelImage = controller.GetLabeledClusteredOutput();; + + // Set output image projection, origin and spacing for labelImage + labelImage->SetProjectionRef(inputImage->GetProjectionRef()); + labelImage->SetOrigin(inputImage->GetOrigin()); + labelImage->SetSpacing(inputImage->GetSpacing()); + SetParameterOutputImage<UInt32ImageType>("out", labelImage); + } void AfterExecuteAndWriteOutputs()