Commit 3be4f753 authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch '2261-role_output_in_computeimagestatistics' into 'release-8.0'

ADD: role output for mean, min, max, std

See merge request !890
parents 2cd4c980 5713d592
Pipeline #10036 passed with stages
in 145 minutes and 53 seconds
......@@ -6,6 +6,18 @@
<StatisticVector value="210.884" />
<StatisticVector value="388.449" />
</Statistic>
<Statistic name="min">
<StatisticVector value="185.401" />
<StatisticVector value="224.62" />
<StatisticVector value="107.775" />
<StatisticVector value="99.3083" />
</Statistic>
<Statistic name="max">
<StatisticVector value="1964.89" />
<StatisticVector value="1992.82" />
<StatisticVector value="1964.4" />
<StatisticVector value="2016.54" />
</Statistic>
<Statistic name="stddev">
<StatisticVector value="39.1969" />
<StatisticVector value="69.9943" />
......
......@@ -6,6 +6,18 @@
<StatisticVector value="221.599" />
<StatisticVector value="349.019" />
</Statistic>
<Statistic name="min">
<StatisticVector value="176.353" />
<StatisticVector value="192.315" />
<StatisticVector value="96.8528" />
<StatisticVector value="59.377" />
</Statistic>
<Statistic name="max">
<StatisticVector value="1964.89" />
<StatisticVector value="1992.82" />
<StatisticVector value="1964.4" />
<StatisticVector value="2016.54" />
</Statistic>
<Statistic name="stddev">
<StatisticVector value="37.9385" />
<StatisticVector value="69.6035" />
......
......@@ -6,6 +6,18 @@
<StatisticVector value="208.931" />
<StatisticVector value="368.327" />
</Statistic>
<Statistic name="min">
<StatisticVector value="77" />
<StatisticVector value="66" />
<StatisticVector value="1" />
<StatisticVector value="1" />
</Statistic>
<Statistic name="max">
<StatisticVector value="2047" />
<StatisticVector value="2016" />
<StatisticVector value="2047" />
<StatisticVector value="2047" />
</Statistic>
<Statistic name="stddev">
<StatisticVector value="32.1736" />
<StatisticVector value="64.648" />
......
......@@ -74,15 +74,37 @@ private:
SetParameterDescription("bv", "Background value to ignore in computation of statistics.");
MandatoryOff("bv");
AddParameter(ParameterType_OutputFilename, "out", "Output XML file");
SetParameterDescription("out", "XML filename where the statistics are saved for future reuse.");
MandatoryOff("out");
AddParameter(ParameterType_Group, "out", "Optional outputs");
AddParameter(ParameterType_OutputFilename, "out.xml", "Output XML file");
SetParameterDescription("out.xml", "XML filename where the statistics are saved for future reuse.");
MandatoryOff("out.xml");
AddParameter(ParameterType_String, "out.mean", "Mean pixel Value");
SetParameterDescription("out.mean", "Mean pixel value.");
SetParameterRole("out.mean", Role_Output);
MandatoryOff("out.mean");
AddParameter(ParameterType_String, "out.min", "Min pixel Value");
SetParameterDescription("out.min", "Minimum pixel value.");
SetParameterRole("out.min", Role_Output);
MandatoryOff("out.min");
AddParameter(ParameterType_String, "out.max", "Max pixel Value");
SetParameterDescription("out.max", "Maximum pixel value.");
SetParameterRole("out.max", Role_Output);
MandatoryOff("out.max");
AddParameter(ParameterType_String, "out.std", "Standard deviation of pixel Value");
SetParameterDescription("out.std", "Standard deviation of pixel value.");
SetParameterRole("out.std", Role_Output);
MandatoryOff("out.std");
AddRAMParameter();
// Doc example parameter settings
SetDocExampleParameterValue("il", "QB_1_ortho.tif");
SetDocExampleParameterValue("out", "EstimateImageStatisticsQB1.xml");
SetDocExampleParameterValue("out.xml", "EstimateImageStatisticsQB1.xml");
SetOfficialDocLink();
}
......@@ -115,6 +137,14 @@ private:
MatrixValueType mean(nbBands, static_cast<unsigned int>(nbImages));
mean.Fill(itk::NumericTraits<MatrixValueType::ValueType>::Zero);
// Build a Measurement Vector of min
MatrixValueType min(nbBands, static_cast<unsigned int>(nbImages));
min.Fill(itk::NumericTraits<MatrixValueType::ValueType>::max());
// Build a Measurement Vector of max
MatrixValueType max(nbBands, static_cast<unsigned int>(nbImages));
max.Fill(itk::NumericTraits<MatrixValueType::ValueType>::min());
// Build a Measurement Matrix of variance
MatrixValueType variance(nbBands, static_cast<unsigned int>(nbImages));
variance.Fill(itk::NumericTraits<MatrixValueType::ValueType>::Zero);
......@@ -149,10 +179,14 @@ private:
MeasurementType nbRelevantPixels = statsEstimator->GetNbRelevantPixels();
MeasurementType meanPerBand = statsEstimator->GetMean();
MeasurementType minPerBand = statsEstimator->GetMinimum();
MeasurementType maxPerBand = statsEstimator->GetMaximum();
for (unsigned int itBand = 0; itBand < nbBands; itBand++)
{
mean(itBand, imageId) = meanPerBand[itBand];
min(itBand, imageId) = minPerBand[itBand];
max(itBand, imageId) = maxPerBand[itBand];
variance(itBand, imageId) = (statsEstimator->GetCovariance())(itBand, itBand);
nbSamples(itBand, imageId) = nbRelevantPixels[itBand];
}
......@@ -167,6 +201,14 @@ private:
totalMeanPerBand.SetSize(nbBands);
totalMeanPerBand.Fill(itk::NumericTraits<MeasurementType::ValueType>::Zero);
MeasurementType totalMinPerBand;
totalMinPerBand.SetSize(nbBands);
totalMinPerBand.Fill(itk::NumericTraits<MeasurementType::ValueType>::max());
MeasurementType totalMaxPerBand;
totalMaxPerBand.SetSize(nbBands);
totalMaxPerBand.Fill(itk::NumericTraits<MeasurementType::ValueType>::min());
MeasurementType totalVariancePerBand;
totalVariancePerBand.SetSize(nbBands);
totalVariancePerBand.Fill(itk::NumericTraits<MeasurementType::ValueType>::Zero);
......@@ -178,6 +220,8 @@ private:
MeasurementType::ValueType nbSample = nbSamples(itBand, imageId);
totalSamplesPerBand[itBand] += nbSample;
totalMeanPerBand[itBand] += mean(itBand, imageId) * nbSample;
totalMinPerBand[itBand] = std::min(totalMinPerBand[itBand], min(itBand, imageId));
totalMaxPerBand[itBand] = std::max(totalMaxPerBand[itBand], max(itBand, imageId));
totalVariancePerBand[itBand] += variance(itBand, imageId) * (nbSample - 1);
}
}
......@@ -203,6 +247,8 @@ private:
else
{
totalMeanPerBand[itBand] = itk::NumericTraits<ValueType>::Zero;
totalMinPerBand[itBand] = itk::NumericTraits<ValueType>::Zero;
totalMaxPerBand[itBand] = itk::NumericTraits<ValueType>::Zero;
}
}
......@@ -214,13 +260,26 @@ private:
stddev[i] = std::sqrt(totalVariancePerBand[i]);
}
if (HasValue("out"))
// Display the pixel value
std::ostringstream oss_mean, oss_min, oss_max, oss_std;
oss_mean << totalMeanPerBand;
oss_min << totalMinPerBand;
oss_max << totalMaxPerBand;
oss_std << stddev;
SetParameterString("out.mean", oss_mean.str());
SetParameterString("out.min", oss_min.str());
SetParameterString("out.max", oss_max.str());
SetParameterString("out.std", oss_std.str());
if (HasValue("out.xml"))
{
// Write the Statistics via the statistic writer
typedef otb::StatisticsXMLFileWriter<MeasurementType> StatisticsWriter;
StatisticsWriter::Pointer writer = StatisticsWriter::New();
writer->SetFileName(GetParameterString("out"));
writer->SetFileName(GetParameterString("out.xml"));
writer->AddInput("mean", totalMeanPerBand);
writer->AddInput("min", totalMinPerBand);
writer->AddInput("max", totalMaxPerBand);
writer->AddInput("stddev", stddev);
writer->Update();
}
......
......@@ -137,12 +137,12 @@ public:
void ConnectKMClassificationParams()
{
Connect("training.cfield", "extraction.field");
Connect("training.io.stats", "imgstats.out");
Connect("training.io.stats", "imgstats.out.xml");
Connect("classif.in", "imgenvelop.in");
Connect("classif.model", "training.io.out");
Connect("classif.ram", "polystats.ram");
Connect("classif.imstat", "imgstats.out");
Connect("classif.imstat", "imgstats.out.xml");
}
void ConnectKMClassificationMask()
......@@ -251,7 +251,7 @@ public:
GetInternalApplication("training")->SetParameterString("classifier.sharkkm.incentroids", GetParameterString("centroids.in"));
GetInternalApplication("training")
->SetParameterString("classifier.sharkkm.cstats", GetInternalApplication("imgstats")->GetParameterString("out"));
->SetParameterString("classifier.sharkkm.cstats", GetInternalApplication("imgstats")->GetParameterString("out.xml"));
}
......@@ -269,10 +269,10 @@ public:
{
// std::vector<std::string> imageFileNameList = {imageFileName};
GetInternalApplication("imgstats")->SetParameterImageBase("il", img);
GetInternalApplication("imgstats")->SetParameterString("out", imagesStatsFileName);
GetInternalApplication("imgstats")->SetParameterString("out.xml", imagesStatsFileName);
ExecuteInternal("imgstats");
otbAppLogINFO("image statistics file: " << GetInternalApplication("imgstats")->GetParameterString("out"));
otbAppLogINFO("image statistics file: " << GetInternalApplication("imgstats")->GetParameterString("out.xml"));
}
......
......@@ -736,7 +736,7 @@ endif()
otb_test_application(NAME apTvClComputeImagesStatisticsQB1
APP ComputeImagesStatistics
OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif
-out ${TEMP}/apTvClEstimateImageStatisticsQB1.xml
-out.xml ${TEMP}/apTvClEstimateImageStatisticsQB1.xml
VALID --compare-ascii ${NOTOL}
${OTBAPP_BASELINE_FILES}/clImageStatisticsQB1.xml
${TEMP}/apTvClEstimateImageStatisticsQB1.xml)
......@@ -746,7 +746,7 @@ otb_test_application(NAME apTvClComputeImagesStatisticsQB456
OPTIONS -il ${INPUTDATA}/Classification/QB_4_extract.tif
${INPUTDATA}/Classification/QB_5_extract.tif
${INPUTDATA}/Classification/QB_6_extract.tif
-out ${TEMP}/apTvClEstimateImageStatisticsQB456.xml
-out.xml ${TEMP}/apTvClEstimateImageStatisticsQB456.xml
VALID --compare-ascii ${NOTOL}
${OTBAPP_BASELINE_FILES}/clImageStatisticsQB456.xml
${TEMP}/apTvClEstimateImageStatisticsQB456.xml)
......@@ -756,7 +756,7 @@ otb_test_application(NAME apTvClComputeImagesStatisticsQB123
OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif
${INPUTDATA}/Classification/QB_2_ortho.tif
${INPUTDATA}/Classification/QB_3_ortho.tif
-out ${TEMP}/apTvClEstimateImageStatisticsQB123.xml
-out.xml ${TEMP}/apTvClEstimateImageStatisticsQB123.xml
VALID --compare-ascii ${NOTOL}
${OTBAPP_BASELINE_FILES}/clImageStatisticsQB123.xml
${TEMP}/apTvClEstimateImageStatisticsQB123.xml)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment