diff --git a/Applications/Radiometry/otbOpticalCalibration.cxx b/Applications/Radiometry/otbOpticalCalibration.cxx index 9e14d4a9bdd59cb063ca180d31d339e4544ced49..08ede8225542b5fea2b82bcb1c67ec75fb92d5dd 100644 --- a/Applications/Radiometry/otbOpticalCalibration.cxx +++ b/Applications/Radiometry/otbOpticalCalibration.cxx @@ -60,16 +60,16 @@ namespace otb itkTypeMacro(OpticalCalibration, Application); typedef ImageToLuminanceImageFilter<UInt16VectorImageType, - DoubleVectorImageType> ImageToLuminanceImageFilterType; + DoubleVectorImageType> ImageToLuminanceImageFilterType; typedef LuminanceToReflectanceImageFilter<DoubleVectorImageType, - DoubleVectorImageType> LuminanceToReflectanceImageFilterType; + DoubleVectorImageType> LuminanceToReflectanceImageFilterType; typedef otb::MultiplyByScalarImageFilter<DoubleVectorImageType, - DoubleVectorImageType> ScaleFilterType; + DoubleVectorImageType> ScaleFilterType; typedef ReflectanceToSurfaceReflectanceImageFilter<DoubleVectorImageType, - DoubleVectorImageType> ReflectanceToSurfaceReflectanceImageFilterType; + DoubleVectorImageType> ReflectanceToSurfaceReflectanceImageFilterType; typedef ReflectanceToSurfaceReflectanceImageFilterType::FilterFunctionValuesType FilterFunctionValuesType; typedef FilterFunctionValuesType::ValuesVectorType ValuesVectorType; typedef AtmosphericCorrectionParameters AtmosphericCorrectionParametersType; @@ -78,206 +78,206 @@ namespace otb private: void DoInit() { - SetName("OpticalCalibration"); - SetDescription("Perform optical calibration TOA/TOC (Top Of Atmosphere/Top Of Canopy). Supported sensors: QuickBird, Ikonos, WorldView2, Formosat, Spot5"); - // Documentation - SetDocName("Optical calibration"); - SetDocLongDescription("The application allows to convert pixel values from DN (for Digital Numbers) to physically interpretable and comparable values. Calibrated values are called surface reflectivity and its values lie in the range [0, 1].\nThe first level is called Top Of Atmosphere (TOA) reflectivity. It takes into account the sensor gain, sensor spectral response and the solar illumination.\nThe second level is called Top Of Canopy (TOC) reflectivity. In addition to sensor gain and solar illumination, it takes into account the optical thickness of the atmosphere, the atmospheric pressure, the water vapor amount, the ozone amount, as well as the composition and amount of aerosol gasses.\nIt is also possible to indicate an AERONET file which contains atmospheric parameters (version 1 and version 2 of Aeronet file are supported."); - SetDocLimitations("None"); - SetDocAuthors("OTB-Team"); - SetDocSeeAlso("The OTB CookBook"); + SetName("OpticalCalibration"); + SetDescription("Perform optical calibration TOA/TOC (Top Of Atmosphere/Top Of Canopy). Supported sensors: QuickBird, Ikonos, WorldView2, Formosat, Spot5"); + // Documentation + SetDocName("Optical calibration"); + SetDocLongDescription("The application allows to convert pixel values from DN (for Digital Numbers) to physically interpretable and comparable values. Calibrated values are called surface reflectivity and its values lie in the range [0, 1].\nThe first level is called Top Of Atmosphere (TOA) reflectivity. It takes into account the sensor gain, sensor spectral response and the solar illumination.\nThe second level is called Top Of Canopy (TOC) reflectivity. In addition to sensor gain and solar illumination, it takes into account the optical thickness of the atmosphere, the atmospheric pressure, the water vapor amount, the ozone amount, as well as the composition and amount of aerosol gasses.\nIt is also possible to indicate an AERONET file which contains atmospheric parameters (version 1 and version 2 of Aeronet file are supported."); + SetDocLimitations("None"); + SetDocAuthors("OTB-Team"); + SetDocSeeAlso("The OTB CookBook"); - AddDocTag(Tags::Calibration); - - AddParameter(ParameterType_InputImage, "in", "Input"); - SetParameterDescription("in", "Input image filename (values in DN)"); - - AddParameter(ParameterType_OutputImage, "out", "Output"); - SetParameterDescription("out","Output calibrated image filename"); - - AddRAMParameter(); - - AddParameter(ParameterType_Choice, "level", "Calibration Level"); - AddChoice("level.toa", "TOA : Top Of Atmosphere"); - AddChoice("level.toc", "TOC : Top Of Canopy (EXPERIMENTAL)"); - SetParameterString("level", "toa"); - - AddParameter(ParameterType_Empty, "milli", "Convert to milli reflectance"); - SetParameterDescription("milli", "Flag to use milli-reflectance instead of reflectance.\n" - "This allows to save the image with integer pixel type (in the range [0, 1000] instead of floating point in the range [0, 1]. In order to do that, use this option and set the output pixel type (-out filename uint16 for example)"); - DisableParameter("milli"); - MandatoryOff("milli"); - - AddParameter(ParameterType_InputFilename, "rsr", "Relative Spectral Response File"); - std::ostringstream oss; - oss << "Sensor relative spectral response file"<<std::endl; - oss << "By default the application gets these informations in the metadata"; - SetParameterDescription("rsr", oss.str()); - MandatoryOff("rsr"); - - AddParameter(ParameterType_Group,"atmo","Atmospheric parameters"); - SetParameterDescription("atmo","This group allows to set the atmospheric parameters."); - AddParameter(ParameterType_Choice, "atmo.aerosol", "Aerosol Model"); - AddChoice("atmo.aerosol.noaersol", "No Aerosol Model"); - AddChoice("atmo.aerosol.continental", "Continental"); - AddChoice("atmo.aerosol.maritime", "Maritime"); - AddChoice("atmo.aerosol.urban", "Urban"); - AddChoice("atmo.aerosol.desertic", "Desertic"); - - AddParameter(ParameterType_Float, "atmo.oz", "Ozone Amount"); - SetParameterDescription("atmo.oz", "Ozone Amount"); + AddDocTag(Tags::Calibration); + + AddParameter(ParameterType_InputImage, "in", "Input"); + SetParameterDescription("in", "Input image filename (values in DN)"); + + AddParameter(ParameterType_OutputImage, "out", "Output"); + SetParameterDescription("out","Output calibrated image filename"); + + AddRAMParameter(); + + AddParameter(ParameterType_Choice, "level", "Calibration Level"); + AddChoice("level.toa", "TOA : Top Of Atmosphere"); + AddChoice("level.toc", "TOC : Top Of Canopy (EXPERIMENTAL)"); + SetParameterString("level", "toa"); + + AddParameter(ParameterType_Empty, "milli", "Convert to milli reflectance"); + SetParameterDescription("milli", "Flag to use milli-reflectance instead of reflectance.\n" + "This allows to save the image with integer pixel type (in the range [0, 1000] instead of floating point in the range [0, 1]. In order to do that, use this option and set the output pixel type (-out filename uint16 for example)"); + DisableParameter("milli"); + MandatoryOff("milli"); + + AddParameter(ParameterType_InputFilename, "rsr", "Relative Spectral Response File"); + std::ostringstream oss; + oss << "Sensor relative spectral response file"<<std::endl; + oss << "By default the application gets these informations in the metadata"; + SetParameterDescription("rsr", oss.str()); + MandatoryOff("rsr"); + + AddParameter(ParameterType_Group,"atmo","Atmospheric parameters"); + SetParameterDescription("atmo","This group allows to set the atmospheric parameters."); + AddParameter(ParameterType_Choice, "atmo.aerosol", "Aerosol Model"); + AddChoice("atmo.aerosol.noaersol", "No Aerosol Model"); + AddChoice("atmo.aerosol.continental", "Continental"); + AddChoice("atmo.aerosol.maritime", "Maritime"); + AddChoice("atmo.aerosol.urban", "Urban"); + AddChoice("atmo.aerosol.desertic", "Desertic"); + + AddParameter(ParameterType_Float, "atmo.oz", "Ozone Amount"); + SetParameterDescription("atmo.oz", "Ozone Amount"); - AddParameter(ParameterType_Float, "atmo.wa", "Water Vapor Amount"); - SetParameterDescription("atmo.wa", "Water Vapor Amount (in saturation fraction of water)"); + AddParameter(ParameterType_Float, "atmo.wa", "Water Vapor Amount"); + SetParameterDescription("atmo.wa", "Water Vapor Amount (in saturation fraction of water)"); - AddParameter(ParameterType_Float, "atmo.pressure", "Atmospheric Pressure"); - SetParameterDescription("atmo.pressure", "Atmospheric Pressure (in hPa)"); + AddParameter(ParameterType_Float, "atmo.pressure", "Atmospheric Pressure"); + SetParameterDescription("atmo.pressure", "Atmospheric Pressure (in hPa)"); - AddParameter(ParameterType_Float, "atmo.opt", "Aerosol Optical Thickness"); - SetParameterDescription("atmo.opt", "Aerosol Optical Thickness"); - - SetDefaultParameterFloat("atmo.oz", 0.); - SetDefaultParameterFloat("atmo.wa", 2.5); - SetDefaultParameterFloat("atmo.pressure", 1030.); - - SetDefaultParameterFloat("atmo.opt", 0.2); - MandatoryOff("atmo.oz"); - MandatoryOff("atmo.wa"); - MandatoryOff("atmo.pressure"); - MandatoryOff("atmo.opt"); - - AddParameter(ParameterType_InputFilename, "atmo.aeronet", "Aeronet File"); - SetParameterDescription("atmo.aeronet","Aeronet file containing atmospheric parameters"); - MandatoryOff("atmo.aeronet"); - - // Doc example parameter settings - SetDocExampleParameterValue("in", "QB_1_ortho.tif"); - SetDocExampleParameterValue("level", "toa"); - SetDocExampleParameterValue("out", "OpticalCalibration.tif"); + AddParameter(ParameterType_Float, "atmo.opt", "Aerosol Optical Thickness"); + SetParameterDescription("atmo.opt", "Aerosol Optical Thickness"); + + SetDefaultParameterFloat("atmo.oz", 0.); + SetDefaultParameterFloat("atmo.wa", 2.5); + SetDefaultParameterFloat("atmo.pressure", 1030.); + + SetDefaultParameterFloat("atmo.opt", 0.2); + MandatoryOff("atmo.oz"); + MandatoryOff("atmo.wa"); + MandatoryOff("atmo.pressure"); + MandatoryOff("atmo.opt"); + + AddParameter(ParameterType_InputFilename, "atmo.aeronet", "Aeronet File"); + SetParameterDescription("atmo.aeronet","Aeronet file containing atmospheric parameters"); + MandatoryOff("atmo.aeronet"); + + // Doc example parameter settings + SetDocExampleParameterValue("in", "QB_1_ortho.tif"); + SetDocExampleParameterValue("level", "toa"); + SetDocExampleParameterValue("out", "OpticalCalibration.tif"); } void DoUpdateParameters() { - // Nothing to update + // Nothing to update } void DoExecute() { - UInt16VectorImageType::Pointer inImage = GetParameterUInt16VectorImage("in"); - - //Check if valid metadata informations are available to compute ImageToLuminance and LuminanceToReflectance - itk::MetaDataDictionary dict = inImage->GetMetaDataDictionary(); - OpticalImageMetadataInterface::Pointer lImageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(dict); - - // Test if needed data are available : an exception will be thrown - // if one the following Get* return failure. the exception is then - // caught in the Wrapper::Application class which redirect it to - // the logger - // ImageToLuminance - lImageMetadataInterface->GetPhysicalGain(); - lImageMetadataInterface->GetPhysicalBias(); - - // LuminanceToReflectance - lImageMetadataInterface->GetDay(); - lImageMetadataInterface->GetMonth(); + UInt16VectorImageType::Pointer inImage = GetParameterUInt16VectorImage("in"); + + //Check if valid metadata informations are available to compute ImageToLuminance and LuminanceToReflectance + itk::MetaDataDictionary dict = inImage->GetMetaDataDictionary(); + OpticalImageMetadataInterface::Pointer lImageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(dict); + + // Test if needed data are available : an exception will be thrown + // if one the following Get* return failure. the exception is then + // caught in the Wrapper::Application class which redirect it to + // the logger + // ImageToLuminance + lImageMetadataInterface->GetPhysicalGain(); + lImageMetadataInterface->GetPhysicalBias(); + + // LuminanceToReflectance + lImageMetadataInterface->GetDay(); + lImageMetadataInterface->GetMonth(); - lImageMetadataInterface->GetSolarIrradiance(); - lImageMetadataInterface->GetSunElevation(); - - m_ImageToLuminanceFilter = ImageToLuminanceImageFilterType::New(); - m_LuminanceToReflectanceFilter = LuminanceToReflectanceImageFilterType::New(); - m_ReflectanceToSurfaceReflectanceFilter = ReflectanceToSurfaceReflectanceImageFilterType::New(); - - m_ImageToLuminanceFilter->SetInput(inImage); - m_LuminanceToReflectanceFilter->SetInput(m_ImageToLuminanceFilter->GetOutput()); - m_ReflectanceToSurfaceReflectanceFilter->SetInput(m_LuminanceToReflectanceFilter->GetOutput()); - - m_ScaleFilter = ScaleFilterType::New(); - m_ScaleFilter->InPlaceOn(); - - switch ( GetParameterInt("level") ) - { - case Level_TOA: - { - m_LuminanceToReflectanceFilter->UpdateOutputInformation(); - m_ScaleFilter->SetInput(m_LuminanceToReflectanceFilter->GetOutput()); - } - break; - case Level_TOC: - { - m_ReflectanceToSurfaceReflectanceFilter->SetIsSetAtmosphericRadiativeTerms(false); - m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(true); - m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); - m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(false); - - m_AtmosphericParam = m_ReflectanceToSurfaceReflectanceFilter->GetCorrectionParameters(); - //AerosolModelType aeroMod = AtmosphericCorrectionParametersType::NO_AEROSOL; - - switch ( GetParameterInt("atmo.aerosol") ) - { - case Aerosol_Desertic: - { - // Aerosol_Desertic correspond to 4 in the enum but actually in - // the class atmosphericParam it is known as parameter 5 - m_AtmosphericParam->SetAerosolModel(static_cast<AerosolModelType>(5)); - } - break; - default: - { - m_AtmosphericParam->SetAerosolModel(static_cast<AerosolModelType>(GetParameterInt("atmo.aerosol"))); - } - break; - } - // Set the atmospheric param - m_AtmosphericParam->SetOzoneAmount(GetParameterFloat("atmo.oz")); - m_AtmosphericParam->SetWaterVaporAmount(GetParameterFloat("atmo.wa")); - m_AtmosphericParam->SetAtmosphericPressure(GetParameterFloat("atmo.pressure")); - m_AtmosphericParam->SetAerosolOptical(GetParameterFloat("atmo.opt")); + lImageMetadataInterface->GetSolarIrradiance(); + lImageMetadataInterface->GetSunElevation(); + + m_ImageToLuminanceFilter = ImageToLuminanceImageFilterType::New(); + m_LuminanceToReflectanceFilter = LuminanceToReflectanceImageFilterType::New(); + m_ReflectanceToSurfaceReflectanceFilter = ReflectanceToSurfaceReflectanceImageFilterType::New(); + + m_ImageToLuminanceFilter->SetInput(inImage); + m_LuminanceToReflectanceFilter->SetInput(m_ImageToLuminanceFilter->GetOutput()); + m_ReflectanceToSurfaceReflectanceFilter->SetInput(m_LuminanceToReflectanceFilter->GetOutput()); + + m_ScaleFilter = ScaleFilterType::New(); + m_ScaleFilter->InPlaceOn(); + + switch ( GetParameterInt("level") ) + { + case Level_TOA: + { + m_LuminanceToReflectanceFilter->UpdateOutputInformation(); + m_ScaleFilter->SetInput(m_LuminanceToReflectanceFilter->GetOutput()); + } + break; + case Level_TOC: + { + m_ReflectanceToSurfaceReflectanceFilter->SetIsSetAtmosphericRadiativeTerms(false); + m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(true); + m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); + m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(false); + + m_AtmosphericParam = m_ReflectanceToSurfaceReflectanceFilter->GetCorrectionParameters(); + //AerosolModelType aeroMod = AtmosphericCorrectionParametersType::NO_AEROSOL; + + switch ( GetParameterInt("atmo.aerosol") ) + { + case Aerosol_Desertic: + { + // Aerosol_Desertic correspond to 4 in the enum but actually in + // the class atmosphericParam it is known as parameter 5 + m_AtmosphericParam->SetAerosolModel(static_cast<AerosolModelType>(5)); + } + break; + default: + { + m_AtmosphericParam->SetAerosolModel(static_cast<AerosolModelType>(GetParameterInt("atmo.aerosol"))); + } + break; + } + // Set the atmospheric param + m_AtmosphericParam->SetOzoneAmount(GetParameterFloat("atmo.oz")); + m_AtmosphericParam->SetWaterVaporAmount(GetParameterFloat("atmo.wa")); + m_AtmosphericParam->SetAtmosphericPressure(GetParameterFloat("atmo.pressure")); + m_AtmosphericParam->SetAerosolOptical(GetParameterFloat("atmo.opt")); - // Relative Spectral Response File - if (IsParameterEnabled("rsr")) - { - m_ReflectanceToSurfaceReflectanceFilter->SetFilterFunctionValuesFileName(GetParameterString("rsr")); - } - else - { - m_ReflectanceToSurfaceReflectanceFilter->SetFilterFunctionCoef(lImageMetadataInterface->GetSpectralSensitivity()); - } - - // Aeronet file - if (IsParameterEnabled("atmo.aeronet")) - { - m_ReflectanceToSurfaceReflectanceFilter->SetAeronetFileName(GetParameterString("atmo.aeronet")); - } - - m_ReflectanceToSurfaceReflectanceFilter->SetIsSetAtmosphericRadiativeTerms(false); - m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(true); - m_ReflectanceToSurfaceReflectanceFilter->GenerateParameters(); - m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); - m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(false); - - //itk::OStringStream oss; - // oss.str(""); - // oss << m_AtmosphericParam; - // // std::cout << oss.str() << std::endl; - - // AtmosphericRadiativeTerms::Pointer atmoTerms = m_ReflectanceToSurfaceReflectanceFilter->GetAtmosphericRadiativeTerms(); - // oss << std::endl << atmoTerms; - // std::cout << oss.str() << std::endl; - - //rescale the surface reflectance in milli-reflectance - - m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); - m_ScaleFilter->SetInput(m_ReflectanceToSurfaceReflectanceFilter->GetOutput()); - } - break; - } - - // Output Image - const double scale = IsParameterEnabled("milli") ? 1000.0 : 1.0; - m_ScaleFilter->SetCoef(scale); - - SetParameterOutputImage("out", m_ScaleFilter->GetOutput()); + // Relative Spectral Response File + if (IsParameterEnabled("rsr")) + { + m_ReflectanceToSurfaceReflectanceFilter->SetFilterFunctionValuesFileName(GetParameterString("rsr")); + } + else + { + m_ReflectanceToSurfaceReflectanceFilter->SetFilterFunctionCoef(lImageMetadataInterface->GetSpectralSensitivity()); + } + + // Aeronet file + if (IsParameterEnabled("atmo.aeronet")) + { + m_ReflectanceToSurfaceReflectanceFilter->SetAeronetFileName(GetParameterString("atmo.aeronet")); + } + + m_ReflectanceToSurfaceReflectanceFilter->SetIsSetAtmosphericRadiativeTerms(false); + m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(true); + m_ReflectanceToSurfaceReflectanceFilter->GenerateParameters(); + m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); + m_ReflectanceToSurfaceReflectanceFilter->SetUseGenerateParameters(false); + + //itk::OStringStream oss; + // oss.str(""); + // oss << m_AtmosphericParam; + // // std::cout << oss.str() << std::endl; + + // AtmosphericRadiativeTerms::Pointer atmoTerms = m_ReflectanceToSurfaceReflectanceFilter->GetAtmosphericRadiativeTerms(); + // oss << std::endl << atmoTerms; + // std::cout << oss.str() << std::endl; + + //rescale the surface reflectance in milli-reflectance + + m_ReflectanceToSurfaceReflectanceFilter->UpdateOutputInformation(); + m_ScaleFilter->SetInput(m_ReflectanceToSurfaceReflectanceFilter->GetOutput()); + } + break; + } + + // Output Image + const double scale = IsParameterEnabled("milli") ? 1000.0 : 1.0; + m_ScaleFilter->SetCoef(scale); + + SetParameterOutputImage("out", m_ScaleFilter->GetOutput()); } ImageToLuminanceImageFilterType ::Pointer m_ImageToLuminanceFilter;