diff --git a/Documentation/Cookbook/CMakeLists.txt b/Documentation/Cookbook/CMakeLists.txt index aa56436834823f4286cd7f7f0e9f70b6b43d8806..46ced13903345d5cfc11550dc75379b57bf65c42 100644 --- a/Documentation/Cookbook/CMakeLists.txt +++ b/Documentation/Cookbook/CMakeLists.txt @@ -117,10 +117,15 @@ file(COPY ${RST_SOURCE_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Art DESTINATION ${RST_BINARY_DIR}) +# Create symlinks to otb-data/Output and otb-data/Input in the rst build directory +# Used for including figures and images in the CookBook +execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${OTB_DATA_ROOT}/Output" "${RST_BINARY_DIR}/Output") +execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${OTB_DATA_ROOT}/Input" "${RST_BINARY_DIR}/Input") + set(SPHINX_CONF_DIR ${CMAKE_CURRENT_BINARY_DIR}) string(TIMESTAMP OTB_COPYRIGHT_YEAR "%Y") -set(OTB_COPYRIGHT_TEXT "${OTB_COPYRIGHT_YEAR} CNES.The OTB CookBook is licensed under a Creative Commons Attribution-ShareAlike 4.0 International license (CC-BY-SA)") +set(OTB_COPYRIGHT_TEXT "${OTB_COPYRIGHT_YEAR} CNES. The OTB CookBook is licensed under a Creative Commons Attribution-ShareAlike 4.0 International license (CC-BY-SA).") configure_file(${RST_SOURCE_DIR}/conf.py.in ${SPHINX_CONF_DIR}/conf.py @ONLY) @@ -130,7 +135,16 @@ add_custom_target(generate_otbapps_rst COMMAND ${SH_INTERP} ${CMAKE_CURRENT_BINARY_DIR}/RunApplicationsRstGenerator.sh ${RST_BINARY_DIR} WORKING_DIRECTORY ${RST_BINARY_DIR} - COMMENT "Auto-generating Application Reference Documentation in RST" + COMMENT "Auto-generating Application Documentation in RST" + DEPENDS OTBSWIGWrapper-all + ) + +add_custom_target(generate_examples_rst + COMMAND "python3" ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/otbGenerateExamplesRstDoc.py + ${RST_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${RST_BINARY_DIR} + COMMENT "Auto-generating Examples in RST" DEPENDS OTBSWIGWrapper-all ) @@ -152,6 +166,7 @@ add_custom_target(CookBookHTML -c ${SPHINX_CONF_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS generate_otbapps_rst + DEPENDS generate_examples_rst COMMENT "Building RST documentation in html") add_custom_target(CookBookArchive diff --git a/Documentation/Cookbook/Scripts/RunExamples.py b/Documentation/Cookbook/Scripts/RunExamples.py new file mode 100755 index 0000000000000000000000000000000000000000..5bab0c760fd0a9e425131a27597338388f621511 --- /dev/null +++ b/Documentation/Cookbook/Scripts/RunExamples.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2005-2019 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. +# + +import argparse +import glob +import subprocess +import os +from os.path import join +import re + +def run_example(otb_root, otb_data, name, dry_run): + """ + Run an example by name + Assumes the current working directory is an OTB build + """ + + # Find binary in bin/ + binary_names = glob.glob(join("bin", name)) + if len(binary_names) == 0: + raise RuntimeError("Can't find binary for {}".format(name)) + if len(binary_names) > 1: + raise RuntimeError("Found {} binaries for {}".format(len(binary_names), name)) + binary = os.path.abspath(binary_names[0]) + + # Find source file in otb_root/Examples/<tag>/name + sources_files = glob.glob(join(otb_root, "Examples/*/" + name + ".cxx")) + if len(sources_files) == 0: + raise RuntimeError("Can't find source file for {}".format(name)) + if len(sources_files) > 1: + raise RuntimeError("Found {} source files for {}".format(len(sources_files), name)) + filename = os.path.abspath(sources_files[0]) + + # Extract example usage command arguments + usage_rx = r"\/\* Example usage:\n\.\/[a-zA-Z]+ (.*?)\*\/" + match = re.search(usage_rx, open(filename).read(), flags = re.MULTILINE | re.DOTALL) + + if not match: + raise RuntimeError("Can't find example usage in {}".format(filename)) + + example_args = match.group(1).replace("\\\n", "").split() + + # Make sure Output dir exists + os.makedirs(join(otb_data, "Output"), exist_ok=True) + + print("$ " + binary + " " + " ".join(example_args)) + + if dry_run: + return + + # Execute the example with otb_data as working directory, + # because paths are given relative to otb_data in the example usage + subprocess.check_call([binary, *example_args], cwd=otb_data) + +# TODO handle examples with multiple usage (Examples/BasicFilters/DEMToRainbowExample.cxx) + +def main(): + parser = argparse.ArgumentParser(usage="Run one or all OTB cxx examples") + parser.add_argument("otb_root", help="Path to otb repository") + parser.add_argument("otb_data", help="Path to otb-data repository") + parser.add_argument("--name", type=str, help="Run only one example with then given name") + parser.add_argument("-n", "--dry-run", action='store_true', help="Dry run, only print commands") + parser.add_argument("-k", "--keep-going", action='store_true', help="Keep going after failing examples") + args = parser.parse_args() + + if args.name: + run_example(args.otb_root, args.otb_data, args.name, dry_run=args.dry_run) + else: + list_of_examples =[os.path.splitext(os.path.basename(f))[0] for f in glob.glob(join(args.otb_root, "Examples/*/*.cxx"))] + for name in list_of_examples: + try: + run_example(args.otb_root, args.otb_data, name, dry_run=args.dry_run) + except Exception as e: + if args.keep_going: + print("Warning:", e) + else: + raise + +if __name__ == "__main__": + main() diff --git a/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py b/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py new file mode 100644 index 0000000000000000000000000000000000000000..a8a8f9e954b3ec554aee790bad46096d99f9820e --- /dev/null +++ b/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2005-2019 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. +# + +import argparse +import os +import os.path +from os.path import join +from collections import defaultdict +import re +import glob + +from rst_utils import rst_section, RstPageHeading + +def generate_examples_index(rst_dir, list_of_examples): + + # Compute dictionary of tag -> (list of examples) + tag_files = defaultdict(list) + for filename in list_of_examples: + tag = filename.split("/")[1] + name, _ = os.path.splitext(filename.split("/")[2]) + + tag_files[tag].append(join(tag, name + ".rst")) + + # Render index file and tag index files + os.makedirs(join(rst_dir, "Examples"), exist_ok=True) + index_f = open(join(rst_dir, "Examples.rst"), "w") + index_f.write(RstPageHeading("Examples", 3, ref="cpp-examples")) + + for tag, examples_filenames in tag_files.items(): + tag_filename = join("Examples", tag + ".rst") + index_f.write("\t" + tag_filename + "\n") + + with open(join(rst_dir, tag_filename), "w") as tag_f: + tag_f.write(RstPageHeading(tag, 3)) + + for examples_filename in examples_filenames: + tag_f.write("\t" + examples_filename + "\n") + +def indent(str): + return "\n".join([" " + line for line in str.split("\n")]) + +def cpp_uncomment(code): + # Strip '// ' + return "\n".join([line[4:] for line in code.split("\n")]) + +def render_example(filename, otb_root): + "Render a cxx example to rst" + + # Read the source code of the cxx example + code = open(join(otb_root, filename)).read() + + # Don't show the license header to make it nicer, + # and the cookbook is already under a CC license + examples_license_header = open("templates/examples_license_header.txt").read() + code = code.replace(examples_license_header, "") + + # Extract usage + # TODO handle multiple usage + rx_usage = r"\/\* Example usage:\n(\.\/[a-zA-Z]+ (.*?))\*\/" + usage_match = re.search(rx_usage, code, flags = re.MULTILINE | re.DOTALL) + if usage_match is None: + print("Warning: no usage found for example " + filename) + example_usage = "" + else: + example_usage = open("templates/example_usage.rst").read().format(indent(usage_match.group(1).strip())) + + # Don't show usage in example source + code = re.sub(rx_usage, "", code, flags = re.MULTILINE | re.DOTALL) + + # Make the link to the source code + link_name = os.path.basename(filename) + link_href = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/raw/develop/" + filename + "?inline=false" + + # Read the description from the example .rst file if it exists + example_rst_file = join(otb_root, filename.replace(".cxx", ".rst")) + if os.path.isfile(example_rst_file): + rst_description = open(example_rst_file).read() + else: + rst_description = "" + + # Render the template + template_example = open("templates/example.rst").read() + output_rst = template_example.format( + label="example-" + root, + heading=rst_section(name, "="), + description=rst_description, + usage=example_usage, + code=indent(code.strip()), + link_name=link_name, + link_href=link_href + ) + + return output_rst + +if __name__ == "__main__": + parser = argparse.ArgumentParser(usage="Export examples to rst") + parser.add_argument("rst_dir", help="Directory where rst files are generated") + parser.add_argument("otb_root", help="OTB repository root") + args = parser.parse_args() + + # Get list of cxx examples as relative paths from otb_root + list_of_examples = [os.path.relpath(p, start=args.otb_root) for p in glob.glob(join(args.otb_root, "Examples/*/*.cxx"))] + print("Generating rst for {} examples".format(len(list_of_examples))) + + # Generate example index and tag indexes + generate_examples_index(join(args.rst_dir, "C++"), list_of_examples) + + # Generate examples rst + for filename in list_of_examples: + name = os.path.basename(filename) + tag = filename.split("/")[1] + root, ext = os.path.splitext(name) + + os.makedirs(join(args.rst_dir, "C++", "Examples", tag), exist_ok=True) + with open(join(args.rst_dir, "C++", "Examples", tag, root + ".rst"), "w") as output_file: + output_file.write(render_example(filename, args.otb_root)) diff --git a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py index 213e7d91c15dc8dc9f136e8aec04e16bd0ef2c5c..c6c0cc4fb9dd59c630dfd8e97ecaea3e1d518978 100755 --- a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py +++ b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py @@ -29,6 +29,8 @@ from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_ from otb_warnings import application_documentation_warnings +from rst_utils import rst_section, RstPageHeading + linesep = os.linesep def EncloseString(s): @@ -179,17 +181,6 @@ def render_choice(app, key): choices=choice_entries, ) -def rst_section(text, delimiter, ref=None): - "Make a rst section title" - - output = "" - - if ref is not None: - output += ".. _" + ref + ":\n\n" - - output += text + "\n" + delimiter * len(text) + "\n\n" - return output - def rst_parameter_value(app, key): "Render a parameter value to rst" @@ -400,13 +391,6 @@ def GetApplicationTags(appname): app = otbApplication.Registry.CreateApplication(appname) return app.GetDocTags() -def RstPageHeading(text, maxdepth, ref=None): - output = rst_section(text, "=", ref=ref) - output += ".. toctree::" + linesep - output += "\t:maxdepth: " + maxdepth + linesep - output += linesep + linesep - return output - def GenerateRstForApplications(rst_dir): "Generate .rst files for all applications" diff --git a/Documentation/Cookbook/Scripts/rst_utils.py b/Documentation/Cookbook/Scripts/rst_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..d6096b25a7794763fd87711600ce6e63e46d6e83 --- /dev/null +++ b/Documentation/Cookbook/Scripts/rst_utils.py @@ -0,0 +1,18 @@ + +def rst_section(text, delimiter, ref=None): + "Make a rst section title" + + output = "" + + if ref is not None: + output += ".. _" + ref + ":\n\n" + + output += text + "\n" + delimiter * len(text) + "\n\n" + return output + +def RstPageHeading(text, maxdepth, ref=None): + output = rst_section(text, "=", ref=ref) + output += ".. toctree::\n" + output += "\t:maxdepth: {}\n\n\n".format(maxdepth) + return output + diff --git a/Documentation/Cookbook/rst/C++.rst b/Documentation/Cookbook/rst/C++.rst new file mode 100644 index 0000000000000000000000000000000000000000..4898c812bd869d8071324cd0722276e9b1e1d7a8 --- /dev/null +++ b/Documentation/Cookbook/rst/C++.rst @@ -0,0 +1,8 @@ +.. _cpp-api: + +C++ API +======= + +.. toctree:: + + C++/Examples.rst diff --git a/Documentation/Cookbook/rst/index_TOC.rst b/Documentation/Cookbook/rst/index_TOC.rst index bf5f59714ed4eeedc61ac3cf94a9bf3bccb7497c..e09a9db205d9a595230914dc9273ffc92a53a2e3 100644 --- a/Documentation/Cookbook/rst/index_TOC.rst +++ b/Documentation/Cookbook/rst/index_TOC.rst @@ -13,5 +13,6 @@ Table of Contents AdvancedUse Recipes Applications + C++ FAQ Contributors diff --git a/Documentation/Cookbook/rst/templates/example.rst b/Documentation/Cookbook/rst/templates/example.rst new file mode 100644 index 0000000000000000000000000000000000000000..9153a7e2d35aef4525369fbff25ad36619206050 --- /dev/null +++ b/Documentation/Cookbook/rst/templates/example.rst @@ -0,0 +1,13 @@ +.. _{label}: + +{heading} + +{description} + +{usage} + +Example source code (`{link_name} <{link_href}>`_): + +.. code-block:: cpp + +{code} diff --git a/Documentation/Cookbook/rst/templates/example_usage.rst b/Documentation/Cookbook/rst/templates/example_usage.rst new file mode 100644 index 0000000000000000000000000000000000000000..d17615ae5ad2d41ca4ab475aaee025174a4973da --- /dev/null +++ b/Documentation/Cookbook/rst/templates/example_usage.rst @@ -0,0 +1,5 @@ +Example usage: + +.. code-block:: bash + +{} diff --git a/Documentation/Cookbook/rst/templates/examples_license_header.txt b/Documentation/Cookbook/rst/templates/examples_license_header.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a2da0dcdb19bbcb60e8b40d120f330b7dfb5fe8 --- /dev/null +++ b/Documentation/Cookbook/rst/templates/examples_license_header.txt @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2005-2019 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. + */ diff --git a/Examples/Application/ApplicationExample.cxx b/Examples/Application/ApplicationExample.cxx index 1874d28688255edd62d43d518648973bbbef2461..58d01e0509b2e6e3f271a48a998e01ff467370c4 100644 --- a/Examples/Application/ApplicationExample.cxx +++ b/Examples/Application/ApplicationExample.cxx @@ -19,88 +19,57 @@ */ +/* Example usage: +./ApplicationExample Input/QB_Suburb.png Output/ApplicationExample.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {ApplicationExample.png} -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex // This example illustrates the creation of an application. // A new application is a class, which derives from \subdoxygen{otb}{Wrapper}{Application} class. // We start by including the needed header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" -// Software Guide : EndCodeSnippet namespace otb { -// Software Guide : BeginLatex // Application class is defined in Wrapper namespace. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet namespace Wrapper { -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // ExampleApplication class is derived from Application class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet class ApplicationExample : public Application -// Software Guide : EndCodeSnippet { public: - // Software Guide : BeginLatex // Class declaration is followed by \code{ITK} public types for the class, the superclass and // smart pointers. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef ApplicationExample Self; - typedef Application Superclass; - typedef itk::SmartPointer<Self> Pointer; + typedef ApplicationExample Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Following macros are necessary to respect ITK object factory mechanisms. Please report // to \ref{sec:FilterConventions} for additional information. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet itkNewMacro(Self); itkTypeMacro(ExampleApplication, otb::Application); - // Software Guide : EndCodeSnippet private: - // Software Guide : BeginLatex // \doxygen{otb}{Application} relies on three main private methods: \code{DoInit()}, \code{DoUpdate()}, and \code{DoExecute()}. // Section \ref{sec:appArchitecture} gives a description a these methods. - // Software Guide : EndLatex - // Software Guide : BeginLatex // \code{DoInit()} method contains class information and description, parameter set up, and example values. - // Software Guide : EndLatex void DoInit() override { - // Software Guide : BeginLatex // Application name and description are set using following methods : // \begin{description} // \item[\code{SetName()}] Name of the application. @@ -111,44 +80,36 @@ private: // \item[\code{SetDocAuthors()}] Set the application Authors. Author List. Format : "John Doe, Winnie the Pooh" \dots // \item[\code{SetDocSeeAlso()}] If the application is related to one another, it can be mentioned. // \end{description} - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SetName("Example"); - SetDescription("This application opens an image and save it. " - "Pay attention, it includes Latex snippets in order to generate " - "software guide documentation"); + SetDescription( + "This application opens an image and save it. " + "Pay attention, it includes Latex snippets in order to generate " + "software guide documentation"); SetDocName("Example"); - SetDocLongDescription("The purpose of this application is " - "to present parameters types," - " and Application class framework. " - "It is used to generate Software guide documentation" - " for Application chapter example."); + SetDocLongDescription( + "The purpose of this application is " + "to present parameters types," + " and Application class framework. " + "It is used to generate Software guide documentation" + " for Application chapter example."); SetDocLimitations("None"); SetDocAuthors("OTB-Team"); SetDocSeeAlso(" "); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // \code{AddDocTag()} method categorize the application using relevant tags. // The header file \code{otbWrapperTags.h} in OTB sources contains some predefined tags defined in \code{Tags} namespace. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet AddDocTag(Tags::Analysis); AddDocTag("Test"); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Application parameters declaration is done using \code{AddParameter()} method. // \code{AddParameter()} requires the input parameter type // (ParameterType\_InputImage, ParameterType\_Int, ParameterType\_Float), its name and description. // \subdoxygen{otb}{Wrapper}{Application} class contains methods to set parameters characteristics. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet AddParameter(ParameterType_InputImage, "in", "Input Image"); AddParameter(ParameterType_OutputImage, "out", "Output Image"); @@ -181,13 +142,11 @@ private: AddChoice("inchoice.choice1", "Choice 1"); AddChoice("inchoice.choice2", "Choice 2"); AddChoice("inchoice.choice3", "Choice 3"); - - AddParameter(ParameterType_Float, "inchoice.choice1.floatchoice1" - , "Example of float parameter for choice1"); + + AddParameter(ParameterType_Float, "inchoice.choice1.floatchoice1", "Example of float parameter for choice1"); SetDefaultParameterFloat("inchoice.choice1.floatchoice1", 0.125); - AddParameter(ParameterType_Float, "inchoice.choice3.floatchoice3" - , "Example of float parameter for choice3"); + AddParameter(ParameterType_Float, "inchoice.choice3.floatchoice3", "Example of float parameter for choice3"); SetDefaultParameterFloat("inchoice.choice3.floatchoice3", 5.0); AddParameter(ParameterType_Group, "ingroup", "Input group"); @@ -195,14 +154,12 @@ private: AddParameter(ParameterType_Int, "ingroup.valint", "Example of integer parameter for group"); MandatoryOff("ingroup.valint"); AddParameter(ParameterType_Group, "ingroup.images", "Input Images group"); - AddParameter(ParameterType_InputImage, "ingroup.images.inputimage" - , "Input Image"); + AddParameter(ParameterType_InputImage, "ingroup.images.inputimage", "Input Image"); MandatoryOff("ingroup.images.inputimage"); AddParameter(ParameterType_Group, "outgroup", "Output group"); MandatoryOff("outgroup"); - AddParameter(ParameterType_OutputImage, "outgroup.outputimage" - , "Output Image"); + AddParameter(ParameterType_OutputImage, "outgroup.outputimage", "Output Image"); MandatoryOff("outgroup.outputimage"); AddParameter(ParameterType_InputImageList, "il", "Input image list"); MandatoryOff("il"); @@ -220,58 +177,42 @@ private: AddParameter(ParameterType_ComplexOutputImage, "cout", "Output complex image"); MandatoryOff("cin"); MandatoryOff("cout"); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // An example of command-line is automatically generated. Method \code{SetDocExampleParameterValue()} is // used to set parameters. Dataset should be located in \code{OTB-Data/Examples} directory. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SetDocExampleParameterValue("boolean", "true"); SetDocExampleParameterValue("in", "QB_Suburb.png"); SetDocExampleParameterValue("out", "Application_Example.png"); - // Software Guide : EndCodeSnippet } - // Software Guide : BeginLatex // \code{DoUpdateParameters()} is called as soon as a parameter value change. Section \ref{sec:appDoUpdateParameters} // gives a complete description of this method. - // Software Guide : EndLatex // Software Guide :BeginCodeSnippet void DoUpdateParameters() override { } - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // \code{DoExecute()} contains the application core. Section \ref{sec:appDoExecute} // gives a complete description of this method. - // Software Guide : EndLatex // Software Guide :BeginCodeSnippet void DoExecute() override { FloatVectorImageType::Pointer inImage = GetParameterImage("in"); int paramInt = GetParameterInt("param2"); - otbAppLogDEBUG( << paramInt << std::endl ); + otbAppLogDEBUG(<< paramInt << std::endl); int paramFloat = GetParameterFloat("param3"); - otbAppLogINFO( << paramFloat ); + otbAppLogINFO(<< paramFloat); SetParameterOutputImage("out", inImage); } // Software Guide :EndCodeSnippet - - }; -} -} +} // namespace Wrapper +} // namespace otb -// Software Guide : BeginLatex // Finally \code{OTB\_APPLICATION\_EXPORT} is called: -// Software Guide : EndLatex // Software Guide :BeginCodeSnippet OTB_APPLICATION_EXPORT(otb::Wrapper::ApplicationExample) // Software Guide :EndCodeSnippet - - diff --git a/Examples/BasicFilters/BandMathFilterExample.cxx b/Examples/BasicFilters/BandMathFilterExample.cxx index f7aaf1f78e271dd8bf8e746334ae386c318d174f..d5e798f58fd307bde14d5bab6d4a123de33906d7 100644 --- a/Examples/BasicFilters/BandMathFilterExample.cxx +++ b/Examples/BasicFilters/BandMathFilterExample.cxx @@ -18,20 +18,18 @@ * limitations under the License. */ +/* Example usage: +./BandMathFilterExample Input/qb_RoadExtract.tif Output/RoadExtractBandMath.tif Output/qb_BandMath-pretty.jpg +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {RoadExtractBandMath.tif}, {qb_BandMath-pretty.jpg} -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex +// Software Guide : BeginDescription // -// This filter is based on the mathematical parser library muParser. -// The built in functions and operators list is available at: -// \url{http://muparser.sourceforge.net/mup_features.html}. +// This filter is based on the mathematical parser library muParser. +// The built in functions and operators list is available at: +// http://muparser.sourceforge.net/mup_features.html. // -// In order to use this filter, at least one input image should be +// In order to use this filter, at least one input image should be // set. An associated variable name can be specified or not by using // the corresponding SetNthInput method. For the nth input image, if // no associated variable name has been specified, a default variable @@ -40,9 +38,9 @@ // // The next step is to set the expression according to the variable // names. For example, in the default case with three input images the -// following expression is valid : "(b1+b2)*b3". +// following expression is valid: ``(b1+b2)*b3``. // -// Software Guide : EndLatex +// Software Guide : EndDescription #include "itkMacro.h" #include <iostream> @@ -55,66 +53,39 @@ #include "itkCastImageFilter.h" #include "otbVectorImageToImageListFilter.h" -// Software Guide : BeginLatex -// // We start by including the required header file. // The aim of this example is to compute the Normalized Difference Vegetation Index (NDVI) // from a multispectral image and then apply a threshold to this // index to extract areas containing a dense vegetation canopy. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet #include "otbBandMathImageFilter.h" -// Software Guide : EndCodeSnippet -int main( int argc, char* argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputImageFile "; std::cerr << " outputPrettyImageFile" << std::endl; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// We start by the classical \code{typedef}s needed for reading and -// writing the images. The \doxygen{otb}{BandMathImageFilter} class -// works with \doxygen{otb}{Image} as input, so we need to define additional -// filters to extract each layer of the multispectral image. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef double PixelType; - typedef otb::VectorImage<PixelType, 2> InputImageType; - typedef otb::Image<PixelType, 2> OutputImageType; - typedef otb::ImageList<OutputImageType> ImageListType; - typedef otb::VectorImageToImageListFilter<InputImageType, ImageListType> - VectorImageToImageListType; - typedef otb::ImageFileReader<InputImageType> ReaderType; - typedef otb::ImageFileWriter<OutputImageType> WriterType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// We can now define the type for the filter: -// -// Software Guide : EndLatex + // We start by the typedef needed for reading and + // writing the images. The BandMathImageFilter class + // works with Image as input, so we need to define additional + // filters to extract each layer of the multispectral image. -// Software Guide : BeginCodeSnippet - typedef otb::BandMathImageFilter<OutputImageType> FilterType; -// Software Guide : EndCodeSnippet + typedef double PixelType; + typedef otb::VectorImage<PixelType, 2> InputImageType; + typedef otb::Image<PixelType, 2> OutputImageType; + typedef otb::ImageList<OutputImageType> ImageListType; + typedef otb::VectorImageToImageListFilter<InputImageType, ImageListType> VectorImageToImageListType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; -// Software Guide : BeginLatex -// -// We instantiate the filter, the reader, and the writer: -// -// Software Guide : EndLatex + // We can now define the type for the filter: + typedef otb::BandMathImageFilter<OutputImageType> FilterType; -// Software Guide : BeginCodeSnippet + // We instantiate the filter, the reader, and the writer: ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); @@ -123,20 +94,12 @@ int main( int argc, char* argv[]) writer->SetInput(filter->GetOutput()); reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); -// Software Guide : EndCodeSnippet reader->UpdateOutputInformation(); - -// Software Guide : BeginLatex -// -// We now need to extract each band from the input \doxygen{otb}{VectorImage}, -// it illustrates the use of the \doxygen{otb}{VectorImageToImageList}. -// Each extracted layer is an input to the \doxygen{otb}{BandMathImageFilter}: -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + // We now need to extract each band from the input \doxygen{otb}{VectorImage}, + // it illustrates the use of the \doxygen{otb}{VectorImageToImageList}. + // Each extracted layer is an input to the \doxygen{otb}{BandMathImageFilter}: VectorImageToImageListType::Pointer imageList = VectorImageToImageListType::New(); imageList->SetInput(reader->GetOutput()); @@ -144,72 +107,48 @@ int main( int argc, char* argv[]) const unsigned int nbBands = reader->GetOutput()->GetNumberOfComponentsPerPixel(); - for(unsigned int j = 0; j < nbBands; ++j) - { - filter->SetNthInput(j, imageList->GetOutput()->GetNthElement(j)); - } -// Software Guide : EndCodeSnippet + for (unsigned int j = 0; j < nbBands; ++j) + { + filter->SetNthInput(j, imageList->GetOutput()->GetNthElement(j)); + } -// Software Guide : BeginLatex -// -// Now we can define the mathematical expression to perform on the layers (b1, b2, b3, b4). -// The filter takes advantage of the parsing capabilities of the muParser library and -// allows setting the expression as on a digital calculator. -// -// The expression below returns 255 if the ratio $(NIR-RED)/(NIR+RED)$ is greater than 0.4 and 0 if not. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + // Now we can define the mathematical expression to perform on the layers (b1, b2, b3, b4). + // The filter takes advantage of the parsing capabilities of the muParser library and + // allows setting the expression as on a digital calculator. + // + // The expression below returns 255 if the ratio $(NIR-RED)/(NIR+RED)$ is greater than 0.4 and 0 if not. filter->SetExpression("if((b4-b3)/(b4+b3) > 0.4, 255, 0)"); - - #ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS + +#ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS filter->SetExpression("((b4-b3)/(b4+b3) > 0.4) ? 255 : 0"); - #else +#else filter->SetExpression("if((b4-b3)/(b4+b3) > 0.4, 255, 0)"); - #endif - -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// We can now plug the pipeline and run it. -// -// Software Guide : EndLatex +#endif -// Software Guide : BeginCodeSnippet + // We can now plug the pipeline and run it. writer->Update(); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The muParser library also provides the possibility to extend existing built-in functions. For example, -// you can use the OTB expression "ndvi(b3, b4)" with the filter. In this instance, the mathematical expression would be -// \textit{if($ndvi(b3, b4)>0.4$, 255, 0)}, which would return the same result. -// -// Software Guide : EndLatex - -// Software Guide : BeginLatex -// -// Figure~\ref{fig:BandMathImageFilter} shows the result of the threshold applied to the NDVI index -// of a Quickbird image. -// \begin{figure} -// \center -// \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} -// \includegraphics[width=0.45\textwidth]{qb_BandMath-pretty.eps} -// \itkcaption[Band Math]{From left to right: -// Original image, thresholded NDVI index.} -// \label{fig:BandMathImageFilter} -// \end{figure} -// -// Software Guide : EndLatex - typedef otb::Image<unsigned char, 2> OutputPrettyImageType; - typedef otb::ImageFileWriter<OutputPrettyImageType> PrettyImageFileWriterType; + // The muParser library also provides the possibility to extend existing built-in functions. For example, + // you can use the OTB expression "ndvi(b3, b4)" with the filter. In this instance, the mathematical expression would be + // \textit{if($ndvi(b3, b4)>0.4$, 255, 0)}, which would return the same result. + + // Figure~\ref{fig:BandMathImageFilter} shows the result of the threshold applied to the NDVI index + // of a Quickbird image. + // \begin{figure} + // \center + // \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} + // \includegraphics[width=0.45\textwidth]{qb_BandMath-pretty.eps} + // \itkcaption[Band Math]{From left to right: + // Original image, thresholded NDVI index.} + // \label{fig:BandMathImageFilter} + // \end{figure} + + typedef otb::Image<unsigned char, 2> OutputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> PrettyImageFileWriterType; typedef itk::CastImageFilter<OutputImageType, OutputPrettyImageType> CastImageFilterType; PrettyImageFileWriterType::Pointer prettyWriter = PrettyImageFileWriterType::New(); - CastImageFilterType::Pointer caster = CastImageFilterType::New(); + CastImageFilterType::Pointer caster = CastImageFilterType::New(); caster->SetInput(filter->GetOutput()); prettyWriter->SetInput(caster->GetOutput()); diff --git a/Examples/BasicFilters/BandMathXImageFilterExample.cxx b/Examples/BasicFilters/BandMathXImageFilterExample.cxx index bf5d3b1a7cdee126ebf2d53fd19119fad5fa984f..7978a9c30b8822cf7e3198e03520256f2587f898 100644 --- a/Examples/BasicFilters/BandMathXImageFilterExample.cxx +++ b/Examples/BasicFilters/BandMathXImageFilterExample.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./BandMathXImageFilterExample Input/qb_RoadExtract.tif Output/qb_BandMath-res1.tif Output/qb_BandMath-res2.tif Output/context.txt +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {qb_BandMath-res1.tif}, {qb_BandMath-res2.tif}, {context.txt} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This filter is based on the mathematical parser library muParserX. // The built in functions and operators list is available at: // \url{http://articles.beltoforion.de/article.php?a=muparserx}. @@ -39,8 +36,6 @@ // corresponding input index plus one (for instance, im1 is related to the first input). // If the jth input image is multidimensional, then the variable imj represents a vector whose components are related to its bands. // In order to access the kth band, the variable observes the following pattern : imjbk. -// -// Software Guide : EndLatex #include "itkMacro.h" #include <iostream> @@ -49,233 +44,138 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : BeginLatex -// // We start by including the needed header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbBandMathXImageFilter.h" -// Software Guide : EndCodeSnippet -int main( int argc, char* argv[]) +int main(int argc, char* argv[]) { if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputImageFile "; std::cerr << " outputImageFile2"; std::cerr << " context.txt" << std::endl; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// Then, we set the classical \code{typedef}s needed for reading and -// writing the images. The \doxygen{otb}{BandMathXImageFilter} class -// works with \doxygen{otb}{VectorImage}. -// -// Software Guide : EndLatex + // Then, we set the classical \code{typedef}s needed for reading and + // writing the images. The \doxygen{otb}{BandMathXImageFilter} class + // works with \doxygen{otb}{VectorImage}. -// Software Guide : BeginCodeSnippet - typedef double PixelType; - typedef otb::VectorImage<PixelType, 2> ImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; -// Software Guide : EndCodeSnippet + typedef double PixelType; + typedef otb::VectorImage<PixelType, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<ImageType> WriterType; -// Software Guide : BeginLatex -// -// We can now define the type for the filter: -// -// Software Guide : EndLatex + // We can now define the type for the filter: -// Software Guide : BeginCodeSnippet - typedef otb::BandMathXImageFilter<ImageType> FilterType; -// Software Guide : EndCodeSnippet + typedef otb::BandMathXImageFilter<ImageType> FilterType; -// Software Guide : BeginLatex -// -// We instantiate the filter, the reader, and the writer: -// -// Software Guide : EndLatex + // We instantiate the filter, the reader, and the writer: -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); FilterType::Pointer filter = FilterType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The reader and the writer are parametrized with usual settings: -// -// Software Guide : EndLatex + // The reader and the writer are parametrized with usual settings: -// Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The aim of this example is to compute a simple high-pass filter. -// For that purpose, we are going to perform the difference between the original signal -// and its averaged version. The definition of the expression that follows is only suitable for a 4-band image. -// So first, we must check this requirement: -// -// Software Guide : EndLatex + // The aim of this example is to compute a simple high-pass filter. + // For that purpose, we are going to perform the difference between the original signal + // and its averaged version. The definition of the expression that follows is only suitable for a 4-band image. + // So first, we must check this requirement: -// Software Guide : BeginCodeSnippet - reader->UpdateOutputInformation(); - if (reader->GetOutput()->GetNumberOfComponentsPerPixel() !=4) + reader->UpdateOutputInformation(); + if (reader->GetOutput()->GetNumberOfComponentsPerPixel() != 4) itkGenericExceptionMacro(<< "Input image must have 4 bands." << std::endl); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Now, we can define the expression. The variable im1 represents a pixel (made of 4 components) of the input image. -// The variable im1b1N5x5 represents a neighborhood of size 5x5 around this pixel (and so on for each band). -// The last element we need is the operator 'mean'. By setting its inputs with four neigborhoods, we tell this operator to process the four related bands. -// As output, it will produce a vector of four components; this is consistent with the fact that we wish to perform a difference with im1. -// -// Thus, the expression is as follows: + // Now, we can define the expression. The variable im1 represents a pixel (made of 4 components) of the input image. + // The variable im1b1N5x5 represents a neighborhood of size 5x5 around this pixel (and so on for each band). + // The last element we need is the operator 'mean'. By setting its inputs with four neigborhoods, we tell this operator to process the four related bands. + // As output, it will produce a vector of four components; this is consistent with the fact that we wish to perform a difference with im1. + // + // Thus, the expression is as follows: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - filter->SetExpression("im1-mean(im1b1N5x5,im1b2N5x5,im1b3N5x5,im1b4N5x5)"); -// Software Guide : EndCodeSnippet + filter->SetExpression("im1-mean(im1b1N5x5,im1b2N5x5,im1b3N5x5,im1b4N5x5)"); -// Software Guide : BeginLatex -// -// Note that the importance of the averaging is driven by the names of the neighborhood variables. -// Last thing we have to do, is to set the pipeline: -// -// Software Guide : EndLatex + // Note that the importance of the averaging is driven by the names of the neighborhood variables. + // Last thing we have to do, is to set the pipeline: -// Software Guide : BeginCodeSnippet - filter->SetNthInput(0,reader->GetOutput()); - writer->SetInput(filter->GetOutput()); - writer->Update(); -// Software Guide : EndCodeSnippet + filter->SetNthInput(0, reader->GetOutput()); + writer->SetInput(filter->GetOutput()); + writer->Update(); -// Software Guide : BeginLatex -// -// Figure~\ref{fig:BandMathXImageFilter} shows the result of our high-pass filter. -// \begin{figure} -// \center -// \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} -// \includegraphics[width=0.45\textwidth]{qb_BandMath-res1.eps} -// \itkcaption[Band Math X]{From left to right: -// Original image, high-pass filter output.} -// \label{fig:BandMathXImageFilter} -// \end{figure} -// -// Software Guide : EndLatex + // Figure~\ref{fig:BandMathXImageFilter} shows the result of our high-pass filter. + // \begin{figure} + // \center + // \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} + // \includegraphics[width=0.45\textwidth]{qb_BandMath-res1.eps} + // \itkcaption[Band Math X]{From left to right: + // Original image, high-pass filter output.} + // \label{fig:BandMathXImageFilter} + // \end{figure} -// Software Guide : BeginLatex -// -// Now let's see a little bit more complex example. -// The aim now is to give the central pixel a higher weight. Moreover : -// - we wish to use smaller neighborhoods -// - we wish to drop the 4th band -// - we wish to add a given number to each band. -// -// First, we instantiate new filters to later make a proper pipeline: -// -// Software Guide : EndLatex + // Now let's see a little bit more complex example. + // The aim now is to give the central pixel a higher weight. Moreover : + // - we wish to use smaller neighborhoods + // - we wish to drop the 4th band + // - we wish to add a given number to each band. + // + // First, we instantiate new filters to later make a proper pipeline: -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader2 = ReaderType::New(); WriterType::Pointer writer2 = WriterType::New(); FilterType::Pointer filter2 = FilterType::New(); reader2->SetFileName(argv[1]); writer2->SetFileName(argv[3]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We define a new kernel (rows are separated by semi-colons, whereas their elements are separated by commas): -// -// Software Guide : EndLatex + // We define a new kernel (rows are separated by semi-colons, whereas their elements are separated by commas): -// Software Guide : BeginCodeSnippet - filter2->SetMatrix("kernel","{ 0.1 , 0.1 , 0.1; 0.1 , 0.2 , 0.1; 0.1 , 0.1 , 0.1 }"); -// Software Guide : EndCodeSnippet + filter2->SetMatrix("kernel", "{ 0.1 , 0.1 , 0.1; 0.1 , 0.2 , 0.1; 0.1 , 0.1 , 0.1 }"); -// Software Guide : BeginLatex -// -// We then define a new constant: -// -// Software Guide : EndLatex + // We then define a new constant: -// Software Guide : BeginCodeSnippet - filter2->SetConstant("cst",1.0); -// Software Guide : EndCodeSnippet + filter2->SetConstant("cst", 1.0); -// Software Guide : BeginLatex -// -// We now set the expression (note the use of 'dotpr' operator, as well as the 'bands' operator which is used as a band selector): -// -// Software Guide : EndLatex + // We now set the expression (note the use of 'dotpr' operator, as well as the 'bands' operator which is used as a band selector): -// Software Guide : BeginCodeSnippet filter2->SetExpression("bands(im1,{1,2,3})-dotpr(kernel,im1b1N3x3,im1b2N3x3,im1b3N3x3) + {cst,cst,cst}"); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// It is possible to export these definitions to a txt file (they will be reusable later thanks to the method ImportContext): -// -// Software Guide : EndLatex + // It is possible to export these definitions to a txt file (they will be reusable later thanks to the method ImportContext): -// Software Guide : BeginCodeSnippet filter2->ExportContext(argv[4]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// And finally, we set the pipeline: -// -// Software Guide : EndLatex + // And finally, we set the pipeline: -// Software Guide : BeginCodeSnippet - filter2->SetNthInput(0,reader2->GetOutput()); - writer2->SetInput(filter2->GetOutput()); - writer2->Update(); -// Software Guide : EndCodeSnippet + filter2->SetNthInput(0, reader2->GetOutput()); + writer2->SetInput(filter2->GetOutput()); + writer2->Update(); -// Software Guide : BeginLatex -// -// Figure~\ref{fig:BandMathXImageFilter2} shows the result of the second filter. -// \begin{figure} -// \center -// \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} -// \includegraphics[width=0.45\textwidth]{qb_BandMath-res2.eps} -// \itkcaption[Band Math X]{From left to right: -// Original image, second filter output.} -// \label{fig:BandMathXImageFilter2} -// \end{figure} -// -// Software Guide : EndLatex + // Figure~\ref{fig:BandMathXImageFilter2} shows the result of the second filter. + // \begin{figure} + // \center + // \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps} + // \includegraphics[width=0.45\textwidth]{qb_BandMath-res2.eps} + // \itkcaption[Band Math X]{From left to right: + // Original image, second filter output.} + // \label{fig:BandMathXImageFilter2} + // \end{figure} -// Software Guide : BeginLatex -// -// Finally, it is strongly recommended to take a look at the cookbook, where additional information and examples can be found (http://www.orfeo-toolbox.org/packages/OTBCookBook.pdf). -// -// Software Guide : EndLatex + // Finally, it is strongly recommended to take a look at the cookbook, where additional information and examples can be found + // (http://www.orfeo-toolbox.org/packages/OTBCookBook.pdf). return EXIT_SUCCESS; diff --git a/Examples/BasicFilters/DEMToRainbowExample.cxx b/Examples/BasicFilters/DEMToRainbowExample.cxx index 33df21aaaac1f50e3425aa3706d32fbf97cc36fd..f1cf3e83a3ca04a550f95b21bff3dbcbb325a763 100644 --- a/Examples/BasicFilters/DEMToRainbowExample.cxx +++ b/Examples/BasicFilters/DEMToRainbowExample.cxx @@ -19,24 +19,21 @@ */ +/* Example usage: +./DEMToRainbowExample Output/DEMToRainbowImageGenerator.png 6.5 45.5 500 500 0.002 -0.002 Input/DEM_srtm +*/ -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {DEMToRainbowImageGenerator.png} -// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Input/DEM_srtm -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {DEMToHotImageGenerator.png} -// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Input/DEM_srtm hot -// Software Guide : EndCommandLineArgs +/* Example usage: +./DEMToRainbowExample Output/DEMToHotImageGenerator.png 6.5 45.5 500 500 0.002 -0.002 Input/DEM_srtm hot +*/ + + +/* Example usage: +./DEMToRainbowExample Output/DEMToReliefImageGenerator.png 6.5 45.5 500 500 0.002 -0.002 Input/DEM_srtm relief +*/ -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {DEMToReliefImageGenerator.png} -// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Input/DEM_srtm relief -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // In some situation, it is desirable to represent a gray scale image in color for easier // interpretation. This is particularly the case if pixel values in the image are used // to represent some data such as elevation, deformation map, @@ -48,8 +45,6 @@ // combined with the \doxygen{otb}{ScalarToRainbowRGBPixelFunctor}. You can refer to the // source code or to section \ref{sec:ReadDEM} for the DEM conversion to image, // we will focus on the color conversion part here. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -59,24 +54,22 @@ #include "otbDEMToImageGenerator.h" #include "otbReliefColormapFunctor.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 9) - { - std::cout << argv[0] << - " <output_filename> <Longitude Output Origin point>"; - std::cout << - " <Latitude Output Origin point> <X Output Size> <Y Output size>"; - std::cout << " <X Spacing> <Y Spacing> <DEM folder path>" << std::endl; + { + std::cout << argv[0] << " <output_filename> <Longitude Output Origin point>"; + std::cout << " <Latitude Output Origin point> <X Output Size> <Y Output size>"; + std::cout << " <X Spacing> <Y Spacing> <DEM folder path>" << std::endl; return EXIT_FAILURE; - } + } - typedef double PixelType; - typedef unsigned char UCharPixelType; - typedef itk::RGBPixel<UCharPixelType> RGBPixelType; - typedef otb::Image<PixelType, 2> ImageType; - typedef otb::Image<RGBPixelType, 2> RGBImageType; + typedef double PixelType; + typedef unsigned char UCharPixelType; + typedef itk::RGBPixel<UCharPixelType> RGBPixelType; + typedef otb::Image<PixelType, 2> ImageType; + typedef otb::Image<RGBPixelType, 2> RGBImageType; typedef otb::ImageFileWriter<RGBImageType> WriterType; WriterType::Pointer writer = WriterType::New(); @@ -86,9 +79,9 @@ int main(int argc, char * argv[]) DEMToImageGeneratorType::Pointer demToImage = DEMToImageGeneratorType::New(); - typedef DEMToImageGeneratorType::SizeType SizeType; - typedef DEMToImageGeneratorType::SpacingType SpacingType; - typedef DEMToImageGeneratorType::PointType PointType; + typedef DEMToImageGeneratorType::SizeType SizeType; + typedef DEMToImageGeneratorType::SpacingType SpacingType; + typedef DEMToImageGeneratorType::PointType PointType; otb::DEMHandler::Instance()->OpenDEMDirectory(argv[8]); @@ -110,99 +103,77 @@ int main(int argc, char * argv[]) demToImage->SetOutputSpacing(spacing); - // Software Guide : BeginLatex - // // As in the previous example, the \doxygen{itk}{ScalarToRGBColormapImageFilter} is // the filter in charge of calling the functor we specify to do the work for // each pixel. Here it is the \doxygen{otb}{ScalarToRainbowRGBPixelFunctor}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::ScalarToRGBColormapImageFilter<ImageType, - RGBImageType> ColorMapFilterType; - ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); + typedef itk::ScalarToRGBColormapImageFilter<ImageType, RGBImageType> ColorMapFilterType; + ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); colormapper->UseInputImageExtremaForScalingOff(); if (argc == 9) - { - typedef otb::Functor::ScalarToRainbowRGBPixelFunctor<PixelType, - RGBPixelType> - ColorMapFunctorType; - ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); + { + typedef otb::Functor::ScalarToRainbowRGBPixelFunctor<PixelType, RGBPixelType> ColorMapFunctorType; + ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); colormap->SetMinimumInputValue(0); colormap->SetMaximumInputValue(4000); colormapper->SetColormap(colormap); - } - // Software Guide : EndCodeSnippet + } else - { + { if (strcmp(argv[9], "hot") == 0) - { - typedef itk::Function::HotColormapFunction<PixelType, - RGBPixelType> - ColorMapFunctorType; - ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); + { + typedef itk::Function::HotColormapFunction<PixelType, RGBPixelType> ColorMapFunctorType; + ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); colormap->SetMinimumInputValue(0); colormap->SetMaximumInputValue(4000); colormapper->SetColormap(colormap); - } + } else - { - typedef otb::Functor::ReliefColormapFunctor<PixelType, - RGBPixelType> - ColorMapFunctorType; - ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); + { + typedef otb::Functor::ReliefColormapFunctor<PixelType, RGBPixelType> ColorMapFunctorType; + ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); colormap->SetMinimumInputValue(0); colormap->SetMaximumInputValue(4000); colormapper->SetColormap(colormap); - } } - // Software Guide : BeginLatex - // + } // And we connect the color mapper filter with the filter producing // the image of the DEM: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet colormapper->SetInput(demToImage->GetOutput()); - // Software Guide : EndCodeSnippet writer->SetInput(colormapper->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Figure~\ref{fig:RAINBOW_FILTER} shows the effect of applying the filter to // a gray scale image. // -// \begin{figure} -// \center -// \includegraphics[width=0.44\textwidth]{pretty_DEMToImageGenerator.eps} -// \includegraphics[width=0.44\textwidth]{DEMToRainbowImageGenerator.eps} -// \includegraphics[width=0.44\textwidth]{DEMToHotImageGenerator.eps} -// \includegraphics[width=0.44\textwidth]{DEMToReliefImageGenerator.eps} -// \itkcaption[Grayscale to color]{The gray level DEM extracted from SRTM -// data (top-left) and the same area represented in color.} -// \label{fig:RAINBOW_FILTER} -// \end{figure} -// Software Guide : EndLatex + // \begin{figure} + // \center + // \includegraphics[width=0.44\textwidth]{pretty_DEMToImageGenerator.eps} + // \includegraphics[width=0.44\textwidth]{DEMToRainbowImageGenerator.eps} + // \includegraphics[width=0.44\textwidth]{DEMToHotImageGenerator.eps} + // \includegraphics[width=0.44\textwidth]{DEMToReliefImageGenerator.eps} + // \itkcaption[Grayscale to color]{The gray level DEM extracted from SRTM + // data (top-left) and the same area represented in color.} + // \label{fig:RAINBOW_FILTER} + // \end{figure} return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/FrostImageFilter.cxx b/Examples/BasicFilters/FrostImageFilter.cxx index 0b064fda6d0dc1659e769a1467d534eff4d90059..13d12674854981e964a32c70fe8d60756cbb9681 100644 --- a/Examples/BasicFilters/FrostImageFilter.cxx +++ b/Examples/BasicFilters/FrostImageFilter.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./FrostImageFilter Input/GomaSmall.png Output/GomaSmallFrostFiltered.png 5 0.1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {GomaSmall.png} -// OUTPUTS: {GomaSmallFrostFiltered.png} -// 5 0.1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{FrostImageFilter}. // This filter belongs to the family of the edge-preserving smoothing // filters which are usually used for speckle reduction in radar @@ -54,41 +50,31 @@ // will be highlighted. // // First, we need to include the header: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbFrostImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputImageFile radius deramp" << std::endl; return EXIT_FAILURE; - } + } - typedef unsigned char PixelType; + typedef unsigned char PixelType; - typedef otb::Image<PixelType, 2> InputImageType; - typedef otb::Image<PixelType, 2> OutputImageType; + typedef otb::Image<PixelType, 2> InputImageType; + typedef otb::Image<PixelType, 2> OutputImageType; - // Software Guide : BeginLatex - // // The filter can be instantiated using the image types defined previously. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::FrostImageFilter<InputImageType, OutputImageType> FilterType; - // Software Guide : EndCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; @@ -101,22 +87,14 @@ int main(int argc, char * argv[]) writer->SetInput(filter->GetOutput()); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the // \doxygen{otb}{FrostImageFilter}. // // \index{otb::FrostImageFilter!SetInput()} // \index{otb::FileImageReader!GetOutput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The method \code{SetRadius()} defines the size of the window to // be used for the computation of the local statistics. The method // \code{SetDeramp()} sets the $K$ coefficient. @@ -124,22 +102,17 @@ int main(int argc, char * argv[]) // \index{otb::FrostImageFilter!SetRadius()} // \index{otb::FrostImageFilter!SetDeramp()} // \index{SetDeramp()!otb::FrostImageFilter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FilterType::SizeType Radius; Radius[0] = atoi(argv[3]); Radius[1] = atoi(argv[3]); filter->SetRadius(Radius); filter->SetDeramp(atof(argv[4])); - // Software Guide : EndCodeSnippet writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:FROST_FILTER} shows the result of applying the Frost // filter to a SAR image. // \begin{figure} @@ -155,8 +128,6 @@ int main(int argc, char * argv[]) // \begin{itemize} // \item \doxygen{otb}{LeeImageFilter} // \end{itemize} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/HillShadingExample.cxx b/Examples/BasicFilters/HillShadingExample.cxx index a9b14bf42fb649579b9a5d403171ca9cd5df78d6..1d58ca2f68482dc62bdfe16e8fca5e4a9ce76668 100644 --- a/Examples/BasicFilters/HillShadingExample.cxx +++ b/Examples/BasicFilters/HillShadingExample.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./HillShadingExample Output/HillShadingExample.png Output/HillShadingColorExample.png 6.5 45.5 500 500 0.002 -0.002 Input/DEM_srtm +*/ -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {HillShadingExample.png}, {HillShadingColorExample.png} -// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Input/DEM_srtm -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // Visualization of digital elevation models (DEM) is often more intuitive by simulating a // lighting source and generating the corresponding shadows. This principle is called // hill shading. @@ -38,8 +35,6 @@ // \doxygen{otb}{ReliefColormapFunctor} you can easily generate the classic elevation maps. // // This example will focus on the shading itself. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -53,26 +48,25 @@ #include "itkShiftScaleImageFilter.h" #include "otbWorldFile.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 10) - { + { std::cout << argv[0] << " <output_filename> <output_color_filename> " << " <Longitude Output Origin point> <Latitude Output Origin point>" << " <X Output Size> <Y Output size>" << " <X Spacing> <Y Spacing> <DEM folder path>" - << " [Projection Ref]" - << std::endl; + << " [Projection Ref]" << std::endl; return EXIT_FAILURE; - } - - typedef double PixelType; - typedef unsigned char UCharPixelType; - typedef itk::RGBPixel<UCharPixelType> RGBPixelType; - typedef otb::Image<PixelType, 2> ImageType; - typedef otb::Image<RGBPixelType, 2> RGBImageType; - typedef otb::Image<UCharPixelType, 2> ScalarImageType; + } + + typedef double PixelType; + typedef unsigned char UCharPixelType; + typedef itk::RGBPixel<UCharPixelType> RGBPixelType; + typedef otb::Image<PixelType, 2> ImageType; + typedef otb::Image<RGBPixelType, 2> RGBImageType; + typedef otb::Image<UCharPixelType, 2> ScalarImageType; typedef otb::ImageFileWriter<RGBImageType> WriterType; typedef otb::ImageFileWriter<ScalarImageType> ScalarWriterType; @@ -86,9 +80,9 @@ int main(int argc, char * argv[]) DEMToImageGeneratorType::Pointer demToImage = DEMToImageGeneratorType::New(); - typedef DEMToImageGeneratorType::SizeType SizeType; - typedef DEMToImageGeneratorType::SpacingType SpacingType; - typedef DEMToImageGeneratorType::PointType PointType; + typedef DEMToImageGeneratorType::SizeType SizeType; + typedef DEMToImageGeneratorType::SpacingType SpacingType; + typedef DEMToImageGeneratorType::PointType PointType; otb::DEMHandler::Instance()->OpenDEMDirectory(argv[9]); @@ -111,69 +105,56 @@ int main(int argc, char * argv[]) demToImage->SetOutputSpacing(spacing); double res = 0; - if ( argc > 10) - { + if (argc > 10) + { demToImage->SetOutputProjectionRef(argv[10]); res = spacing[0]; - } + } else - { - //Compute the resolution (Vincenty formula) + { + // Compute the resolution (Vincenty formula) double lon1 = origin[0]; double lon2 = origin[0] + size[0] * spacing[0]; double lat1 = origin[1]; double lat2 = origin[1] + size[1] * spacing[1]; - double R = 6371; // km - double d = std::acos(std::sin(lat1) * std::sin(lat2) + - std::cos(lat1) * std::cos(lat2) * std::cos(lon2 - lon1)) * R; - res = d / std::sqrt(2.0); - } - // Software Guide : BeginLatex - // + double R = 6371; // km + double d = std::acos(std::sin(lat1) * std::sin(lat2) + std::cos(lat1) * std::cos(lat2) * std::cos(lon2 - lon1)) * R; + res = d / std::sqrt(2.0); + } // After generating the DEM image as in the DEMToImageGenerator example, you can declare // the hill shading mechanism. The hill shading is implemented as a functor doing some // operations in its neighborhood. A convenient filter called \doxygen{otb}{HillShadingFilter} // is defined around this mechanism. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::HillShadingFilter<ImageType, ImageType> HillShadingFilterType; - HillShadingFilterType::Pointer hillShading = HillShadingFilterType::New(); + HillShadingFilterType::Pointer hillShading = HillShadingFilterType::New(); hillShading->SetRadius(1); hillShading->SetInput(demToImage->GetOutput()); - // Software Guide : EndCodeSnippet hillShading->GetFunctor().SetXRes(res); hillShading->GetFunctor().SetYRes(res); typedef itk::ShiftScaleImageFilter<ImageType, ScalarImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetScale(255.0); rescaler->SetInput(hillShading->GetOutput()); writer->SetInput(rescaler->GetOutput()); - typedef itk::ScalarToRGBColormapImageFilter<ImageType, - RGBImageType> ColorMapFilterType; - ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); + typedef itk::ScalarToRGBColormapImageFilter<ImageType, RGBImageType> ColorMapFilterType; + ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); colormapper->UseInputImageExtremaForScalingOff(); - typedef otb::Functor::ReliefColormapFunctor<PixelType, - RGBPixelType> ColorMapFunctorType; - ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); + typedef otb::Functor::ReliefColormapFunctor<PixelType, RGBPixelType> ColorMapFunctorType; + ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New(); colormap->SetMinimumInputValue(0); colormap->SetMaximumInputValue(4000); colormapper->SetColormap(colormap); colormapper->SetInput(demToImage->GetOutput()); - typedef itk::BinaryFunctorImageFilter<RGBImageType, ImageType, RGBImageType, - otb::Functor:: - HillShadeModulationFunctor<RGBPixelType, - PixelType, - RGBPixelType> > - MultiplyFilterType; + typedef itk::BinaryFunctorImageFilter<RGBImageType, ImageType, RGBImageType, otb::Functor::HillShadeModulationFunctor<RGBPixelType, PixelType, RGBPixelType>> + MultiplyFilterType; MultiplyFilterType::Pointer multiply = MultiplyFilterType::New(); multiply->SetInput1(colormapper->GetOutput()); @@ -182,20 +163,20 @@ int main(int argc, char * argv[]) writer2->SetInput(multiply->GetOutput()); try - { + { writer->Update(); writer2->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } otb::WorldFile::Pointer worldFile = otb::WorldFile::New(); worldFile->SetLonOrigin(origin[0]); @@ -208,8 +189,6 @@ int main(int argc, char * argv[]) worldFile->SetImageFilename(argv[2]); worldFile->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:HILL_SHADING} shows the hill shading result from SRTM data. // // \begin{figure} @@ -220,7 +199,6 @@ int main(int argc, char * argv[]) // the color representation (right)} // \label{fig:HILL_SHADING} // \end{figure} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/IndexedToRGBExample.cxx b/Examples/BasicFilters/IndexedToRGBExample.cxx index 55d2e8a822d70803fbca6070a40449f65825cf77..adba63456d9ca821727c58f18b15b81477c563f0 100644 --- a/Examples/BasicFilters/IndexedToRGBExample.cxx +++ b/Examples/BasicFilters/IndexedToRGBExample.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./IndexedToRGBExample Input/buildingExtractionIndexed.tif Output/buildingExtractionRGB.png Output/buildingExtractionIndexed_scaled.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {buildingExtractionIndexed.tif} -// OUTPUTS: {buildingExtractionRGB.png}, {buildingExtractionIndexed_scaled.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // Some algorithms produce an indexed image as output. In such images, // each pixel is given a value according to the region number it belongs to. // This value starting at 0 or 1 is usually an integer value. @@ -39,8 +36,6 @@ // such conversion, it is important to ensure that neighborhood region, which are // likely to have consecutive number have easily dicernable colors. This is done // randomly using a hash function by the \doxygen{itk}{ScalarToRGBPixelFunctor}. -// -// Software Guide : EndLatex #include "otbImage.h" #include "otbImageFileReader.h" @@ -50,65 +45,55 @@ #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0] << " <inputImageFile> "; std::cerr << " <outputRGBImageFile> <outputScaledImageFile>" << std::endl; return EXIT_FAILURE; - } - const char * inputFilename = argv[1]; - const char * outputRGBFilename = argv[2]; - const char * outputScaledFilename = argv[3]; + } + const char* inputFilename = argv[1]; + const char* outputRGBFilename = argv[2]; + const char* outputScaledFilename = argv[3]; typedef otb::Image<unsigned long, 2> ImageType; typedef otb::Image<itk::RGBPixel<unsigned char>, 2> RGBImageType; typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFilename); - // Software Guide : BeginLatex - // // The \doxygen{itk}{UnaryFunctorImageFilter} is the filter in charge of // calling the functor we specify to do the work for each pixel. Here it is the // \doxygen{itk}{ScalarToRGBPixelFunctor}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> - ColorMapFunctorType; - typedef itk::UnaryFunctorImageFilter<ImageType, RGBImageType, - ColorMapFunctorType> ColorMapFilterType; - ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); + typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType; + typedef itk::UnaryFunctorImageFilter<ImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType; + ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); colormapper->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet typedef otb::ImageFileWriter<RGBImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputRGBFilename); writer->SetInput(colormapper->GetOutput()); writer->Update(); - //The following is just to produce the input image for the software guide - typedef otb::Image<unsigned char, 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + // The following is just to produce the input image for the software guide + typedef otb::Image<unsigned char, 2> OutputImageType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetInput(reader->GetOutput()); typedef otb::ImageFileWriter<OutputImageType> UCharWriterType; - UCharWriterType::Pointer writer2 = UCharWriterType::New(); + UCharWriterType::Pointer writer2 = UCharWriterType::New(); writer2->SetFileName(outputScaledFilename); writer2->SetInput(rescaler->GetOutput()); writer2->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:INDEXTORGB_FILTER} shows the result of the conversion // from an indexed image to a color image. // \begin{figure} @@ -119,8 +104,6 @@ int main(int argc, char * argv[]) // conversion to color image.} // \label{fig:INDEXTORGB_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/LeeImageFilter.cxx b/Examples/BasicFilters/LeeImageFilter.cxx index 803bb7901090e56620f962969c9001661340d834..fee4c62c8772beb4c285aa855faaca4dcbc88579 100644 --- a/Examples/BasicFilters/LeeImageFilter.cxx +++ b/Examples/BasicFilters/LeeImageFilter.cxx @@ -19,171 +19,66 @@ */ +/* Example usage: +./LeeImageFilter Input/GomaSmall.png Output/GomaSmallLeeFiltered.png 3 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {GomaSmall.png} -// OUTPUTS: {GomaSmallLeeFiltered.png} -// 3 1 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// -// This example illustrates the use of the \doxygen{otb}{LeeImageFilter}. -// This filter belongs to the family of the edge-preserving smoothing -// filters which are usually used for speckle reduction in radar -// images. The Lee filter \cite{LeeFilter} aplies a linear regression -// which minimizes the mean-square error in the frame of a -// multiplicative speckle model. -// -// -// The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet #include "otbLeeImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { - if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputImageFile radius NbLooks" << std::endl; return EXIT_FAILURE; - } - - // Software Guide : BeginLatex - // - // Then we must decide what pixel type to use for the image. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef unsigned char PixelType; - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // The images are defined using the pixel type and the dimension. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::Image<PixelType, 2> InputImageType; - typedef otb::Image<PixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // The filter can be instantiated using the image types defined above. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet + } + + typedef unsigned char PixelType; + + // The images are defined using the pixel type and the dimension. + typedef otb::Image<PixelType, 2> InputImageType; + typedef otb::Image<PixelType, 2> OutputImageType; + + // The filter can be instantiated using the image types defined above. typedef otb::LeeImageFilter<InputImageType, OutputImageType> FilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read + // An ImageFileReader class is also instantiated in order to read // image data from a file. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the // output image to a file. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Both the filter and the reader are created by invoking their \code{New()} // methods and assigning the result to SmartPointers. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetInput(filter->GetOutput()); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the - // \doxygen{otb}{LeeImageFilter}. - // - // \index{otb::LeeImageFilter!SetInput()} - // \index{otb::FileImageReader!GetOutput()} - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet + // LeeImageFilter. filter->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // The method \code{SetRadius()} defines the size of the window to - // be used for the computation of the local statistics. The method - // \code{SetNbLooks()} sets the number of looks of the input - // image. - // - // \index{otb::LeeImageFilter!SetRadius()} - // \index{otb::LeeImageFilter!SetNbLooks()} - // \index{SetNbLooks()!otb::LeeImageFilter} - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet + + // The method SetRadius() defines the size of the window to + // be used for the computation of the local statistics. The method + // SetNbLooks() sets the number of looks of the input + // image. FilterType::SizeType Radius; Radius[0] = atoi(argv[3]); Radius[1] = atoi(argv[3]); filter->SetRadius(Radius); filter->SetNbLooks(atoi(argv[4])); - // Software Guide : EndCodeSnippet writer->SetFileName(argv[2]); writer->Update(); - - // Software Guide : BeginLatex - // Figure~\ref{fig:LEE_FILTER} shows the result of applying the Lee - // filter to a SAR image. - // \begin{figure} - // \center - // \includegraphics[width=0.44\textwidth]{GomaSmall.eps} - // \includegraphics[width=0.44\textwidth]{GomaSmallLeeFiltered.eps} - // \itkcaption[Lee Filter Application]{Result of applying the - // \doxygen{otb}{LeeImageFilter} to a SAR image.} - // \label{fig:LEE_FILTER} - // \end{figure} - // - // \relatedClasses - // \begin{itemize} - // \item \doxygen{otb}{FrostImageFilter} - // \end{itemize} - // - // Software Guide : EndLatex - - return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/LeeImageFilter.rst b/Examples/BasicFilters/LeeImageFilter.rst new file mode 100644 index 0000000000000000000000000000000000000000..bb34942a9ec560a722e01b71309dc570862d30b1 --- /dev/null +++ b/Examples/BasicFilters/LeeImageFilter.rst @@ -0,0 +1,12 @@ +This example illustrates the use of the LeeImageFilter. +This filter belongs to the family of the edge-preserving smoothing +filters which are usually used for speckle reduction in radar +images. The LeeFilter aplies a linear regression +which minimizes the mean-square error in the frame of a +multiplicative speckle model. + +.. figure:: /Input/GomaSmall.png + +.. figure:: /Output/GomaSmallLeeFiltered.png + + Result of applying the Lee filter to a SAR image. diff --git a/Examples/BasicFilters/MeanShiftSegmentationFilterExample.cxx b/Examples/BasicFilters/MeanShiftSegmentationFilterExample.cxx index 78396188f347adb7c37204f137cce9eb61a86d63..f3992ead4089875bee8132029e4278585e214d66 100644 --- a/Examples/BasicFilters/MeanShiftSegmentationFilterExample.cxx +++ b/Examples/BasicFilters/MeanShiftSegmentationFilterExample.cxx @@ -19,15 +19,20 @@ */ +/* Example usage: +./MeanShiftSegmentationFilterExample Input/ROI_QB_MUL_1.png \ + Output/MSLabeledOutput.tif \ + Output/MSClusteredOutput.tif \ + Output/MSLabeledOutput-pretty.png \ + Output/MSClusteredOutput-pretty.png \ + 16 \ + 16 \ + 100 \ + 100 \ + 0.1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1.png} -// OUTPUTS: {MSLabeledOutput.tif}, {MSClusteredOutput.tif}, {MSLabeledOutput-pretty.png}, {MSClusteredOutput-pretty.png} -// 16 16 100 100 0.1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example demonstrates the use of the // \doxygen{otb}{MeanShiftSegmentationFilter} class which implements // filtering and clustering using the mean shift algorithm @@ -37,8 +42,6 @@ // then computed and the algorithm iterates with this new spatial and // color center. The Mean Shift can be used for edge-preserving // smoothing, or for clustering. -// -// Software Guide : EndLatex #include "otbVectorImage.h" #include "otbImageFileReader.h" @@ -49,43 +52,32 @@ #include "itkScalarToRGBPixelFunctor.h" #include "itkUnaryFunctorImageFilter.h" -// Software Guide : BeginLatex -// // We start by including the needed header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMeanShiftSegmentationFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 11) - { + { std::cerr << "Usage: " << argv[0] << " infname labeledfname clusteredfname labeledpretty clusteredpretty " - << "spatialRadius rangeRadius minRegionSize maxiter thres" << std::endl; + << "spatialRadius rangeRadius minRegionSize maxiter thres" << std::endl; return EXIT_FAILURE; - } - - const char * infname = argv[1]; - const char * labeledfname = argv[2]; - const char * clusteredfname = argv[3]; - const char * labeledpretty = argv[4]; - const char * clusteredpretty = argv[5]; - const unsigned int spatialRadius = atoi(argv[6]); - const double rangeRadius = atof(argv[7]); - const unsigned int minRegionSize = atoi(argv[8]); - const unsigned int maxiter = atoi(argv[9]); - const double thres = atof(argv[10]); - - // Software Guide : BeginLatex - // + } + + const char* infname = argv[1]; + const char* labeledfname = argv[2]; + const char* clusteredfname = argv[3]; + const char* labeledpretty = argv[4]; + const char* clusteredpretty = argv[5]; + const unsigned int spatialRadius = atoi(argv[6]); + const double rangeRadius = atof(argv[7]); + const unsigned int minRegionSize = atoi(argv[8]); + const unsigned int maxiter = atoi(argv[9]); + const double thres = atof(argv[10]); + // We start by the classical \code{typedef}s needed for reading and // writing the images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef float PixelType; @@ -96,80 +88,50 @@ int main(int argc, char * argv[]) typedef otb::Image<LabelPixelType, Dimension> LabelImageType; typedef otb::Image<ColorPixelType, Dimension> RGBImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; typedef otb::ImageFileWriter<LabelImageType> LabelWriterType; typedef otb::MeanShiftSegmentationFilter<ImageType, LabelImageType, ImageType> FilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We instantiate the filter, the reader, and 2 writers (for the // labeled and clustered images). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - FilterType::Pointer filter = FilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer1 = WriterType::New(); + FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer1 = WriterType::New(); LabelWriterType::Pointer writer2 = LabelWriterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We set the file names for the reader and the writers: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(infname); writer1->SetFileName(clusteredfname); writer2->SetFileName(labeledfname); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now set the parameters for the filter. There are 3 main // parameters: the spatial radius used for defining the neighborhood, // the range radius used for defining the interval in the color space // and the minimum size for the regions to be kept after clustering. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetSpatialBandwidth(spatialRadius); filter->SetRangeBandwidth(rangeRadius); filter->SetMinRegionSize(minRegionSize); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Two another parameters can be set : the maximum iteration number, which defines maximum number of iteration until convergence. // Algorithm iterative scheme will stop if convergence hasn't been reached after the maximum number of iterations. - // Threshold parameter defines mean-shift vector convergence value. Algorithm iterative scheme will stop if mean-shift vector is below this threshold or if iteration number reached maximum number of iterations. - // Software Guide : EndLatex + // Threshold parameter defines mean-shift vector convergence value. Algorithm iterative scheme will stop if mean-shift vector is below this threshold or if + // iteration number reached maximum number of iterations. - // Software Guide : BeginCodeSnippet filter->SetMaxIterationNumber(maxiter); filter->SetThreshold(thres); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now plug the pipeline and run it. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer1->SetInput(filter->GetClusteredOutput()); writer2->SetInput(filter->GetLabelOutput()); writer1->Update(); writer2->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:MeanShiftSegmentationFilter} shows the result of applying the mean shift // to a Quickbird image. // \begin{figure} @@ -182,16 +144,15 @@ int main(int argc, char * argv[]) // mean shift after clustering , and labeled image.} // \label{fig:MeanShiftSegmentationFilter} // \end{figure} - // Software Guide : EndLatex typedef otb::PrintableImageFilter<ImageType> PrintableFilterType; - PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New(); + PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New(); printableImageFilter->SetChannel(1); printableImageFilter->SetChannel(2); printableImageFilter->SetChannel(3); - typedef PrintableFilterType::OutputImageType OutputImageType; + typedef PrintableFilterType::OutputImageType OutputImageType; typedef otb::ImageFileWriter<OutputImageType> PrettyWriterType; PrettyWriterType::Pointer prettyWriter = PrettyWriterType::New(); @@ -206,9 +167,9 @@ int main(int argc, char * argv[]) LabelRGBWriterType::Pointer labelRGBWriter = LabelRGBWriterType::New(); // Label to RGB image - typedef itk::Functor::ScalarToRGBPixelFunctor<LabelPixelType> FunctorType; + typedef itk::Functor::ScalarToRGBPixelFunctor<LabelPixelType> FunctorType; typedef itk::UnaryFunctorImageFilter<LabelImageType, RGBImageType, FunctorType> ColorLabelFilterType; - ColorLabelFilterType::Pointer labelToRGB = ColorLabelFilterType::New(); + ColorLabelFilterType::Pointer labelToRGB = ColorLabelFilterType::New(); labelToRGB->SetInput(filter->GetLabelOutput()); diff --git a/Examples/BasicFilters/PrintableImageFilterExample.cxx b/Examples/BasicFilters/PrintableImageFilterExample.cxx index 0e6a01b36a54d5a64fd15c3c1bde75b73b0ebea3..abe40efdbbb6d00a6e6009e7296ddb5882feb802 100644 --- a/Examples/BasicFilters/PrintableImageFilterExample.cxx +++ b/Examples/BasicFilters/PrintableImageFilterExample.cxx @@ -19,21 +19,16 @@ */ +/* Example usage: +./PrintableImageFilterExample Input/IMAGERY_SSECH.tif Output/PrintableExampleOutput1.jpg 1 2 3 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {IMAGERY_SSECH.tif} -// OUTPUTS: {PrintableExampleOutput1.jpg} -// 1 2 3 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {IMAGERY_SSECH.tif} -// OUTPUTS: {PrintableExampleOutput2.jpg} -// 1 4 2 -// Software Guide : EndCommandLineArgs +/* Example usage: +./PrintableImageFilterExample Input/IMAGERY_SSECH.tif Output/PrintableExampleOutput2.jpg 1 4 2 +*/ + -// Software Guide : BeginLatex -// // Most of the time, satellite images have more than three spectral bands. As we // are only able to see three colors (red, green and blue), we have to find a way to // represent these images using only three bands. This is called creating a color @@ -57,32 +52,29 @@ // have to be careful to reverse the order if you want a natural display. It could also be reverse // to facilitate direct viewing, as for SPOT5 (1: NIR, 2: Red, 3: Green, 4: SWIR) but in this situations // you have to be careful when you process the image. -// -// Software Guide : EndLatex #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << argv[0] << " <inputImageFile> "; - std::cerr << " <outputImageFile> <RedBand> <GreenBand> <BlueBand>" << - std::endl; + std::cerr << " <outputImageFile> <RedBand> <GreenBand> <BlueBand>" << std::endl; return EXIT_FAILURE; - } + } - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; - int redChannelNumber = atoi(argv[3]); - int greenChannelNumber = atoi(argv[4]); - int blueChannelNumber = atoi(argv[5]); + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; + int redChannelNumber = atoi(argv[3]); + int greenChannelNumber = atoi(argv[4]); + int blueChannelNumber = atoi(argv[5]); - typedef double InputPixelType; + typedef double InputPixelType; const unsigned int Dimension = 2; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; @@ -92,34 +84,22 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFilename); - // Software Guide : BeginLatex - // // To easily convert the image to a {\em printable} format, i.e. 3 bands // \code{unsigned char} value, you can use the \doxygen{otb}{PrintableImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::PrintableImageFilter<InputImageType> PrintableFilterType; - PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New(); + PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New(); printableImageFilter->SetInput(reader->GetOutput()); printableImageFilter->SetChannel(redChannelNumber); printableImageFilter->SetChannel(greenChannelNumber); printableImageFilter->SetChannel(blueChannelNumber); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // When you create the writer to plug at the output of the \code{printableImageFilter} // you may want to use the direct type definition as it is a good way to avoid mismatch: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef PrintableFilterType::OutputImageType OutputImageType; + typedef PrintableFilterType::OutputImageType OutputImageType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); @@ -127,7 +107,6 @@ int main(int argc, char * argv[]) writer->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:PRINTABLE_FILTER} illustrates different color compositions for a SPOT 5 image. // \begin{figure} // \center @@ -138,8 +117,6 @@ int main(int argc, char * argv[]) // right another composition: XS3 in red, XS4 in green and XS2 in blue.} // \label{fig:PRINTABLE_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/BasicFilters/ScalingFilterExample.cxx b/Examples/BasicFilters/ScalingFilterExample.cxx index 37cf9dd7913fb430ef69791519195219c166ed83..174fa6699ca6a13dfd88f1d28c79e03ca960d1b5 100644 --- a/Examples/BasicFilters/ScalingFilterExample.cxx +++ b/Examples/BasicFilters/ScalingFilterExample.cxx @@ -19,21 +19,16 @@ */ +/* Example usage: +./ScalingFilterExample Input/QB_Toulouse_Ortho_PAN.tif Output/QB_Toulouse_Ortho_PAN_rescaled.png Output/QB_Toulouse_Ortho_PAN_casted.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Toulouse_Ortho_PAN.tif} -// OUTPUTS: {QB_Toulouse_Ortho_PAN_rescaled.png}, {QB_Toulouse_Ortho_PAN_casted.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // On one hand, satellite images are commonly coded on more than 8 bits to provide // the dynamic range required from shadows to clouds. On the other hand, image formats // in use for printing and display are usually limited to 8 bits. We need to convert the value // to enable a proper display. This is usually done using linear scaling. Of course, you have // to be aware that some information is lost in the process. -// -// Software Guide : EndLatex #include "otbImage.h" #include "otbImageFileReader.h" @@ -42,54 +37,45 @@ #include "itkRescaleIntensityImageFilter.h" #include "itkCastImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0] << " <inputImageFile> "; - std::cerr << " <outputRescaledImageFile> <outputCastedImageFile>" << - std::endl; + std::cerr << " <outputRescaledImageFile> <outputCastedImageFile>" << std::endl; return EXIT_FAILURE; - } + } - typedef unsigned short InputPixelType; - typedef unsigned char OutputPixelType; + typedef unsigned short InputPixelType; + typedef unsigned char OutputPixelType; typedef otb::Image<InputPixelType, 2> InputImageType; typedef otb::Image<OutputPixelType, 2> OutputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \doxygen{itk}{RescaleIntensityImageFilter} is used to rescale the value: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InputImageType, - OutputImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> RescalerType; + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); writer->Update(); typedef itk::CastImageFilter<InputImageType, OutputImageType> CasterType; - CasterType::Pointer caster = CasterType::New(); + CasterType::Pointer caster = CasterType::New(); caster->SetInput(reader->GetOutput()); writer->SetFileName(argv[3]); writer->SetInput(caster->GetOutput()); writer->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:SCALING_FILTER} illustrates the difference between a proper scaling and // a simple truncation of the value and demonstrates why it is // important to keep this in mind. @@ -103,8 +89,6 @@ int main(int argc, char * argv[]) // a proper rescaling} // \label{fig:SCALING_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/ChangeDetection/CorrelChDet.cxx b/Examples/ChangeDetection/CorrelChDet.cxx index 88655cfe1670a0f263330f15be0bf3a637789b76..7c2b4773384fa9bcd9cb85d2725da329bf6bf166 100644 --- a/Examples/ChangeDetection/CorrelChDet.cxx +++ b/Examples/ChangeDetection/CorrelChDet.cxx @@ -25,13 +25,11 @@ #include "itkShiftScaleImageFilter.h" #include "otbCommandProgressUpdate.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ERSBefore.png}, {ERSAfter.png} -// OUTPUTS: {CorrChDet.tif} -// 15 -// Software Guide : EndCommandLineArgs +/* Example usage: +./CorrelChDet Input/ERSBefore.png Input/ERSAfter.png Output/CorrChDet.tif 15 +*/ + -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{CorrelationChangeDetector} for detecting changes // between pairs of images. This filter computes the correlation coefficient in @@ -48,183 +46,119 @@ // \end{figure} // // We start by including the corresponding header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbCorrelationChangeDetector.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc < 5) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile1 inputImageFile2 " << "outputImageFile radius" << std::endl; return -1; - } + } // Define the dimension of the images const unsigned int Dimension = 2; - // Software Guide : BeginLatex // We start by declaring the types for the two input images, the // change image and the image to be stored in a file for visualization. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef float InternalPixelType; typedef unsigned char OutputPixelType; typedef otb::Image<InternalPixelType, Dimension> InputImageType1; typedef otb::Image<InternalPixelType, Dimension> InputImageType2; typedef otb::Image<InternalPixelType, Dimension> ChangeImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now declare the types for the readers. Since the images // can be vey large, we will force the pipeline to use // streaming. For this purpose, the file writer will be // streamed. This is achieved by using the // \doxygen{otb}{ImageFileWriter} class. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader<InputImageType1> ReaderType1; - typedef otb::ImageFileReader<InputImageType2> ReaderType2; + typedef otb::ImageFileReader<InputImageType1> ReaderType1; + typedef otb::ImageFileReader<InputImageType2> ReaderType2; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The change detector will give a response which is normalized // between 0 and 1. Before // saving the image to a file in, for instance, PNG format, we will // rescale the results of the change detection in order to use all // the output pixel type range of values. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::ShiftScaleImageFilter<ChangeImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::ShiftScaleImageFilter<ChangeImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // The \doxygen{otb}{CorrelationChangeDetector} is templated over // the types of the two input images and the type of the generated change // image. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::CorrelationChangeDetector< - InputImageType1, - InputImageType2, - ChangeImageType> FilterType; - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::CorrelationChangeDetector<InputImageType1, InputImageType2, ChangeImageType> FilterType; + // The different elements of the pipeline can now be instantiated. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - ReaderType1::Pointer reader1 = ReaderType1::New(); - ReaderType2::Pointer reader2 = ReaderType2::New(); - WriterType::Pointer writer = WriterType::New(); - FilterType::Pointer filter = FilterType::New(); - RescalerType::Pointer rescaler = RescalerType::New(); - // Software Guide : EndCodeSnippet - const char * inputFilename1 = argv[1]; - const char * inputFilename2 = argv[2]; - const char * outputFilename = argv[3]; - // Software Guide : BeginLatex - // + + ReaderType1::Pointer reader1 = ReaderType1::New(); + ReaderType2::Pointer reader2 = ReaderType2::New(); + WriterType::Pointer writer = WriterType::New(); + FilterType::Pointer filter = FilterType::New(); + RescalerType::Pointer rescaler = RescalerType::New(); + const char* inputFilename1 = argv[1]; + const char* inputFilename2 = argv[2]; + const char* outputFilename = argv[3]; // We set the parameters of the different elements of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader1->SetFileName(inputFilename1); reader2->SetFileName(inputFilename2); writer->SetFileName(outputFilename); float scale = itk::NumericTraits<OutputPixelType>::max(); rescaler->SetScale(scale); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The only parameter for this change detector is the radius of // the window used for computing the correlation coefficient. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetRadius(atoi(argv[4])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We build the pipeline by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput1(reader1->GetOutput()); filter->SetInput2(reader2->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Since the processing time of large images can be long, it is // interesting to monitor the evolution of the computation. In // order to do so, the change detectors can use the // command/observer design pattern. This is easily done by // attaching an observer to the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::CommandProgressUpdate<FilterType> CommandType; CommandType::Pointer observer = CommandType::New(); filter->AddObserver(itk::ProgressEvent(), observer); - // Software Guide : EndCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } - -// Software Guide : BeginLatex -// Figure \ref{fig:RESCORRCHDET} shows the result of the change -// detection by local correlation. -// \begin{figure} -// \center -// \includegraphics[width=0.35\textwidth]{CorrChDet.eps} -// \itkcaption[Correlation Change Detection Results]{Result of the -// correlation change detector} -// \label{fig:RESCORRCHDET} -// \end{figure} -// Software Guide : EndLatex + } + + // Figure \ref{fig:RESCORRCHDET} shows the result of the change + // detection by local correlation. + // \begin{figure} + // \center + // \includegraphics[width=0.35\textwidth]{CorrChDet.eps} + // \itkcaption[Correlation Change Detection Results]{Result of the + // correlation change detector} + // \label{fig:RESCORRCHDET} + // \end{figure} return EXIT_SUCCESS; - } diff --git a/Examples/ChangeDetection/DiffChDet.cxx b/Examples/ChangeDetection/DiffChDet.cxx index 2a31323a264d2c0f73eda11495864d65fc9fd034..f28fc422fd89415e40ca9c15f826d4ad1cb492b5 100644 --- a/Examples/ChangeDetection/DiffChDet.cxx +++ b/Examples/ChangeDetection/DiffChDet.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./DiffChDet Input/SpotBefore.png Input/SpotAfter.png Output/DiffChDet.tif 3 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {SpotBefore.png}, {SpotAfter.png} -// OUTPUTS: {DiffChDet.tif} -// 3 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{MeanDifferenceImageFilter} for detecting changes // between pairs of images. This filter computes the mean intensity in @@ -45,12 +42,8 @@ // \end{figure} // // We start by including the corresponding header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMeanDifferenceImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -65,23 +58,18 @@ int main(int argc, char* argv[]) { if (argc < 5) - { + { std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] << - " inputImageFile1 inputImageFile2 outputImageFile radius" << std::endl; + std::cerr << argv[0] << " inputImageFile1 inputImageFile2 outputImageFile radius" << std::endl; return -1; - } + } // Define the dimension of the images const unsigned int Dimension = 2; - // Software Guide : BeginLatex // We start by declaring the types for the two input images, the // change image and the image to be stored in a file for visualization. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef float InternalPixelType; typedef unsigned char OutputPixelType; typedef otb::Image<InternalPixelType, Dimension> InputImageType1; @@ -89,22 +77,13 @@ int main(int argc, char* argv[]) typedef otb::Image<InternalPixelType, Dimension> ChangeImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now declare the types for the readers and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType1> ReaderType1; typedef otb::ImageFileReader<InputImageType2> ReaderType2; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The change detector will give positive and negative values // depending on the sign of the difference. We are usually // interested only in the absolute value of the difference. For @@ -112,129 +91,81 @@ int main(int argc, char* argv[]) // saving the image to a file in, for instance, PNG format, we will // rescale the results of the change detection in order to use the full range // of values of the output pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::AbsImageFilter<ChangeImageType, - ChangeImageType> AbsType; - typedef itk::RescaleIntensityImageFilter<ChangeImageType, - OutputImageType> RescalerType; + typedef itk::AbsImageFilter<ChangeImageType, ChangeImageType> AbsType; + typedef itk::RescaleIntensityImageFilter<ChangeImageType, OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{MeanDifferenceImageFilter} is templated over // the types of the two input images and the type of the generated change // image. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::MeanDifferenceImageFilter< - InputImageType1, - InputImageType2, - ChangeImageType> FilterType; - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::MeanDifferenceImageFilter<InputImageType1, InputImageType2, ChangeImageType> FilterType; + // The different elements of the pipeline can now be instantiated. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - ReaderType1::Pointer reader1 = ReaderType1::New(); - ReaderType2::Pointer reader2 = ReaderType2::New(); - WriterType::Pointer writer = WriterType::New(); - FilterType::Pointer filter = FilterType::New(); + + ReaderType1::Pointer reader1 = ReaderType1::New(); + ReaderType2::Pointer reader2 = ReaderType2::New(); + WriterType::Pointer writer = WriterType::New(); + FilterType::Pointer filter = FilterType::New(); AbsType::Pointer absFilter = AbsType::New(); - RescalerType::Pointer rescaler = RescalerType::New(); - // Software Guide : EndCodeSnippet + RescalerType::Pointer rescaler = RescalerType::New(); - const char * inputFilename1 = argv[1]; - const char * inputFilename2 = argv[2]; - const char * outputFilename = argv[3]; + const char* inputFilename1 = argv[1]; + const char* inputFilename2 = argv[2]; + const char* outputFilename = argv[3]; - // Software Guide : BeginLatex - // // We set the parameters of the different elements of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader1->SetFileName(inputFilename1); reader2->SetFileName(inputFilename2); writer->SetFileName(outputFilename); rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The only parameter for this change detector is the radius of // the window used for computing the mean of the intensities. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetRadius(atoi(argv[4])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We build the pipeline by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput1(reader1->GetOutput()); filter->SetInput2(reader2->GetOutput()); absFilter->SetInput(filter->GetOutput()); rescaler->SetInput(absFilter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Since the processing time of large images can be long, it is // interesting to monitor the evolution of the computation. In // order to do so, the change detectors can use the // command/observer design pattern. This is easily done by // attaching an observer to the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::CommandProgressUpdate<FilterType> CommandType; CommandType::Pointer observer = CommandType::New(); filter->AddObserver(itk::ProgressEvent(), observer); - // Software Guide : EndCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } -// Software Guide : BeginLatex -// Figure \ref{fig:RESDIFFCHDET} shows the result of the change -// detection by difference of local means. -// \begin{figure} -// \center -// \includegraphics[width=0.35\textwidth]{DiffChDet.eps} -// \itkcaption[Difference Change Detection Results]{Result of the mean -// difference change detector} -// \label{fig:RESDIFFCHDET} -// \end{figure} -// Software Guide : EndLatex + } + // Figure \ref{fig:RESDIFFCHDET} shows the result of the change + // detection by difference of local means. + // \begin{figure} + // \center + // \includegraphics[width=0.35\textwidth]{DiffChDet.eps} + // \itkcaption[Difference Change Detection Results]{Result of the mean + // difference change detector} + // \label{fig:RESDIFFCHDET} + // \end{figure} return EXIT_SUCCESS; - } diff --git a/Examples/ChangeDetection/KullbackLeiblerDistanceChDet.cxx b/Examples/ChangeDetection/KullbackLeiblerDistanceChDet.cxx index f5ea21f2459ccdebae5db2d4c42647e89d99427e..e60b6c1b80bf5a27d3896ec94bbc7dbf785e6e33 100644 --- a/Examples/ChangeDetection/KullbackLeiblerDistanceChDet.cxx +++ b/Examples/ChangeDetection/KullbackLeiblerDistanceChDet.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {GomaAvant.png}, {GomaApres.png} -// OUTPUTS: {KLdistanceChDet.png} -// 35 -// Software Guide : EndCommandLineArgs +/* Example usage: +./KullbackLeiblerDistanceChDet Input/GomaAvant.png Input/GomaApres.png Output/KLdistanceChDet.png 35 +*/ + -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{KullbackLeiblerDistanceImageFilter} for detecting changes // between pairs of images. This filter computes the Kullback-Leibler @@ -74,8 +72,6 @@ // implemented in \doxygen{otb}{MeanRatioImageFilter}, // in section~\ref{sec:RatioOfMeans}. Nevertheless // the corresponding header file has to be used instead. -// -// Software Guide : EndLatex #include "itkMacro.h" #include "otbImage.h" @@ -84,59 +80,43 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCodeSnippet #include "otbKullbackLeiblerDistanceImageFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { try - { + { if (argc != 5) - { - std::cerr << - "Change detection through a Kullback-Leibler measure (which is a distance between local distributions)\n"; - std::cerr << - "Kullback-Leibler measure is optimized by a Edgeworth series expansion\n"; + { + std::cerr << "Change detection through a Kullback-Leibler measure (which is a distance between local distributions)\n"; + std::cerr << "Kullback-Leibler measure is optimized by a Edgeworth series expansion\n"; std::cerr << argv[0] << " imgAv imgAp imgResu winSize\n"; return 1; - } + } - char * fileName1 = argv[1]; - char * fileName2 = argv[2]; - char * fileNameOut = argv[3]; - int winSize = atoi(argv[4]); + char* fileName1 = argv[1]; + char* fileName2 = argv[2]; + char* fileNameOut = argv[3]; + int winSize = atoi(argv[4]); - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double PixelType; typedef unsigned char OutputPixelType; typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : BeginLatex - // // The \doxygen{otb}{KullbackLeiblerDistanceImageFilter} is templated over // the types of the two input images and the type of the generated change // image, in a similar way as the \doxygen{otb}{MeanRatioImageFilter}. It is // the only line to be changed from the ratio of means change detection // example to perform a change detection through a distance between // distributions... - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::KullbackLeiblerDistanceImageFilter<ImageType, - ImageType, - ImageType> FilterType; - // Software Guide : EndCodeSnippet + typedef otb::KullbackLeiblerDistanceImageFilter<ImageType, ImageType, ImageType> FilterType; - // Software Guide : BeginLatex - // // The different elements of the pipeline can now be instantiated. Follow the // ratio of means change detector example. - // - // Software Guide : EndLatex typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; @@ -147,32 +127,19 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader2 = ReaderType::New(); reader2->SetFileName(fileName2); - // Software Guide : BeginLatex - // // The only parameter for this change detector is the radius of // the window used for computing the cumulants. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FilterType::Pointer filter = FilterType::New(); filter->SetRadius((winSize - 1) / 2); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The pipeline is built by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput1(reader1->GetOutput()); filter->SetInput2(reader2->GetOutput()); - // Software Guide : EndCodeSnippet - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescaleFilterType; - RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescaleFilterType; + RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); rescaler->SetInput(filter->GetOutput()); rescaler->SetOutputMinimum(0); @@ -182,23 +149,21 @@ int main(int argc, char * argv[]) writer->SetFileName(fileNameOut); writer->SetInput(rescaler->GetOutput()); writer->Update(); - - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; std::cout << err << std::endl; return EXIT_FAILURE; - } + } catch (...) - { + { std::cout << "Unknown exception thrown !" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex // Figure \ref{fig:RESKLDCHDET} shows the result of the change // detection by computing the Kullback-Leibler distance between // local pdf through an Edgeworth approximation. @@ -209,7 +174,6 @@ int main(int argc, char * argv[]) // Kullback-Leibler change detector} // \label{fig:RESKLDCHDET} // \end{figure} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/ChangeDetection/KullbackLeiblerProfileChDet.cxx b/Examples/ChangeDetection/KullbackLeiblerProfileChDet.cxx index 7f89db9ea1bfda70159890443116d07f73d08a51..2ec5e68636b69367b6e8d7a9609ff6a5ac5f17ef 100644 --- a/Examples/ChangeDetection/KullbackLeiblerProfileChDet.cxx +++ b/Examples/ChangeDetection/KullbackLeiblerProfileChDet.cxx @@ -19,14 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {GomaAvant.png}, {GomaApres.png} -// OUTPUTS: {KLProfileChDet.png} -// 5 51 1 12 24 -// Software Guide : EndCommandLineArgs +/* Example usage: +./KullbackLeiblerProfileChDet Input/GomaAvant.png Input/GomaApres.png Output/KLProfileChDet.png 5 51 1 12 24 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the class // \doxygen{otb}{KullbackLeiblerProfileImageFilter} for detecting changes // between pairs of images, according to a range of window size. @@ -42,75 +39,53 @@ // Then, the program begins with the \doxygen{otb}{VectorImage} and the // \doxygen{otb}{KullbackLeiblerProfileImageFilter} header files in addition // to those already details in the \doxygen{otb}{MeanRatioImageFilter} example. -// -// Software Guide : EndLatex #include "otbImage.h" #include "otbMultiChannelExtractROI.h" #include "otbVectorRescaleIntensityImageFilter.h" -// Software Guide : BeginCodeSnippet #include "otbKullbackLeiblerProfileImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { try - { + { if (argc != 9) - { - std::cerr << - "Change detection based on Kullback-Leibler distance betweenlocal pdf through an Edgeworth approximation\n"; - std::cerr << argv[0] << - " imgAv imgAp imgResu winSizeMin winSizeMax outRedIndex outGreenIndex outBlueIndex\n"; + { + std::cerr << "Change detection based on Kullback-Leibler distance betweenlocal pdf through an Edgeworth approximation\n"; + std::cerr << argv[0] << " imgAv imgAp imgResu winSizeMin winSizeMax outRedIndex outGreenIndex outBlueIndex\n"; return 1; - } - - char * fileName1 = argv[1]; - char * fileName2 = argv[2]; - char * fileNameOut = argv[3]; - int winSizeMin = atoi(argv[4]); - int winSizeMax = atoi(argv[5]); - unsigned int ri = atoi(argv[6]); - unsigned int gi = atoi(argv[7]); - unsigned int bi = atoi(argv[8]); - - const unsigned int Dimension = 2; + } + + char* fileName1 = argv[1]; + char* fileName2 = argv[2]; + char* fileNameOut = argv[3]; + int winSizeMin = atoi(argv[4]); + int winSizeMax = atoi(argv[5]); + unsigned int ri = atoi(argv[6]); + unsigned int gi = atoi(argv[7]); + unsigned int bi = atoi(argv[8]); + + const unsigned int Dimension = 2; typedef double PixelType; typedef unsigned char OutPixelType; - // Software Guide : BeginLatex - // // The \doxygen{otb}{KullbackLeiblerProfileImageFilter} is templated over // the types of the two input images and the type of the generated change // image (which is now of multi-components), in a similar way as the // \doxygen{otb}{KullbackLeiblerDistanceImageFilter}. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::Image<PixelType, Dimension> ImageType; - typedef otb::VectorImage<PixelType, Dimension> VectorImageType; - typedef otb::KullbackLeiblerProfileImageFilter<ImageType, - ImageType, - VectorImageType> FilterType; - // Software Guide : EndCodeSnippet - - typedef otb::VectorImage<OutPixelType, - Dimension> - OutVectorImageType; - typedef otb::ImageFileReader<ImageType> - ReaderType; - typedef otb::ImageFileWriter<OutVectorImageType> - WriterType; - typedef otb::MultiChannelExtractROI<PixelType, - PixelType> - ChannelSelecterType; - typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, - OutVectorImageType> - RescalerType; + + typedef otb::Image<PixelType, Dimension> ImageType; + typedef otb::VectorImage<PixelType, Dimension> VectorImageType; + typedef otb::KullbackLeiblerProfileImageFilter<ImageType, ImageType, VectorImageType> FilterType; + + typedef otb::VectorImage<OutPixelType, Dimension> OutVectorImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<OutVectorImageType> WriterType; + typedef otb::MultiChannelExtractROI<PixelType, PixelType> ChannelSelecterType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, OutVectorImageType> RescalerType; ReaderType::Pointer reader1 = ReaderType::New(); reader1->SetFileName(fileName1); @@ -118,8 +93,6 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader2 = ReaderType::New(); reader2->SetFileName(fileName2); - // Software Guide : BeginLatex - // // The different elements of the pipeline can now be instantiated in the // same way as the ratio of means change detector example. // @@ -130,14 +103,10 @@ int main(int argc, char * argv[]) // (i.e. add a ring of width 1 pixel around the current neightborhood shape). // The process is applied until the larger window size is reached. // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet FilterType::Pointer filter = FilterType::New(); filter->SetRadius((winSizeMin - 1) / 2, (winSizeMax - 1) / 2); filter->SetInput1(reader1->GetOutput()); filter->SetInput2(reader2->GetOutput()); - // Software Guide : EndCodeSnippet ChannelSelecterType::Pointer channelSelecter = ChannelSelecterType::New(); channelSelecter->SetInput(filter->GetOutput()); @@ -160,8 +129,6 @@ int main(int argc, char * argv[]) writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : BeginLatex - // // Figure \ref{fig:RESKLPCHDET} shows the result of the change // detection by computing the Kullback-Leibler distance between // local pdf through an Edgeworth approximation. @@ -173,21 +140,19 @@ int main(int argc, char * argv[]) // channel of the generated output.} // \label{fig:RESKLPCHDET} // \end{figure} - // - // Software Guide : EndLatex - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; std::cout << err << std::endl; return EXIT_FAILURE; - } + } catch (...) - { + { std::cout << "Unknown exception thrown !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Examples/ChangeDetection/MultivariateAlterationDetector.cxx b/Examples/ChangeDetection/MultivariateAlterationDetector.cxx index 3825ff5fa6575e05e6885d6e29e356787155c7d3..3a2f9cb7640b3e9523c77628d0908401699ff232 100644 --- a/Examples/ChangeDetection/MultivariateAlterationDetector.cxx +++ b/Examples/ChangeDetection/MultivariateAlterationDetector.cxx @@ -25,13 +25,16 @@ #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {Spot5-Gloucester-before.tif}, {Spot5-Gloucester-after.tif} -// OUTPUTS: {MADOutput.tif}, {mad-input1.png}, {mad-input2.png}, {mad-output.png} -// -// Software Guide : EndCommandLineArgs +/* Example usage: +./MultivariateAlterationDetector Input/Spot5-Gloucester-before.tif \ + Input/Spot5-Gloucester-after.tif \ + Output/MADOutput.tif \ + Output/mad-input1.png \ + Output/mad-input2.png \ + Output/mad-output.png +*/ + -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{MultivariateAlterationChangeDetectorImageFilter}, // which implements the Multivariate Alteration Change Detector @@ -57,143 +60,98 @@ // simply the difference between the two images). // // We start by including the corresponding header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMultivariateAlterationDetectorImageFilter.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc < 6) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile1 inputImageFile2 outIn1Pretty outIn2Pretty outPretty" << "outputImageFile" << std::endl; return -1; - } + } // Define the dimension of the images const unsigned int Dimension = 2; - // Software Guide : BeginLatex // We then define the types for the input images and for the // change image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned short InputPixelType; typedef float OutputPixelType; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; typedef otb::VectorImage<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now declare the types for the reader. Since the images // can be vey large, we will force the pipeline to use // streaming. For this purpose, the file writer will be // streamed. This is achieved by using the // \doxygen{otb}{ImageFileWriter} class. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet // This is for rendering in software guide - typedef otb::PrintableImageFilter<InputImageType,InputImageType> InputPrintFilterType; - typedef otb::PrintableImageFilter<OutputImageType,OutputImageType> OutputPrintFilterType; - typedef InputPrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<InputImageType, InputImageType> InputPrintFilterType; + typedef otb::PrintableImageFilter<OutputImageType, OutputImageType> OutputPrintFilterType; + typedef InputPrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; // The \doxygen{otb}{MultivariateAlterationDetectorImageFilter} is templated over // the type of the input images and the type of the generated change // image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MultivariateAlterationDetectorImageFilter< - InputImageType,OutputImageType> MADFilterType; - // Software Guide : EndCodeSnippet + typedef otb::MultivariateAlterationDetectorImageFilter<InputImageType, OutputImageType> MADFilterType; - // Software Guide : BeginLatex - // // The different elements of the pipeline can now be instantiated. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader1 = ReaderType::New(); - ReaderType::Pointer reader2 = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + ReaderType::Pointer reader1 = ReaderType::New(); + ReaderType::Pointer reader2 = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); MADFilterType::Pointer madFilter = MADFilterType::New(); - // Software Guide : EndCodeSnippet - const char * inputFilename1 = argv[1]; - const char * inputFilename2 = argv[2]; - const char * outputFilename = argv[3]; - const char * in1pretty = argv[4]; - const char * in2pretty = argv[5]; - const char * outpretty = argv[6]; - // Software Guide : BeginLatex - // + const char* inputFilename1 = argv[1]; + const char* inputFilename2 = argv[2]; + const char* outputFilename = argv[3]; + const char* in1pretty = argv[4]; + const char* in2pretty = argv[5]; + const char* outpretty = argv[6]; // We set the parameters of the different elements of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader1->SetFileName(inputFilename1); reader2->SetFileName(inputFilename2); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We build the pipeline by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet madFilter->SetInput1(reader1->GetOutput()); madFilter->SetInput2(reader2->GetOutput()); writer->SetInput(madFilter->GetOutput()); - // Software Guide : EndCodeSnippet try - { - // Software Guide : BeginLatex - // + { // And then we can trigger the pipeline update, as usual. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); - // Software Guide : EndCodeSnippet - - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } // Here we generate the figures - InputPrintFilterType::Pointer input1PrintFilter = InputPrintFilterType::New(); - InputPrintFilterType::Pointer input2PrintFilter = InputPrintFilterType::New(); + InputPrintFilterType::Pointer input1PrintFilter = InputPrintFilterType::New(); + InputPrintFilterType::Pointer input2PrintFilter = InputPrintFilterType::New(); OutputPrintFilterType::Pointer outputPrintFilter = OutputPrintFilterType::New(); - VisuWriterType::Pointer input1VisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer input2VisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer input1VisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer input2VisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); input1PrintFilter->SetInput(reader1->GetOutput()); input1PrintFilter->SetChannel(3); @@ -220,20 +178,17 @@ int main(int argc, char* argv[]) input2VisuWriter->Update(); outputVisuWriter->Update(); -// Software Guide : BeginLatex -// Figure \ref{fig:MADCHDET} shows the -// results of Multivariate Alteration Detector applied to a pair of -// SPOT5 images before and after a flooding event. -// \begin{figure} -// \center \includegraphics[width=0.32\textwidth]{mad-input1.eps} -// \includegraphics[width=0.32\textwidth]{mad-input2.eps} -// \includegraphics[width=0.32\textwidth]{mad-output.eps} -// \itkcaption[Multivariate Alteration Detection -// Results]{Result of the Multivariate Alteration Detector results on -// SPOT5 data before and after flooding.} \label{fig:MADCHDET} -// \end{figure} -// Software Guide : EndLatex + // Figure \ref{fig:MADCHDET} shows the + // results of Multivariate Alteration Detector applied to a pair of + // SPOT5 images before and after a flooding event. + // \begin{figure} + // \center \includegraphics[width=0.32\textwidth]{mad-input1.eps} + // \includegraphics[width=0.32\textwidth]{mad-input2.eps} + // \includegraphics[width=0.32\textwidth]{mad-output.eps} + // \itkcaption[Multivariate Alteration Detection + // Results]{Result of the Multivariate Alteration Detector results on + // SPOT5 data before and after flooding.} \label{fig:MADCHDET} + // \end{figure} return EXIT_SUCCESS; - } diff --git a/Examples/ChangeDetection/RatioChDet.cxx b/Examples/ChangeDetection/RatioChDet.cxx index 93a6a0ead1475e2ff1b9319d9d33538b5ea8661c..c12ffa03b09a090e36cc18ebfdf5c3f96d9fad84 100644 --- a/Examples/ChangeDetection/RatioChDet.cxx +++ b/Examples/ChangeDetection/RatioChDet.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {GomaAvant.png}, {GomaApres.png} -// OUTPUTS: {RatioChDet.tif} -// 3 -// Software Guide : EndCommandLineArgs +/* Example usage: +./RatioChDet Input/GomaAvant.png Input/GomaApres.png Output/RatioChDet.tif 3 +*/ + -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{MeanRatioImageFilter} for detecting changes // between pairs of images. This filter computes the mean intensity in @@ -50,12 +48,8 @@ // \end{figure} // // We start by including the corresponding header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMeanRatioImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -67,134 +61,82 @@ int main(int argc, char* argv[]) { if (argc < 5) - { + { std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] << - " inputImageFile1 inputImageFile2 outputImageFile radius" << std::endl; + std::cerr << argv[0] << " inputImageFile1 inputImageFile2 outputImageFile radius" << std::endl; return -1; - } + } // Define the dimension of the images const unsigned int Dimension = 2; - // Software Guide : BeginLatex // We start by declaring the types for the two input images, the // change image and the image to be stored in a file for visualization. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef float InternalPixelType; typedef unsigned char OutputPixelType; typedef otb::Image<InternalPixelType, Dimension> InputImageType1; typedef otb::Image<InternalPixelType, Dimension> InputImageType2; typedef otb::Image<InternalPixelType, Dimension> ChangeImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now declare the types for the readers. Since the images // can be vey large, we will force the pipeline to use // streaming. For this purpose, the file writer will be // streamed. This is achieved by using the // \doxygen{otb}{ImageFileWriter} class. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader<InputImageType1> ReaderType1; - typedef otb::ImageFileReader<InputImageType2> ReaderType2; + typedef otb::ImageFileReader<InputImageType1> ReaderType1; + typedef otb::ImageFileReader<InputImageType2> ReaderType2; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The change detector will give a normalized result between 0 and // 1. In order to store the result in PNG format we will // rescale the results of the change detection in order to use all // the output pixel type range of values. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::ShiftScaleImageFilter<ChangeImageType, - OutputImageType> RescalerType; + typedef itk::ShiftScaleImageFilter<ChangeImageType, OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{MeanRatioImageFilter} is templated over // the types of the two input images and the type of the generated change // image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MeanRatioImageFilter< - InputImageType1, - InputImageType2, - ChangeImageType> FilterType; + typedef otb::MeanRatioImageFilter<InputImageType1, InputImageType2, ChangeImageType> FilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The different elements of the pipeline can now be instantiated. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - ReaderType1::Pointer reader1 = ReaderType1::New(); - ReaderType2::Pointer reader2 = ReaderType2::New(); - WriterType::Pointer writer = WriterType::New(); - FilterType::Pointer filter = FilterType::New(); + + ReaderType1::Pointer reader1 = ReaderType1::New(); + ReaderType2::Pointer reader2 = ReaderType2::New(); + WriterType::Pointer writer = WriterType::New(); + FilterType::Pointer filter = FilterType::New(); RescalerType::Pointer rescaler = RescalerType::New(); - // Software Guide : EndCodeSnippet - const char * inputFilename1 = argv[1]; - const char * inputFilename2 = argv[2]; - const char * outputFilename = argv[3]; - // Software Guide : BeginLatex - // + const char* inputFilename1 = argv[1]; + const char* inputFilename2 = argv[2]; + const char* outputFilename = argv[3]; // We set the parameters of the different elements of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader1->SetFileName(inputFilename1); reader2->SetFileName(inputFilename2); writer->SetFileName(outputFilename); float scale = itk::NumericTraits<OutputPixelType>::max(); rescaler->SetScale(scale); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The only parameter for this change detector is the radius of // the window used for computing the mean of the intensities. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetRadius(atoi(argv[4])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We build the pipeline by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput1(reader1->GetOutput()); filter->SetInput2(reader2->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet typedef otb::CommandProgressUpdate<FilterType> CommandType; @@ -202,28 +144,25 @@ int main(int argc, char* argv[]) filter->AddObserver(itk::ProgressEvent(), observer); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } - -// Software Guide : BeginLatex -// Figure \ref{fig:RESRATCHDET} shows the result of the change -// detection by ratio of local means. -// \begin{figure} -// \center -// \includegraphics[width=0.35\textwidth]{RatioChDet.eps} -// \itkcaption[Ratio Change Detection Results]{Result of the -// ratio of means change detector} -// \label{fig:RESRATCHDET} -// \end{figure} -// Software Guide : EndLatex + } + + // Figure \ref{fig:RESRATCHDET} shows the result of the change + // detection by ratio of local means. + // \begin{figure} + // \center + // \includegraphics[width=0.35\textwidth]{RatioChDet.eps} + // \itkcaption[Ratio Change Detection Results]{Result of the + // ratio of means change detector} + // \label{fig:RESRATCHDET} + // \end{figure} return EXIT_SUCCESS; - } diff --git a/Examples/Classification/ClassificationMapRegularizationExample.cxx b/Examples/Classification/ClassificationMapRegularizationExample.cxx index 99ed1a18811f39779a15942280607f0ef8ed5fce..7fa37401fc4f8dcd789e0d85128927cbc2fd11f3 100644 --- a/Examples/Classification/ClassificationMapRegularizationExample.cxx +++ b/Examples/Classification/ClassificationMapRegularizationExample.cxx @@ -19,8 +19,6 @@ */ -// Software Guide : BeginLatex -// // After having generated a classification map, it is possible to // regularize such a labeled image in order to obtain more homogeneous // areas, which facilitates its interpretation. For this @@ -32,12 +30,8 @@ // // In this example we will illustrate its use. We start by including the // appropriate header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbNeighborhoodMajorityVotingImageFilter.h" -// Software Guide : EndCodeSnippet #include "itkMacro.h" #include "otbImage.h" @@ -47,166 +41,106 @@ #include "otbImageFileWriter.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { -// Software Guide : BeginLatex -// -// Since the input image is a classification map, we will assume a -// single band input image for which each pixel value is a label coded -// on 8 bits as an integer between 0 and 255. -// -// Software Guide : EndLatex + // Since the input image is a classification map, we will assume a + // single band input image for which each pixel value is a label coded + // on 8 bits as an integer between 0 and 255. -// Software Guide : BeginCodeSnippet typedef unsigned char IOLabelPixelType; // 8 bits - const unsigned int Dimension = 2; -// Software Guide : EndCodeSnippet + const unsigned int Dimension = 2; -// Software Guide : BeginLatex -// -// Thus, both input and output images are single band labeled images, -// which are composed of the same type of pixels in this example -// (unsigned char). -// -// Software Guide : EndLatex + // Thus, both input and output images are single band labeled images, + // which are composed of the same type of pixels in this example + // (unsigned char). -// Software Guide : BeginCodeSnippet typedef otb::Image<IOLabelPixelType, Dimension> IOLabelImageType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now define the type for the neighborhood majority voting filter, -// which is templated over its input and output images types as well as its -// structuring element type. Choosing only the input image type in the template -// of this filter induces that, both input and output images types are the same -// and that the structuring element is a ball -// (\doxygen{itk}{BinaryBallStructuringElement}). -// -// Software Guide : EndLatex + // We can now define the type for the neighborhood majority voting filter, + // which is templated over its input and output images types as well as its + // structuring element type. Choosing only the input image type in the template + // of this filter induces that, both input and output images types are the same + // and that the structuring element is a ball + // (\doxygen{itk}{BinaryBallStructuringElement}). -// Software Guide : BeginCodeSnippet // Neighborhood majority voting filter type - typedef otb::NeighborhoodMajorityVotingImageFilter<IOLabelImageType> - NeighborhoodMajorityVotingFilterType; -// Software Guide : EndCodeSnippet + typedef otb::NeighborhoodMajorityVotingImageFilter<IOLabelImageType> NeighborhoodMajorityVotingFilterType; -// Software Guide : BeginLatex -// -// Since the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter} is a -// neighborhood based image filter, it is necessary to set the structuring -// element which will be used for the majority voting process. By default, the -// structuring element is a ball -// (\doxygen{itk}{BinaryBallStructuringElement}) with a radius defined by two sizes -// (respectively along X and Y). Thus, it is possible to handle anisotropic -// structuring elements such as ovals. -// -// Software Guide : EndLatex + // Since the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter} is a + // neighborhood based image filter, it is necessary to set the structuring + // element which will be used for the majority voting process. By default, the + // structuring element is a ball + // (\doxygen{itk}{BinaryBallStructuringElement}) with a radius defined by two sizes + // (respectively along X and Y). Thus, it is possible to handle anisotropic + // structuring elements such as ovals. -// Software Guide : BeginCodeSnippet // Binary ball Structuring Element type typedef NeighborhoodMajorityVotingFilterType::KernelType StructuringType; - typedef StructuringType::RadiusType RadiusType; -// Software Guide : EndCodeSnippet + typedef StructuringType::RadiusType RadiusType; -// Software Guide : BeginLatex -// -// Finally, we define the reader and the writer. -// -// Software Guide : EndLatex + // Finally, we define the reader and the writer. -// Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<IOLabelImageType> ReaderType; typedef otb::ImageFileWriter<IOLabelImageType> WriterType; -// Software Guide : EndCodeSnippet - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; + const char* inputFileName = argv[1]; + const char* outputFileName = argv[2]; -// Software Guide : BeginLatex -// -// We instantiate the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter} and the -// reader objects. -// -// Software Guide : EndLatex + // We instantiate the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter} and the + // reader objects. -// Software Guide : BeginCodeSnippet // Neighborhood majority voting filter NeighborhoodMajorityVotingFilterType::Pointer NeighMajVotingFilter; NeighMajVotingFilter = NeighborhoodMajorityVotingFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); -// Software Guide : EndCodeSnippet - std::string KeepOriginalLabelBoolStr = argv[3]; - unsigned int radiusX = atoi(argv[4]); - unsigned int radiusY = atoi(argv[5]); - IOLabelPixelType noDataValue = atoi(argv[6]); - IOLabelPixelType undecidedValue = atoi(argv[7]); + std::string KeepOriginalLabelBoolStr = argv[3]; + unsigned int radiusX = atoi(argv[4]); + unsigned int radiusY = atoi(argv[5]); + IOLabelPixelType noDataValue = atoi(argv[6]); + IOLabelPixelType undecidedValue = atoi(argv[7]); -// Software Guide : BeginLatex -// -// The ball shaped structuring element seBall is instantiated and its -// two radii along X and Y are initialized. -// -// Software Guide : EndLatex + // The ball shaped structuring element seBall is instantiated and its + // two radii along X and Y are initialized. -// Software Guide : BeginCodeSnippet StructuringType seBall; - RadiusType rad; + RadiusType rad; rad[0] = radiusX; rad[1] = radiusY; seBall.SetRadius(rad); seBall.CreateStructuringElement(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Then, this ball shaped neighborhood is used as the kernel structuring element -// for the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter}. -// -// Software Guide : EndLatex + // Then, this ball shaped neighborhood is used as the kernel structuring element + // for the \doxygen{otb}{NeighborhoodMajorityVotingImageFilter}. -// Software Guide : BeginCodeSnippet NeighMajVotingFilter->SetKernel(seBall); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Not classified input pixels are assumed to have the noDataValue label -// and will keep this label in the output image. -// -// Software Guide : EndLatex + // Not classified input pixels are assumed to have the noDataValue label + // and will keep this label in the output image. -// Software Guide : BeginCodeSnippet NeighMajVotingFilter->SetLabelForNoDataPixels(noDataValue); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Furthermore, since the majority voting regularization may lead to different -// majority labels in the neighborhood, in this case, it would be important to define -// the filter's behaviour. For this purpose, a Boolean parameter is used -// in the filter to choose whether pixels with more than one majority class are set -// to undecidedValue (true), or to their Original labels (false = default value) -// in the output image. -// -// Software Guide : EndLatex + // Furthermore, since the majority voting regularization may lead to different + // majority labels in the neighborhood, in this case, it would be important to define + // the filter's behaviour. For this purpose, a Boolean parameter is used + // in the filter to choose whether pixels with more than one majority class are set + // to undecidedValue (true), or to their Original labels (false = default value) + // in the output image. -// Software Guide : BeginCodeSnippet NeighMajVotingFilter->SetLabelForUndecidedPixels(undecidedValue); if (KeepOriginalLabelBoolStr.compare("true") == 0) @@ -217,25 +151,18 @@ int main(int itkNotUsed(argc), char * argv[]) { NeighMajVotingFilter->SetKeepOriginalLabelBool(false); } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We plug the pipeline and -// trigger its execution by updating the output of the writer. -// -// Software Guide : EndLatex + // We plug the pipeline and + // trigger its execution by updating the output of the writer. -// Software Guide : BeginCodeSnippet NeighMajVotingFilter->SetInput(reader->GetOutput()); WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFileName); writer->SetInput(NeighMajVotingFilter->GetOutput()); writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/Classification/DempsterShaferFusionOfClassificationMapsExample.cxx b/Examples/Classification/DempsterShaferFusionOfClassificationMapsExample.cxx index be989f7ab9d2b0a041c061c729754cba22f80153..c9cc0a0a5f4a83e2c84af9e3f01d4bb0cc650bfc 100644 --- a/Examples/Classification/DempsterShaferFusionOfClassificationMapsExample.cxx +++ b/Examples/Classification/DempsterShaferFusionOfClassificationMapsExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // The fusion filter \doxygen{otb}{DSFusionOfClassifiersImageFilter} is based on the Dempster // Shafer (DS) fusion framework. For each pixel, it chooses the class label \emph{Ai} for which the // belief function \emph{bel(Ai)} is maximal after the DS combination of all the available masses of @@ -31,221 +28,179 @@ // \emph{nodataLabel} value are ignored by the fusion process. In case of not unique class labels // with the maximal belief function, the output pixels are set to the \emph{undecidedLabel} value. // We start by including the appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageListToVectorImageFilter.h" #include "otbConfusionMatrixToMassOfBelief.h" #include "otbDSFusionOfClassifiersImageFilter.h" #include <fstream> -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : BeginLatex -// // We will assume unsigned short type input labeled images. We define a type for // confusion matrices as \doxygen{itk}{VariableSizeMatrix} which will be used to estimate the masses of belief of all the // class labels for each input classification map. For this purpose, the // \doxygen{otb}{ConfusionMatrixToMassOfBelief} will be used to convert each input confusion matrix // into masses of belief for each class label. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef unsigned short LabelPixelType; - typedef unsigned long ConfusionMatrixEltType; - typedef itk::VariableSizeMatrix<ConfusionMatrixEltType> ConfusionMatrixType; - typedef otb::ConfusionMatrixToMassOfBelief - <ConfusionMatrixType, LabelPixelType> ConfusionMatrixToMassOfBeliefType; - typedef ConfusionMatrixToMassOfBeliefType::MapOfClassesType MapOfClassesType; -// Software Guide : EndCodeSnippet +typedef unsigned short LabelPixelType; +typedef unsigned long ConfusionMatrixEltType; +typedef itk::VariableSizeMatrix<ConfusionMatrixEltType> ConfusionMatrixType; +typedef otb::ConfusionMatrixToMassOfBelief<ConfusionMatrixType, LabelPixelType> ConfusionMatrixToMassOfBeliefType; +typedef ConfusionMatrixToMassOfBeliefType::MapOfClassesType MapOfClassesType; + +int CSVConfusionMatrixFileReader(const std::string fileName, MapOfClassesType& mapOfClassesRefClX, ConfusionMatrixType& confusionMatrixClX) +{ + std::ifstream inFile; + inFile.open(fileName); -int CSVConfusionMatrixFileReader(const std::string fileName, MapOfClassesType &mapOfClassesRefClX, ConfusionMatrixType &confusionMatrixClX) + if (!inFile) + { + std::cerr << "Confusion Matrix File opening problem with file:" << std::endl; + std::cerr << fileName << std::endl; + return EXIT_FAILURE; + } + else { - std::ifstream inFile; - inFile.open(fileName); + LabelPixelType labelRef = 0, labelProd = 0; + std::string currentLine, refLabelsLine, prodLabelsLine, currentValue; + const char endCommentChar = ':'; + const char separatorChar = ','; + const char eolChar = '\n'; + std::getline(inFile, refLabelsLine, endCommentChar); // Skips the comments + std::getline(inFile, refLabelsLine, eolChar); // Gets the first line after the comment char until the End Of Line char + std::getline(inFile, prodLabelsLine, endCommentChar); // Skips the comments + std::getline(inFile, prodLabelsLine, eolChar); // Gets the second line after the comment char until the End Of Line char + + std::istringstream issRefLabelsLine(refLabelsLine); + std::istringstream issProdLabelsLine(prodLabelsLine); + + MapOfClassesType mapOfClassesProdClX; + + mapOfClassesRefClX.clear(); + mapOfClassesProdClX.clear(); + int itLab = 0; + while (issRefLabelsLine.good()) + { + std::getline(issRefLabelsLine, currentValue, separatorChar); + labelRef = static_cast<LabelPixelType>(std::atoi(currentValue.c_str())); + mapOfClassesRefClX[labelRef] = itLab; + ++itLab; + } + + itLab = 0; + while (issProdLabelsLine.good()) + { + std::getline(issProdLabelsLine, currentValue, separatorChar); + labelProd = static_cast<LabelPixelType>(std::atoi(currentValue.c_str())); + mapOfClassesProdClX[labelProd] = itLab; + ++itLab; + } - if (!inFile) + unsigned int nbRefLabelsClk = mapOfClassesRefClX.size(); + unsigned int nbProdLabelsClk = mapOfClassesProdClX.size(); + ConfusionMatrixType confusionMatrixClXTemp; + confusionMatrixClXTemp = ConfusionMatrixType(nbRefLabelsClk, nbProdLabelsClk); + confusionMatrixClXTemp.Fill(0); + + // Reading the confusion matrix confusionMatrixClXTemp from the file + for (unsigned int itRow = 0; itRow < nbRefLabelsClk; ++itRow) + { + // Gets the itRow^th line after the header lines with the labels + std::getline(inFile, currentLine, eolChar); + std::istringstream issCurrentLine(currentLine); + unsigned int itCol = 0; + while (issCurrentLine.good()) { - std::cerr << "Confusion Matrix File opening problem with file:" << std::endl; - std::cerr << fileName << std::endl; - return EXIT_FAILURE; + std::getline(issCurrentLine, currentValue, separatorChar); + confusionMatrixClXTemp(itRow, itCol) = static_cast<ConfusionMatrixEltType>(std::atoi(currentValue.c_str())); + ++itCol; } - else - { - LabelPixelType labelRef = 0, labelProd = 0; - std::string currentLine, refLabelsLine, prodLabelsLine, currentValue; - const char endCommentChar = ':'; - const char separatorChar = ','; - const char eolChar = '\n'; - std::getline(inFile, refLabelsLine, endCommentChar); // Skips the comments - std::getline(inFile, refLabelsLine, eolChar); // Gets the first line after the comment char until the End Of Line char - std::getline(inFile, prodLabelsLine, endCommentChar); // Skips the comments - std::getline(inFile, prodLabelsLine, eolChar); // Gets the second line after the comment char until the End Of Line char - - std::istringstream issRefLabelsLine(refLabelsLine); - std::istringstream issProdLabelsLine(prodLabelsLine); - - MapOfClassesType mapOfClassesProdClX; - - mapOfClassesRefClX.clear(); - mapOfClassesProdClX.clear(); - int itLab = 0; - while (issRefLabelsLine.good()) - { - std::getline(issRefLabelsLine, currentValue, separatorChar); - labelRef = static_cast<LabelPixelType> (std::atoi(currentValue.c_str())); - mapOfClassesRefClX[labelRef] = itLab; - ++itLab; - } - - itLab = 0; - while (issProdLabelsLine.good()) - { - std::getline(issProdLabelsLine, currentValue, separatorChar); - labelProd = static_cast<LabelPixelType> (std::atoi(currentValue.c_str())); - mapOfClassesProdClX[labelProd] = itLab; - ++itLab; - } + } - unsigned int nbRefLabelsClk = mapOfClassesRefClX.size(); - unsigned int nbProdLabelsClk = mapOfClassesProdClX.size(); - ConfusionMatrixType confusionMatrixClXTemp; - confusionMatrixClXTemp = ConfusionMatrixType(nbRefLabelsClk, nbProdLabelsClk); - confusionMatrixClXTemp.Fill(0); + MapOfClassesType::iterator itMapOfClassesRef, itMapOfClassesProd; - // Reading the confusion matrix confusionMatrixClXTemp from the file - for (unsigned int itRow = 0; itRow < nbRefLabelsClk; ++itRow) - { - //Gets the itRow^th line after the header lines with the labels - std::getline(inFile, currentLine, eolChar); - std::istringstream issCurrentLine(currentLine); - unsigned int itCol = 0; - while (issCurrentLine.good()) - { - std::getline(issCurrentLine, currentValue, separatorChar); - confusionMatrixClXTemp(itRow, itCol) = static_cast<ConfusionMatrixEltType> (std::atoi(currentValue.c_str())); - ++itCol; - } - } + // Formatting confusionMatrixClX from confusionMatrixClXTemp in order to make confusionMatrixClX a square matrix + // from the reference labels in mapOfClassesRefClX + int indiceLabelRef = 0, indiceLabelProd = 0; + int indiceLabelRefTemp = 0, indiceLabelProdTemp = 0; + // Initialization of confusionMatrixClX + confusionMatrixClX = ConfusionMatrixType(nbRefLabelsClk, nbRefLabelsClk); + confusionMatrixClX.Fill(0); + for (itMapOfClassesRef = mapOfClassesRefClX.begin(); itMapOfClassesRef != mapOfClassesRefClX.end(); ++itMapOfClassesRef) + { + // labels labelRef of mapOfClassesRefClX are already sorted + labelRef = itMapOfClassesRef->first; + indiceLabelRefTemp = itMapOfClassesRef->second; - MapOfClassesType::iterator itMapOfClassesRef, itMapOfClassesProd; + for (itMapOfClassesProd = mapOfClassesProdClX.begin(); itMapOfClassesProd != mapOfClassesProdClX.end(); ++itMapOfClassesProd) + { + // labels labelProd of mapOfClassesProdClX are already sorted + labelProd = itMapOfClassesProd->first; + indiceLabelProdTemp = itMapOfClassesProd->second; - // Formatting confusionMatrixClX from confusionMatrixClXTemp in order to make confusionMatrixClX a square matrix - // from the reference labels in mapOfClassesRefClX - int indiceLabelRef = 0, indiceLabelProd = 0; - int indiceLabelRefTemp = 0, indiceLabelProdTemp = 0; - // Initialization of confusionMatrixClX - confusionMatrixClX = ConfusionMatrixType(nbRefLabelsClk, nbRefLabelsClk); - confusionMatrixClX.Fill(0); - for (itMapOfClassesRef = mapOfClassesRefClX.begin(); itMapOfClassesRef != mapOfClassesRefClX.end(); ++itMapOfClassesRef) + // If labelProd is present in mapOfClassesRefClX + if (mapOfClassesRefClX.count(labelProd) != 0) { - // labels labelRef of mapOfClassesRefClX are already sorted - labelRef = itMapOfClassesRef->first; - indiceLabelRefTemp = itMapOfClassesRef->second; - - for (itMapOfClassesProd = mapOfClassesProdClX.begin(); itMapOfClassesProd != mapOfClassesProdClX.end(); ++itMapOfClassesProd) - { - // labels labelProd of mapOfClassesProdClX are already sorted - labelProd = itMapOfClassesProd->first; - indiceLabelProdTemp = itMapOfClassesProd->second; - - // If labelProd is present in mapOfClassesRefClX - if (mapOfClassesRefClX.count(labelProd) != 0) - { - // Indice of labelProd in mapOfClassesRefClX; itMapOfClassesRef->second elements are already SORTED - indiceLabelProd = mapOfClassesRefClX[labelProd]; - confusionMatrixClX(indiceLabelRef, indiceLabelProd) = confusionMatrixClXTemp(indiceLabelRefTemp, indiceLabelProdTemp); - } - } - ++indiceLabelRef; + // Indice of labelProd in mapOfClassesRefClX; itMapOfClassesRef->second elements are already SORTED + indiceLabelProd = mapOfClassesRefClX[labelProd]; + confusionMatrixClX(indiceLabelRef, indiceLabelProd) = confusionMatrixClXTemp(indiceLabelRefTemp, indiceLabelProdTemp); } } - inFile.close(); - return EXIT_SUCCESS; + ++indiceLabelRef; + } } + inFile.close(); + return EXIT_SUCCESS; +} -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { -// Software Guide : BeginLatex -// -// The input labeled images to be fused are expected to be scalar images. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; - typedef otb::Image<LabelPixelType, Dimension> LabelImageType; + // The input labeled images to be fused are expected to be scalar images. + const unsigned int Dimension = 2; + typedef otb::Image<LabelPixelType, Dimension> LabelImageType; typedef otb::VectorImage<LabelPixelType, Dimension> VectorImageType; -// Software Guide : EndCodeSnippet - LabelPixelType nodataLabel = atoi(argv[argc - 3]); + LabelPixelType nodataLabel = atoi(argv[argc - 3]); LabelPixelType undecidedLabel = atoi(argv[argc - 2]); - const char * outfname = argv[argc - 1]; + const char* outfname = argv[argc - 1]; - unsigned int nbParameters = 3; + unsigned int nbParameters = 3; unsigned int nbClassificationMaps = (argc - 1 - nbParameters) / 2; - // Software Guide : BeginLatex - // // We declare an \doxygen{otb}{ImageListToVectorImageFilter} which will stack all the // input classification maps to be fused as a single VectorImage for which each // band is a classification map. This VectorImage will then be the input of the // Dempster Shafer fusion filter \doxygen{otb}{DSFusionOfClassifiersImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageList<LabelImageType> LabelImageListType; - typedef otb::ImageListToVectorImageFilter - <LabelImageListType, VectorImageType> ImageListToVectorImageFilterType; - // Software Guide : EndCodeSnippet + typedef otb::ImageList<LabelImageType> LabelImageListType; + typedef otb::ImageListToVectorImageFilter<LabelImageListType, VectorImageType> ImageListToVectorImageFilterType; typedef ConfusionMatrixToMassOfBeliefType::MassOfBeliefDefinitionMethod MassOfBeliefDefinitionMethod; -// Software Guide : BeginLatex -// -// The Dempster Shafer fusion filter \doxygen{otb}{DSFusionOfClassifiersImageFilter} is declared. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // The Dempster Shafer fusion filter \doxygen{otb}{DSFusionOfClassifiersImageFilter} is declared. // Dempster Shafer - typedef otb::DSFusionOfClassifiersImageFilter - <VectorImageType, LabelImageType> DSFusionOfClassifiersImageFilterType; -// Software Guide : EndCodeSnippet + typedef otb::DSFusionOfClassifiersImageFilter<VectorImageType, LabelImageType> DSFusionOfClassifiersImageFilterType; typedef DSFusionOfClassifiersImageFilterType::VectorOfMapOfMassesOfBeliefType VectorOfMapOfMassesOfBeliefType; -// Software Guide : BeginLatex -// -// Both reader and writer are defined. Since the images -// to classify can be very big, we will use a streamed writer which -// will trigger the streaming ability of the fusion filter. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // Both reader and writer are defined. Since the images + // to classify can be very big, we will use a streamed writer which + // will trigger the streaming ability of the fusion filter. typedef otb::ImageFileReader<LabelImageType> ReaderType; typedef otb::ImageFileWriter<LabelImageType> WriterType; -// Software Guide : EndCodeSnippet - - -// Software Guide : BeginLatex -// -// The image list of input classification maps is filled. Moreover, the input -// confusion matrix files are converted into masses of belief. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - ReaderType::Pointer reader; - LabelImageListType::Pointer imageList = LabelImageListType::New(); + + + // The image list of input classification maps is filled. Moreover, the input + // confusion matrix files are converted into masses of belief. + ReaderType::Pointer reader; + LabelImageListType::Pointer imageList = LabelImageListType::New(); ConfusionMatrixToMassOfBeliefType::Pointer confusionMatrixToMassOfBeliefFilter; confusionMatrixToMassOfBeliefFilter = ConfusionMatrixToMassOfBeliefType::New(); @@ -257,9 +212,9 @@ int main(int argc, char * argv[]) VectorOfMapOfMassesOfBeliefType vectorOfMapOfMassesOfBelief; for (unsigned int itCM = 0; itCM < nbClassificationMaps; ++itCM) - { + { std::string fileNameClassifiedImage = argv[itCM + 1]; - std::string fileNameConfMat = argv[itCM + 1 + nbClassificationMaps]; + std::string fileNameConfMat = argv[itCM + 1 + nbClassificationMaps]; reader = ReaderType::New(); reader->SetFileName(fileNameClassifiedImage); @@ -267,13 +222,12 @@ int main(int argc, char * argv[]) imageList->PushBack(reader->GetOutput()); - MapOfClassesType mapOfClassesClk; + MapOfClassesType mapOfClassesClk; ConfusionMatrixType confusionMatrixClk; // The data (class labels and confusion matrix values) are read and // extracted from the *.CSV file with an ad-hoc file parser - CSVConfusionMatrixFileReader( - fileNameConfMat, mapOfClassesClk, confusionMatrixClk); + CSVConfusionMatrixFileReader(fileNameConfMat, mapOfClassesClk, confusionMatrixClk); // The parameters of the ConfusionMatrixToMassOfBelief filter are set confusionMatrixToMassOfBeliefFilter->SetMapOfClasses(mapOfClassesClk); @@ -283,19 +237,12 @@ int main(int argc, char * argv[]) // Vector containing ALL the K (= nbClassificationMaps) std::map<Label, MOB> // of Masses of Belief - vectorOfMapOfMassesOfBelief.push_back( - confusionMatrixToMassOfBeliefFilter->GetMapMassOfBelief()); - } -// Software Guide : EndCodeSnippet + vectorOfMapOfMassesOfBelief.push_back(confusionMatrixToMassOfBeliefFilter->GetMapMassOfBelief()); + } -// Software Guide : BeginLatex -// -// The image list of input classification maps is converted into a VectorImage to -// be used as input of the \doxygen{otb}{DSFusionOfClassifiersImageFilter}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // The image list of input classification maps is converted into a VectorImage to + // be used as input of the \doxygen{otb}{DSFusionOfClassifiersImageFilter}. // Image List To VectorImage ImageListToVectorImageFilterType::Pointer imageListToVectorImageFilter; imageListToVectorImageFilter = ImageListToVectorImageFilterType::New(); @@ -309,21 +256,14 @@ int main(int argc, char * argv[]) dsFusionFilter->SetInputMapsOfMassesOfBelief(&vectorOfMapOfMassesOfBelief); dsFusionFilter->SetLabelForNoDataPixels(nodataLabel); dsFusionFilter->SetLabelForUndecidedPixels(undecidedLabel); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Once it is plugged the pipeline triggers its execution by updating -// the output of the writer. -// -// Software Guide : EndLatex + // Once it is plugged the pipeline triggers its execution by updating + // the output of the writer. -// Software Guide : BeginCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetInput(dsFusionFilter->GetOutput()); writer->SetFileName(outfname); writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/Classification/SOMImageClassificationExample.cxx b/Examples/Classification/SOMImageClassificationExample.cxx index 4ccec0e7ace8f4a0bf9556819fd9d14670edac45..17ef8efc1c9fd5cc4d47ee6529b7d7d91459d991 100644 --- a/Examples/Classification/SOMImageClassificationExample.cxx +++ b/Examples/Classification/SOMImageClassificationExample.cxx @@ -18,8 +18,6 @@ * limitations under the License. */ -// Software Guide : BeginLatex -// // In previous examples, we have used the // \doxygen{otb}{SOMClassifier}, which uses the ITK classification // framework. This good for compatibility with the ITK framework, but @@ -29,83 +27,47 @@ // developing the \doxygen{otb}{SOMImageClassificationFilter}. In // this example we will illustrate its use. We start by including the // appropriate header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSOMImageClassificationFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbSOMMap.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { - const char * infname = argv[1]; - const char * somfname = argv[2]; - const char * outfname = argv[3]; + const char* infname = argv[1]; + const char* somfname = argv[2]; + const char* outfname = argv[3]; -// Software Guide : BeginLatex -// -// We will assume double precision input images and will also define -// the type for the labeled pixels. -// -// Software Guide : EndLatex + // We will assume double precision input images and will also define + // the type for the labeled pixels. -// Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double PixelType; typedef unsigned short LabeledPixelType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Our classifier will be generic enough to be able to process images -// with any number of bands. We read the images as -// \doxygen{otb}{VectorImage}s. The labeled image will be a scalar image. -// -// Software Guide : EndLatex + // Our classifier will be generic enough to be able to process images + // with any number of bands. We read the images as + // \doxygen{otb}{VectorImage}s. The labeled image will be a scalar image. -// Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now define the type for the classifier filter, which is -// templated over its input and output image types and the SOM type. -// -// Software Guide : EndLatex + // We can now define the type for the classifier filter, which is + // templated over its input and output image types and the SOM type. -// Software Guide : BeginCodeSnippet - typedef otb::SOMMap<ImageType::PixelType> SOMMapType; - typedef otb::SOMImageClassificationFilter<ImageType, - LabeledImageType, - SOMMapType> - ClassificationFilterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// And finally, we define the readers (for the input image and theSOM) -// and the writer. Since the images, -// to classify can be very big, we will use a streamed writer which -// will trigger the streaming ability of the classifier. -// -// Software Guide : EndLatex + typedef otb::SOMMap<ImageType::PixelType> SOMMapType; + typedef otb::SOMImageClassificationFilter<ImageType, LabeledImageType, SOMMapType> ClassificationFilterType; + // And finally, we define the readers (for the input image and theSOM) + // and the writer. Since the images, + // to classify can be very big, we will use a streamed writer which + // will trigger the streaming ability of the classifier. -// Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileReader<SOMMapType> SOMReaderType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileReader<SOMMapType> SOMReaderType; typedef otb::ImageFileWriter<LabeledImageType> WriterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the classifier and the reader objects and we set -// the existing SOM obtained in a previous training step. -// -// Software Guide : EndLatex + // We instantiate the classifier and the reader objects and we set + // the existing SOM obtained in a previous training step. -// Software Guide : BeginCodeSnippet ClassificationFilterType::Pointer filter = ClassificationFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); @@ -116,21 +78,14 @@ int main(int itkNotUsed(argc), char * argv[]) somreader->Update(); filter->SetMap(somreader->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We plug the pipeline and -// trigger its execution by updating the output of the writer. -// -// Software Guide : EndLatex + // We plug the pipeline and + // trigger its execution by updating the output of the writer. -// Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); WriterType::Pointer writer = WriterType::New(); writer->SetInput(filter->GetOutput()); writer->SetFileName(outfname); writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/Classification/SupervisedImageClassificationExample.cxx b/Examples/Classification/SupervisedImageClassificationExample.cxx index 2b026066df2225447ae986dc504a9a8366b2f43a..d48f0678a6b536caee4d804e55403c58a0b492d6 100644 --- a/Examples/Classification/SupervisedImageClassificationExample.cxx +++ b/Examples/Classification/SupervisedImageClassificationExample.cxx @@ -19,8 +19,6 @@ */ -// Software Guide : BeginLatex -// // In OTB, a generic streamed filter called \doxygen{otb}{ImageClassificationFilter} // is available to classify any input multi-channel image according to an input // classification model file. This filter is generic because it works with any @@ -33,128 +31,72 @@ // to generate a classification model either from samples or from images. // In this example we will illustrate its use. We start by including the // appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMachineLearningModelFactory.h" #include "otbImageClassificationFilter.h" -// Software Guide : EndCodeSnippet #include "otbVectorImage.h" #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { - const char * infname = argv[1]; - const char * modelfname = argv[2]; - const char * outfname = argv[3]; - -// Software Guide : BeginLatex -// -// We will assume double precision input images and will also define -// the type for the labeled pixels. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + const char* infname = argv[1]; + const char* modelfname = argv[2]; + const char* outfname = argv[3]; + + // We will assume double precision input images and will also define + // the type for the labeled pixels. + const unsigned int Dimension = 2; typedef double PixelType; typedef unsigned short LabeledPixelType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Our classifier is generic enough to be able to process images -// with any number of bands. We read the input image as a -// \doxygen{otb}{VectorImage}. The labeled image will be a scalar image. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // Our classifier is generic enough to be able to process images + // with any number of bands. We read the input image as a + // \doxygen{otb}{VectorImage}. The labeled image will be a scalar image. typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// We can now define the type for the classifier filter, which is -// templated over its input and output image types. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef otb::ImageClassificationFilter<ImageType, LabeledImageType> - ClassificationFilterType; - typedef ClassificationFilterType::ModelType ModelType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// Moreover, it is necessary to define a \doxygen{otb}{MachineLearningModelFactory} -// which is templated over its input and output pixel types. This factory is used -// to parse the input model file and to define which classification method to use. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef otb::MachineLearningModelFactory<PixelType, LabeledPixelType> - MachineLearningModelFactoryType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// And finally, we define the reader and the writer. Since the images -// to classify can be very big, we will use a streamed writer which -// will trigger the streaming ability of the classifier. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + + // We can now define the type for the classifier filter, which is + // templated over its input and output image types. + typedef otb::ImageClassificationFilter<ImageType, LabeledImageType> ClassificationFilterType; + typedef ClassificationFilterType::ModelType ModelType; + + // Moreover, it is necessary to define a \doxygen{otb}{MachineLearningModelFactory} + // which is templated over its input and output pixel types. This factory is used + // to parse the input model file and to define which classification method to use. + typedef otb::MachineLearningModelFactory<PixelType, LabeledPixelType> MachineLearningModelFactoryType; + + // And finally, we define the reader and the writer. Since the images + // to classify can be very big, we will use a streamed writer which + // will trigger the streaming ability of the classifier. typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<LabeledImageType> WriterType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// We instantiate the classifier and the reader objects and we set -// the existing model obtained in a previous training step. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + + // We instantiate the classifier and the reader objects and we set + // the existing model obtained in a previous training step. ClassificationFilterType::Pointer filter = ClassificationFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The input model file is parsed according to its content and the generated model -// is then loaded within the \doxygen{otb}{ImageClassificationFilter}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + + // The input model file is parsed according to its content and the generated model + // is then loaded within the \doxygen{otb}{ImageClassificationFilter}. ModelType::Pointer model; - model = MachineLearningModelFactoryType::CreateMachineLearningModel( - modelfname, - MachineLearningModelFactoryType::ReadMode); + model = MachineLearningModelFactoryType::CreateMachineLearningModel(modelfname, MachineLearningModelFactoryType::ReadMode); model->Load(modelfname); filter->SetModel(model); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We plug the pipeline and -// trigger its execution by updating the output of the writer. -// -// Software Guide : EndLatex + // We plug the pipeline and + // trigger its execution by updating the output of the writer. -// Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); WriterType::Pointer writer = WriterType::New(); writer->SetInput(filter->GetOutput()); writer->SetFileName(outfname); writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/DimensionReduction/ICAExample.cxx b/Examples/DimensionReduction/ICAExample.cxx index 048594499e98fd8e2ab95042f53ce12083090a6f..804950e6264c86a6adcd30363619d8773a4f1339 100644 --- a/Examples/DimensionReduction/ICAExample.cxx +++ b/Examples/DimensionReduction/ICAExample.cxx @@ -23,14 +23,19 @@ #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {wv2_cannes_8bands.tif} -// OUTPUTS: {FastICAOutput.tif}, {InverseFastICAOutput.tif}, {FastICA-input-pretty.png}, {FastICA-output-pretty.png}, {FastICA-invoutput-pretty.png} -// 8 20 1. -// Software Guide : EndCommandLineArgs +/* Example usage: +./ICAExample Input/wv2_cannes_8bands.tif \ + Output/FastICAOutput.tif \ + Output/InverseFastICAOutput.tif \ + Output/FastICA-input-pretty.png \ + Output/FastICA-output-pretty.png \ + Output/FastICA-invoutput-pretty.png \ + 8 \ + 20 \ + 1. +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{FastICAImageFilter}. // This filter computes a Fast Independent Components Analysis transform. @@ -46,155 +51,92 @@ // of the components, and the maximization is done in an iterative way. // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbFastICAImageFilter.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - typedef double PixelType; - const unsigned int Dimension = 2; - const char * inputFileName = argv[1]; - const char * outputFilename = argv[2]; - const char * outputInverseFilename = argv[3]; + typedef double PixelType; + const unsigned int Dimension = 2; + const char* inputFileName = argv[1]; + const char* outputFilename = argv[2]; + const char* outputInverseFilename = argv[3]; const unsigned int numberOfPrincipalComponentsRequired(atoi(argv[7])); - const char * inpretty = argv[4]; - const char * outpretty = argv[5]; - const char * invoutpretty = argv[6]; - unsigned int numIterations = atoi(argv[8]); - double mu = atof(argv[9]); - - // Software Guide : BeginLatex - // + const char* inpretty = argv[4]; + const char* outpretty = argv[5]; + const char* invoutpretty = argv[6]; + unsigned int numIterations = atoi(argv[8]); + double mu = atof(argv[9]); + // We start by defining the types for the images, the reader, and // the writer. We choose to work with a \doxygen{otb}{VectorImage}, // since we will produce a multi-channel image (the independent // components) from a multi-channel input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We instantiate now the image reader and we set the image file name. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type for the filter. It is templated over the input // and the output image types and also the transformation direction. The // internal structure of this filter is a filter-to-filter like structure. // We can now the instantiate the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::FastICAImageFilter<ImageType, ImageType, - otb::Transform::FORWARD> FastICAFilterType; - FastICAFilterType::Pointer FastICAfilter = FastICAFilterType::New(); - // Software Guide : EndCodeSnippet + typedef otb::FastICAImageFilter<ImageType, ImageType, otb::Transform::FORWARD> FastICAFilterType; + FastICAFilterType::Pointer FastICAfilter = FastICAFilterType::New(); - // Software Guide : BeginLatex - // // We then set the number of independent // components required as output. We can choose to get less ICs than // the number of input bands. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - FastICAfilter->SetNumberOfPrincipalComponentsRequired( - numberOfPrincipalComponentsRequired); - // Software Guide : EndCodeSnippet + FastICAfilter->SetNumberOfPrincipalComponentsRequired(numberOfPrincipalComponentsRequired); - // Software Guide : BeginLatex - // // We set the number of iterations of the ICA algorithm. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FastICAfilter->SetNumberOfIterations(numIterations); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We also set the $\mu$ parameter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - FastICAfilter->SetMu( mu ); - // Software Guide : EndCodeSnippet + FastICAfilter->SetMu(mu); - // Software Guide : BeginLatex - // // We now instantiate the writer and set the file name for the // output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We finally plug the pipeline and trigger the ICA computation with // the method \code{Update()} of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FastICAfilter->SetInput(reader->GetOutput()); writer->SetInput(FastICAfilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // \doxygen{otb}{FastICAImageFilter} allows also to compute inverse // transformation from ICA coefficients. In reverse mode, the // covariance matrix or the transformation matrix // (which may not be square) has to be given. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::FastICAImageFilter< ImageType, ImageType, - otb::Transform::INVERSE > InvFastICAFilterType; - InvFastICAFilterType::Pointer invFilter = InvFastICAFilterType::New(); - - invFilter->SetMeanValues( FastICAfilter->GetMeanValues() ); - invFilter->SetStdDevValues( FastICAfilter->GetStdDevValues() ); - invFilter->SetTransformationMatrix( FastICAfilter->GetTransformationMatrix() ); - invFilter->SetPCATransformationMatrix( - FastICAfilter->GetPCATransformationMatrix() ); + + typedef otb::FastICAImageFilter<ImageType, ImageType, otb::Transform::INVERSE> InvFastICAFilterType; + InvFastICAFilterType::Pointer invFilter = InvFastICAFilterType::New(); + + invFilter->SetMeanValues(FastICAfilter->GetMeanValues()); + invFilter->SetStdDevValues(FastICAfilter->GetStdDevValues()); + invFilter->SetTransformationMatrix(FastICAfilter->GetTransformationMatrix()); + invFilter->SetPCATransformationMatrix(FastICAfilter->GetPCATransformationMatrix()); invFilter->SetInput(FastICAfilter->GetOutput()); WriterType::Pointer invWriter = WriterType::New(); - invWriter->SetFileName(outputInverseFilename ); - invWriter->SetInput(invFilter->GetOutput() ); + invWriter->SetFileName(outputInverseFilename); + invWriter->SetInput(invFilter->GetOutput()); invWriter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:FastICA_FILTER} shows the result of applying forward // and reverse FastICA transformation to a 8 bands Worldview2 image. // \begin{figure} @@ -210,20 +152,18 @@ int main(int itkNotUsed(argc), char* argv[]) // inverse mode (the input RGB image).} // \label{fig:FastICA_FILTER} // \end{figure} - // - // Software Guide : EndLatex // This is for rendering in software guide - typedef otb::PrintableImageFilter<ImageType,ImageType> PrintFilterType; - typedef PrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<ImageType, ImageType> PrintFilterType; + typedef PrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; - PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); - PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); PrintFilterType::Pointer invertOutputPrintFilter = PrintFilterType::New(); - VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); inputPrintFilter->SetInput(reader->GetOutput()); inputPrintFilter->SetChannel(5); diff --git a/Examples/DimensionReduction/MNFExample.cxx b/Examples/DimensionReduction/MNFExample.cxx index 10ef4a15ccb41744535296afd6cd17d3ca157d10..0299f602f7bfeadad31fa628c9511eb0d16cfb6f 100644 --- a/Examples/DimensionReduction/MNFExample.cxx +++ b/Examples/DimensionReduction/MNFExample.cxx @@ -23,14 +23,19 @@ #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {wv2_cannes_8bands.tif} -// OUTPUTS: {MNFOutput.tif}, {InverseMNFOutput.tif}, {MNF-input-pretty.png}, {MNF-output-pretty.png}, {MNF-invoutput-pretty.png} -// 8 1 1 -// Software Guide : EndCommandLineArgs +/* Example usage: +./MNFExample Input/wv2_cannes_8bands.tif \ + Output/MNFOutput.tif \ + Output/InverseMNFOutput.tif \ + Output/MNF-input-pretty.png \ + Output/MNF-output-pretty.png \ + Output/MNF-invoutput-pretty.png \ + 8 \ + 1 \ + 1 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{MNFImageFilter}. This filter computes a Maximum // Noise Fraction transform \cite{green1988transformation} using an @@ -49,65 +54,43 @@ // In this implementation, noise is estimated from a local window. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMNFImageFilter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // We also need to include the header of the noise filter. // // SoftwareGuide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbLocalActivityVectorImageFilter.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - typedef double PixelType; - const unsigned int Dimension = 2; - const char * inputFileName = argv[1]; - const char * outputFilename = argv[2]; - const char * outputInverseFilename = argv[3]; + typedef double PixelType; + const unsigned int Dimension = 2; + const char* inputFileName = argv[1]; + const char* outputFilename = argv[2]; + const char* outputInverseFilename = argv[3]; const unsigned int numberOfPrincipalComponentsRequired(atoi(argv[7])); - const char * inpretty = argv[4]; - const char * outpretty = argv[5]; - const char * invoutpretty = argv[6]; - unsigned int vradius = atoi(argv[8]); - bool normalization = atoi(argv[9]); + const char* inpretty = argv[4]; + const char* outpretty = argv[5]; + const char* invoutpretty = argv[6]; + unsigned int vradius = atoi(argv[8]); + bool normalization = atoi(argv[9]); - // Software Guide : BeginLatex - // // We start by defining the types for the images, the reader, and // the writer. We choose to work with a \doxygen{otb}{VectorImage}, // since we will produce a multi-channel image (the principal // components) from a multi-channel input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We instantiate now the image reader and we set the image file name. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // In contrast with standard Principal Component Analysis, MNF // needs an estimation of the noise correlation matrix // in the dataset prior to transformation. @@ -120,118 +103,68 @@ int main(int itkNotUsed(argc), char* argv[]) // // In this implementation, noise is estimated from a local window. // We define the type of the noise filter. - // - // Software Guide : EndLatex // SoftwareGuide : BeginCodeSnippet - typedef otb::LocalActivityVectorImageFilter<ImageType,ImageType> NoiseFilterType; + typedef otb::LocalActivityVectorImageFilter<ImageType, ImageType> NoiseFilterType; // SoftwareGuide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type for the filter. It is templated over the input // and the output image types and also the transformation direction. The // internal structure of this filter is a filter-to-filter like structure. // We can now the instantiate the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MNFImageFilter<ImageType, ImageType, - NoiseFilterType, - otb::Transform::FORWARD> MNFFilterType; - MNFFilterType::Pointer MNFfilter = MNFFilterType::New(); - // Software Guide : EndCodeSnippet + typedef otb::MNFImageFilter<ImageType, ImageType, NoiseFilterType, otb::Transform::FORWARD> MNFFilterType; + MNFFilterType::Pointer MNFfilter = MNFFilterType::New(); - // Software Guide : BeginLatex - // // We then set the number of principal // components required as output. We can choose to get less PCs than // the number of input bands. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - MNFfilter->SetNumberOfPrincipalComponentsRequired( - numberOfPrincipalComponentsRequired); - // Software Guide : EndCodeSnippet + MNFfilter->SetNumberOfPrincipalComponentsRequired(numberOfPrincipalComponentsRequired); - // Software Guide : BeginLatex - // // We set the radius of the sliding window for noise estimation. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - NoiseFilterType::RadiusType radius = {{ vradius, vradius }}; + NoiseFilterType::RadiusType radius = {{vradius, vradius}}; MNFfilter->GetNoiseImageFilter()->SetRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Last, we can activate normalisation. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - MNFfilter->SetUseNormalization( normalization ); - // Software Guide : EndCodeSnippet + MNFfilter->SetUseNormalization(normalization); - // Software Guide : BeginLatex - // // We now instantiate the writer and set the file name for the // output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We finally plug the pipeline and trigger the MNF computation with // the method \code{Update()} of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet MNFfilter->SetInput(reader->GetOutput()); writer->SetInput(MNFfilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // \doxygen{otb}{MNFImageFilter} allows also to compute inverse // transformation from MNF coefficients. In reverse mode, the // covariance matrix or the transformation matrix // (which may not be square) has to be given. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::MNFImageFilter< ImageType, ImageType, - NoiseFilterType, - otb::Transform::INVERSE > InvMNFFilterType; - InvMNFFilterType::Pointer invFilter = InvMNFFilterType::New(); - - invFilter->SetMeanValues( MNFfilter->GetMeanValues() ); - if ( normalization ) - invFilter->SetStdDevValues( MNFfilter->GetStdDevValues() ); - invFilter->SetTransformationMatrix( MNFfilter->GetTransformationMatrix() ); + + typedef otb::MNFImageFilter<ImageType, ImageType, NoiseFilterType, otb::Transform::INVERSE> InvMNFFilterType; + InvMNFFilterType::Pointer invFilter = InvMNFFilterType::New(); + + invFilter->SetMeanValues(MNFfilter->GetMeanValues()); + if (normalization) + invFilter->SetStdDevValues(MNFfilter->GetStdDevValues()); + invFilter->SetTransformationMatrix(MNFfilter->GetTransformationMatrix()); invFilter->SetInput(MNFfilter->GetOutput()); WriterType::Pointer invWriter = WriterType::New(); - invWriter->SetFileName(outputInverseFilename ); - invWriter->SetInput(invFilter->GetOutput() ); + invWriter->SetFileName(outputInverseFilename); + invWriter->SetInput(invFilter->GetOutput()); invWriter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:MNF_FILTER} shows the result of applying forward // and reverse MNF transformation to a 8 bands Worldview2 image. // \begin{figure} @@ -247,20 +180,18 @@ int main(int itkNotUsed(argc), char* argv[]) // inverse mode (the input RGB image).} // \label{fig:MNF_FILTER} // \end{figure} - // - // Software Guide : EndLatex // This is for rendering in software guide - typedef otb::PrintableImageFilter<ImageType,ImageType> PrintFilterType; - typedef PrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<ImageType, ImageType> PrintFilterType; + typedef PrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; - PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); - PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); PrintFilterType::Pointer invertOutputPrintFilter = PrintFilterType::New(); - VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); inputPrintFilter->SetInput(reader->GetOutput()); inputPrintFilter->SetChannel(5); diff --git a/Examples/DimensionReduction/MaximumAutocorrelationFactor.cxx b/Examples/DimensionReduction/MaximumAutocorrelationFactor.cxx index 55fad11aa574d450f12a740b999cf70f9e65fd88..5de6d9be0357f2079b647bc140a1dc339982024d 100644 --- a/Examples/DimensionReduction/MaximumAutocorrelationFactor.cxx +++ b/Examples/DimensionReduction/MaximumAutocorrelationFactor.cxx @@ -23,13 +23,11 @@ #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {wv2_cannes_8bands.tif} -// OUTPUTS: {MAFOutput.tif}, {maf-input.png}, {maf-output.png} -// -// Software Guide : EndCommandLineArgs +/* Example usage: +./MaximumAutocorrelationFactor Input/wv2_cannes_8bands.tif Output/MAFOutput.tif Output/maf-input.png Output/maf-output.png +*/ + -// Software Guide : BeginLatex // This example illustrates the class // \doxygen{otb}{MaximumAutocorrelationFactorImageFilter}, which // performs a Maximum Autocorrelation Factor transform \cite{nielsen2011kernel}. Like @@ -43,113 +41,69 @@ // Please note that the inverse transform is not implemented yet. // // We start by including the corresponding header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMaximumAutocorrelationFactorImageFilter.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - char * infname = argv[1]; - char * outfname = argv[2]; - char * inpretty = argv[3]; - char * outpretty = argv[4]; + char* infname = argv[1]; + char* outfname = argv[2]; + char* inpretty = argv[3]; + char* outpretty = argv[4]; - // Software Guide : BeginLatex // We then define the types for the input image and the // output image. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<unsigned short, 2> InputImageType; typedef otb::VectorImage<double, 2> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now declare the types for the reader. Since the images // can be very large, we will force the pipeline to use // streaming. For this purpose, the file writer will be // streamed. This is achieved by using the // \doxygen{otb}{ImageFileWriter} class. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // SoftwareGuide : BeginLatex // The \doxygen{otb}{MultivariateAlterationDetectorImageFilter} is templated over // the type of the input images and the type of the generated change // image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MaximumAutocorrelationFactorImageFilter<InputImageType, - OutputImageType> FilterType; - // Software Guide : EndCodeSnippet + typedef otb::MaximumAutocorrelationFactorImageFilter<InputImageType, OutputImageType> FilterType; - // Software Guide : BeginLatex - // // The different elements of the pipeline can now be instantiated. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We set the parameters of the different elements of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(infname); writer->SetFileName(outfname); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We build the pipeline by plugging all the elements together. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And then we can trigger the pipeline update, as usual. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); - // Software Guide : EndCodeSnippet // This is for rendering in software guide - typedef otb::PrintableImageFilter<InputImageType,InputImageType> InputPrintFilterType; - typedef otb::PrintableImageFilter<OutputImageType,OutputImageType> OutputPrintFilterType; - typedef InputPrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<InputImageType, InputImageType> InputPrintFilterType; + typedef otb::PrintableImageFilter<OutputImageType, OutputImageType> OutputPrintFilterType; + typedef InputPrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; - InputPrintFilterType::Pointer inputPrintFilter = InputPrintFilterType::New(); + InputPrintFilterType::Pointer inputPrintFilter = InputPrintFilterType::New(); OutputPrintFilterType::Pointer outputPrintFilter = OutputPrintFilterType::New(); - VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); inputPrintFilter->SetInput(reader->GetOutput()); inputPrintFilter->SetChannel(5); @@ -169,7 +123,6 @@ int main(int itkNotUsed(argc), char* argv[]) inputVisuWriter->Update(); outputVisuWriter->Update(); - // Software Guide : BeginLatex // Figure \ref{fig:MAFFIG} shows the // results of Maximum Autocorrelation Factor applied to an 8 bands // Worldview2 image. @@ -180,7 +133,6 @@ int main(int itkNotUsed(argc), char* argv[]) // Maximum Autocorrelation Factor algorithm applied to a 8 bands // Worldview2 image (3 first components).} \label{fig:MAFFIG} // \end{figure} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/DimensionReduction/NAPCAExample.cxx b/Examples/DimensionReduction/NAPCAExample.cxx index 01ce8b14695ad2650106ea9b67b4c5bffd7dd912..b4f479eaa4b462dfb1709965322641e489747afd 100644 --- a/Examples/DimensionReduction/NAPCAExample.cxx +++ b/Examples/DimensionReduction/NAPCAExample.cxx @@ -23,14 +23,19 @@ #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {wv2_cannes_8bands.tif} -// OUTPUTS: {NAPCAOutput.tif}, {InverseNAPCAOutput.tif}, {napca-input-pretty.png}, {napca-output-pretty.png}, {napca-invoutput-pretty.png} -// 8 1 1 -// Software Guide : EndCommandLineArgs +/* Example usage: +./NAPCAExample Input/wv2_cannes_8bands.tif \ + Output/NAPCAOutput.tif \ + Output/InverseNAPCAOutput.tif \ + Output/napca-input-pretty.png \ + Output/napca-output-pretty.png \ + Output/napca-invoutput-pretty.png \ + 8 \ + 1 \ + 1 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{NAPCAImageFilter}. This filter computes a Noise-Adjusted // Principal Component Analysis transform \cite{lee1990enhancement} using an @@ -50,65 +55,43 @@ // It is basically a reformulation of the Maximum Noise Fraction algorithm. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbNAPCAImageFilter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // We also need to include the header of the noise filter. // // SoftwareGuide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbLocalActivityVectorImageFilter.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - typedef double PixelType; - const unsigned int Dimension = 2; - const char * inputFileName = argv[1]; - const char * outputFilename = argv[2]; - const char * outputInverseFilename = argv[3]; + typedef double PixelType; + const unsigned int Dimension = 2; + const char* inputFileName = argv[1]; + const char* outputFilename = argv[2]; + const char* outputInverseFilename = argv[3]; const unsigned int numberOfPrincipalComponentsRequired(atoi(argv[7])); - const char * inpretty = argv[4]; - const char * outpretty = argv[5]; - const char * invoutpretty = argv[6]; - unsigned int vradius = atoi(argv[8]); - bool normalization = atoi(argv[9]); + const char* inpretty = argv[4]; + const char* outpretty = argv[5]; + const char* invoutpretty = argv[6]; + unsigned int vradius = atoi(argv[8]); + bool normalization = atoi(argv[9]); - // Software Guide : BeginLatex - // // We start by defining the types for the images, the reader and // the writer. We choose to work with a \doxygen{otb}{VectorImage}, // since we will produce a multi-channel image (the principal // components) from a multi-channel input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We instantiate now the image reader and we set the image file name. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // In contrast with standard Principal Component Analysis, NA-PCA // needs an estimation of the noise correlation matrix // in the dataset prior to transformation. @@ -121,119 +104,69 @@ int main(int itkNotUsed(argc), char* argv[]) // // In this implementation, noise is estimated from a local window. // We define the type of the noise filter. - // - // Software Guide : EndLatex // SoftwareGuide : BeginCodeSnippet - typedef otb::LocalActivityVectorImageFilter<ImageType,ImageType> NoiseFilterType; + typedef otb::LocalActivityVectorImageFilter<ImageType, ImageType> NoiseFilterType; // SoftwareGuide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type for the filter. It is templated over the input // and the output image types, the noise estimation filter type, // and also the transformation direction. The // internal structure of this filter is a filter-to-filter like structure. // We can now the instantiate the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::NAPCAImageFilter<ImageType, ImageType, - NoiseFilterType, - otb::Transform::FORWARD> NAPCAFilterType; - NAPCAFilterType::Pointer napcafilter = NAPCAFilterType::New(); - // Software Guide : EndCodeSnippet + typedef otb::NAPCAImageFilter<ImageType, ImageType, NoiseFilterType, otb::Transform::FORWARD> NAPCAFilterType; + NAPCAFilterType::Pointer napcafilter = NAPCAFilterType::New(); - // Software Guide : BeginLatex - // // We then set the number of principal // components required as output. We can choose to get less PCs than // the number of input bands. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - napcafilter->SetNumberOfPrincipalComponentsRequired( - numberOfPrincipalComponentsRequired); - // Software Guide : EndCodeSnippet + napcafilter->SetNumberOfPrincipalComponentsRequired(numberOfPrincipalComponentsRequired); - // Software Guide : BeginLatex - // // We set the radius of the sliding window for noise estimation. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - NoiseFilterType::RadiusType radius = {{ vradius, vradius }}; + NoiseFilterType::RadiusType radius = {{vradius, vradius}}; napcafilter->GetNoiseImageFilter()->SetRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Last, we can activate normalisation. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - napcafilter->SetUseNormalization( normalization ); - // Software Guide : EndCodeSnippet + napcafilter->SetUseNormalization(normalization); - // Software Guide : BeginLatex - // // We now instantiate the writer and set the file name for the // output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We finally plug the pipeline and trigger the NA-PCA computation with // the method \code{Update()} of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet napcafilter->SetInput(reader->GetOutput()); writer->SetInput(napcafilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // \doxygen{otb}{NAPCAImageFilter} allows also to compute inverse // transformation from NA-PCA coefficients. In reverse mode, the // covariance matrix or the transformation matrix // (which may not be square) has to be given. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::NAPCAImageFilter< ImageType, ImageType, - NoiseFilterType, - otb::Transform::INVERSE > InvNAPCAFilterType; - InvNAPCAFilterType::Pointer invFilter = InvNAPCAFilterType::New(); - - invFilter->SetMeanValues( napcafilter->GetMeanValues() ); - if ( normalization ) - invFilter->SetStdDevValues( napcafilter->GetStdDevValues() ); - invFilter->SetTransformationMatrix( napcafilter->GetTransformationMatrix() ); + + typedef otb::NAPCAImageFilter<ImageType, ImageType, NoiseFilterType, otb::Transform::INVERSE> InvNAPCAFilterType; + InvNAPCAFilterType::Pointer invFilter = InvNAPCAFilterType::New(); + + invFilter->SetMeanValues(napcafilter->GetMeanValues()); + if (normalization) + invFilter->SetStdDevValues(napcafilter->GetStdDevValues()); + invFilter->SetTransformationMatrix(napcafilter->GetTransformationMatrix()); invFilter->SetInput(napcafilter->GetOutput()); WriterType::Pointer invWriter = WriterType::New(); - invWriter->SetFileName(outputInverseFilename ); - invWriter->SetInput(invFilter->GetOutput() ); + invWriter->SetFileName(outputInverseFilename); + invWriter->SetInput(invFilter->GetOutput()); invWriter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:NAPCA_FILTER} shows the result of applying forward // and reverse NA-PCA transformation to a 8 bands Worldview2 image. // \begin{figure} @@ -249,20 +182,18 @@ int main(int itkNotUsed(argc), char* argv[]) // inverse mode (the input RGB image).} // \label{fig:NAPCA_FILTER} // \end{figure} - // - // Software Guide : EndLatex // This is for rendering in software guide - typedef otb::PrintableImageFilter<ImageType,ImageType> PrintFilterType; - typedef PrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<ImageType, ImageType> PrintFilterType; + typedef PrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; - PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); - PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); PrintFilterType::Pointer invertOutputPrintFilter = PrintFilterType::New(); - VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); inputPrintFilter->SetInput(reader->GetOutput()); inputPrintFilter->SetChannel(5); diff --git a/Examples/DimensionReduction/PCAExample.cxx b/Examples/DimensionReduction/PCAExample.cxx index cae8f80e408860431fd7f518a0ef9df3bb4a31e1..581c9f6b97e37497a1dd14385179f7b1812a3e4e 100644 --- a/Examples/DimensionReduction/PCAExample.cxx +++ b/Examples/DimensionReduction/PCAExample.cxx @@ -23,14 +23,17 @@ #include "otbImageFileWriter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {wv2_cannes_8bands.tif} -// OUTPUTS: {PCAOutput.tif}, {InversePCAOutput.tif}, {input-pretty.png}, {output-pretty.png}, {invoutput-pretty.png} -// 8 -// Software Guide : EndCommandLineArgs +/* Example usage: +./PCAExample Input/wv2_cannes_8bands.tif \ + Output/PCAOutput.tif \ + Output/InversePCAOutput.tif \ + Output/input-pretty.png \ + Output/output-pretty.png \ + Output/invoutput-pretty.png \ + 8 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{PCAImageFilter}. // This filter computes a Principal Component Analysis using an @@ -38,129 +41,79 @@ // covariance matrix. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbPCAImageFilter.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - typedef double PixelType; - const unsigned int Dimension = 2; - const char * inputFileName = argv[1]; - const char * outputFilename = argv[2]; - const char * outputInverseFilename = argv[3]; + typedef double PixelType; + const unsigned int Dimension = 2; + const char* inputFileName = argv[1]; + const char* outputFilename = argv[2]; + const char* outputInverseFilename = argv[3]; const unsigned int numberOfPrincipalComponentsRequired(atoi(argv[7])); - const char * inpretty = argv[4]; - const char * outpretty = argv[5]; - const char * invoutpretty = argv[6]; + const char* inpretty = argv[4]; + const char* outpretty = argv[5]; + const char* invoutpretty = argv[6]; - // Software Guide : BeginLatex - // // We start by defining the types for the images and the reader and // the writer. We choose to work with a \doxygen{otb}{VectorImage}, // since we will produce a multi-channel image (the principal // components) from a multi-channel input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We instantiate now the image reader and we set the image file name. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type for the filter. It is templated over the input // and the output image types and also the transformation direction. The // internal structure of this filter is a filter-to-filter like structure. // We can now the instantiate the filter. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::PCAImageFilter<ImageType, ImageType, - otb::Transform::FORWARD> PCAFilterType; - PCAFilterType::Pointer pcafilter = PCAFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef otb::PCAImageFilter<ImageType, ImageType, otb::Transform::FORWARD> PCAFilterType; + PCAFilterType::Pointer pcafilter = PCAFilterType::New(); // The only parameter needed for the PCA is the number of principal // components required as output. Principal components are linear combination of input components // (here the input image bands), // which are selected using Singular Value Decomposition eigen vectors sorted by eigen value. // We can choose to get less Principal Components than // the number of input bands. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - pcafilter->SetNumberOfPrincipalComponentsRequired( - numberOfPrincipalComponentsRequired); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + pcafilter->SetNumberOfPrincipalComponentsRequired(numberOfPrincipalComponentsRequired); // We now instantiate the writer and set the file name for the // output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We finally plug the pipeline and trigger the PCA computation with // the method \code{Update()} of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet pcafilter->SetInput(reader->GetOutput()); writer->SetInput(pcafilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // \doxygen{otb}{PCAImageFilter} allows also to compute inverse // transformation from PCA coefficients. In reverse mode, the // covariance matrix or the transformation matrix // (which may not be square) has to be given. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::PCAImageFilter< ImageType, ImageType, - otb::Transform::INVERSE > InvPCAFilterType; - InvPCAFilterType::Pointer invFilter = InvPCAFilterType::New(); + typedef otb::PCAImageFilter<ImageType, ImageType, otb::Transform::INVERSE> InvPCAFilterType; + InvPCAFilterType::Pointer invFilter = InvPCAFilterType::New(); invFilter->SetInput(pcafilter->GetOutput()); invFilter->SetTransformationMatrix(pcafilter->GetTransformationMatrix()); WriterType::Pointer invWriter = WriterType::New(); - invWriter->SetFileName(outputInverseFilename ); - invWriter->SetInput(invFilter->GetOutput() ); + invWriter->SetFileName(outputInverseFilename); + invWriter->SetInput(invFilter->GetOutput()); invWriter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:PCA_FILTER} shows the result of applying forward // and reverse PCA transformation to a 8 bands Worldview2 image. // \begin{figure} @@ -176,20 +129,18 @@ int main(int itkNotUsed(argc), char* argv[]) // inverse mode (the input RGB image).} // \label{fig:PCA_FILTER} // \end{figure} - // - // Software Guide : EndLatex // This is for rendering in software guide - typedef otb::PrintableImageFilter<ImageType,ImageType> PrintFilterType; - typedef PrintFilterType::OutputImageType VisuImageType; - typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; + typedef otb::PrintableImageFilter<ImageType, ImageType> PrintFilterType; + typedef PrintFilterType::OutputImageType VisuImageType; + typedef otb::ImageFileWriter<VisuImageType> VisuWriterType; - PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); - PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer inputPrintFilter = PrintFilterType::New(); + PrintFilterType::Pointer outputPrintFilter = PrintFilterType::New(); PrintFilterType::Pointer invertOutputPrintFilter = PrintFilterType::New(); - VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); - VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer inputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer outputVisuWriter = VisuWriterType::New(); + VisuWriterType::Pointer invertOutputVisuWriter = VisuWriterType::New(); inputPrintFilter->SetInput(reader->GetOutput()); inputPrintFilter->SetChannel(5); diff --git a/Examples/DisparityMap/FineRegistrationImageFilterExample.cxx b/Examples/DisparityMap/FineRegistrationImageFilterExample.cxx index 97fa5a36fd086b38136b6780ade8194f39272938..9acb897791a38a67017a50f518b2f0680d1a7338 100644 --- a/Examples/DisparityMap/FineRegistrationImageFilterExample.cxx +++ b/Examples/DisparityMap/FineRegistrationImageFilterExample.cxx @@ -19,27 +19,39 @@ */ +/* Example usage: +./FineRegistrationImageFilterExample Input/StereoFixed.png \ + Input/StereoMoving.png \ + Output/fcDisplacementFieldOutput-horizontal.png \ + Output/fcDisplacementFieldOutput-vertical.png \ + Output/fcCorrelFieldOutput.png \ + Output/fcDResampledOutput2.png \ + 1.0 \ + 5 \ + 3 \ + 0.1 +*/ + + +/* Example usage: +./FineRegistrationImageFilterExample Input/StereoFixed.png \ + Input/StereoMoving.png \ + Output/fcMRSDDisplacementFieldOutput-horizontal.png \ + Output/fcMRSDDisplacementFieldOutput-vertical.png \ + Output/fcMRSDCorrelFieldOutput.png \ + Output/fcMRSDDResampledOutput2.png \ + 1.0 \ + 5 \ + 3 \ + 0.1 \ + mrsd +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {StereoFixed.png}, {StereoMoving.png} -// OUTPUTS: {fcDisplacementFieldOutput-horizontal.png}, {fcDisplacementFieldOutput-vertical.png}, {fcCorrelFieldOutput.png}, {fcDResampledOutput2.png} -// 1.0 5 3 0.1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {StereoFixed.png}, {StereoMoving.png} -// OUTPUTS: {fcMRSDDisplacementFieldOutput-horizontal.png}, {fcMRSDDisplacementFieldOutput-vertical.png}, {fcMRSDCorrelFieldOutput.png}, {fcMRSDDResampledOutput2.png} -// 1.0 5 3 0.1 mrsd -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// // This example demonstrates the use of the \doxygen{otb}{FineRegistrationImageFilter}. This filter performs deformation estimation // using the classical extrema of image-to-image metric look-up in a search window. // // The first step toward the use of these filters is to include the proper header files. -// -// Software Guide : EndLatex #include "otbImageFileWriter.h" #include "otbImageFileReader.h" @@ -48,9 +60,7 @@ #include "itkWarpImageFilter.h" #include "itkMeanReciprocalSquareDifferenceImageToImageMetric.h" -// Software Guide : BeginCodeSnippet #include "otbFineRegistrationImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageOfVectorsToMonoChannelExtractROI.h" #include "itkRescaleIntensityImageFilter.h" @@ -62,14 +72,13 @@ int main(int argc, char** argv) { if (argc < 11) - { + { std::cerr << "Usage: " << argv[0]; - std::cerr << - " fixedFileName movingFileName fieldOutNameHorizontal fieldOutNameVertical fieldMetric warped "; + std::cerr << " fixedFileName movingFileName fieldOutNameHorizontal fieldOutNameVertical fieldMetric warped "; std::cerr << "smoothingSigma metricRadius explorationRadius subpixelPrecision"; return EXIT_FAILURE; - } + } const unsigned int ImageDimension = 2; @@ -79,40 +88,27 @@ int main(int argc, char** argv) typedef unsigned char OutputPixelType; typedef otb::Image<OutputPixelType, ImageDimension> OutputImageType; - // Software Guide : BeginLatex - // // Several type of \doxygen{otb}{Image} are required to represent the input image, the metric field, // and the deformation field. - // - // Software Guide : EndLatex - //Allocate Images - // Software Guide : BeginCodeSnippet - typedef otb::Image<PixelType, ImageDimension> InputImageType; - typedef otb::Image<PixelType, ImageDimension> MetricImageType; - typedef otb::Image<DisplacementPixelType, - ImageDimension> DisplacementFieldType; - // Software Guide : EndCodeSnippet + // Allocate Images + typedef otb::Image<PixelType, ImageDimension> InputImageType; + typedef otb::Image<PixelType, ImageDimension> MetricImageType; + typedef otb::Image<DisplacementPixelType, ImageDimension> DisplacementFieldType; typedef otb::ImageFileReader<InputImageType> InputReaderType; - InputReaderType::Pointer fReader = InputReaderType::New(); + InputReaderType::Pointer fReader = InputReaderType::New(); fReader->SetFileName(argv[1]); InputReaderType::Pointer mReader = InputReaderType::New(); mReader->SetFileName(argv[2]); - // Software Guide : BeginLatex - // // To make the metric estimation more robust, the first // required step is to blur the input images. This is done using the // \doxygen{itk}{RecursiveGaussianImageFilter}: - // - // Software Guide : EndLatex - //Blur input images - // Software Guide : BeginCodeSnippet - typedef itk::RecursiveGaussianImageFilter<InputImageType, - InputImageType> InputBlurType; + // Blur input images + typedef itk::RecursiveGaussianImageFilter<InputImageType, InputImageType> InputBlurType; InputBlurType::Pointer fBlur = InputBlurType::New(); fBlur->SetInput(fReader->GetOutput()); @@ -121,36 +117,21 @@ int main(int argc, char** argv) InputBlurType::Pointer mBlur = InputBlurType::New(); mBlur->SetInput(mReader->GetOutput()); mBlur->SetSigma(atof(argv[7])); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now, we declare and instantiate the \doxygen{otb}{FineRegistrationImageFilter} which is going to perform the registration: - // - // Software Guide : EndLatex - //Create the filter - // Software Guide : BeginCodeSnippet - typedef otb::FineRegistrationImageFilter<InputImageType, - MetricImageType, - DisplacementFieldType> - RegistrationFilterType; + // Create the filter + typedef otb::FineRegistrationImageFilter<InputImageType, MetricImageType, DisplacementFieldType> RegistrationFilterType; RegistrationFilterType::Pointer registrator = RegistrationFilterType::New(); registrator->SetMovingInput(mBlur->GetOutput()); registrator->SetFixedInput(fBlur->GetOutput()); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Some parameters need to be specified to the filter: // \begin{itemize} // \item The area where the search is performed. This area is defined by its radius: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef RegistrationFilterType::SizeType RadiusType; RadiusType searchRadius; @@ -159,86 +140,54 @@ int main(int argc, char** argv) searchRadius[1] = atoi(argv[8]); registrator->SetSearchRadius(searchRadius); -// Software Guide : EndCodeSnippet std::cout << "Exploration radius " << registrator->GetSearchRadius() << std::endl; - // Software Guide : BeginLatex - // // \item The window used to compute the local metric. This window is also defined by its radius: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet RadiusType metricRadius; metricRadius[0] = atoi(argv[9]); metricRadius[1] = atoi(argv[9]); registrator->SetRadius(metricRadius); -// Software Guide : EndCodeSnippet std::cout << "Metric radius " << registrator->GetRadius() << std::endl; - // Software Guide : BeginLatex - // // We need to set the sub-pixel accuracy we want to obtain: - // - // Software Guide : EndLatex registrator->SetConvergenceAccuracy(atof(argv[10])); - // Software Guide : BeginLatex - // // The default matching metric used by the \doxygen{otb}{FineRegistrationImageFilter} is standard correlation. // However, we may also use any other image-to-image metric provided by ITK. For instance, here is how we // would use the \doxygen{itk}{MutualInformationImageToImageMetric} (do not forget to include the proper header). - // - // Software Guide : EndLatex - - if(argc > 11) - { - // Software Guide : BeginCodeSnippet - typedef itk::MeanReciprocalSquareDifferenceImageToImageMetric - <InputImageType, InputImageType> MRSDMetricType; - MRSDMetricType::Pointer mrsdMetric = MRSDMetricType::New(); - registrator->SetMetric(mrsdMetric); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // The \doxygen{itk}{MutualInformationImageToImageMetric} produces low value for poor matches, therefore, the filter has - // to maximize the metric : - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - registrator->MinimizeOff(); - // Software Guide : EndCodeSnippet - } - - - // Software Guide : BeginLatex - // + + if (argc > 11) + { + typedef itk::MeanReciprocalSquareDifferenceImageToImageMetric<InputImageType, InputImageType> MRSDMetricType; + MRSDMetricType::Pointer mrsdMetric = MRSDMetricType::New(); + registrator->SetMetric(mrsdMetric); + + // The \doxygen{itk}{MutualInformationImageToImageMetric} produces low value for poor matches, therefore, the filter has + // to maximize the metric : + + registrator->MinimizeOff(); + } + + // \end{itemize} // The execution of the \doxygen{otb}{FineRegistrationImageFilter} will be triggered by // the \code{Update()} call on the writer at the end of the // pipeline. Make sure to use a // \doxygen{otb}{ImageFileWriter} if you want to benefit // from the streaming features. - // - // Software Guide : EndLatex - typedef otb::ImageOfVectorsToMonoChannelExtractROI<DisplacementFieldType, - InputImageType> - ChannelExtractionFilterType; - ChannelExtractionFilterType::Pointer channelExtractor = - ChannelExtractionFilterType::New(); + typedef otb::ImageOfVectorsToMonoChannelExtractROI<DisplacementFieldType, InputImageType> ChannelExtractionFilterType; + ChannelExtractionFilterType::Pointer channelExtractor = ChannelExtractionFilterType::New(); channelExtractor->SetInput(registrator->GetOutputDisplacementField()); channelExtractor->SetChannel(1); - typedef itk::RescaleIntensityImageFilter<InputImageType, - OutputImageType> RescalerType; - RescalerType::Pointer fieldRescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> RescalerType; + RescalerType::Pointer fieldRescaler = RescalerType::New(); fieldRescaler->SetInput(channelExtractor->GetOutput()); fieldRescaler->SetOutputMaximum(255); @@ -255,9 +204,8 @@ int main(int argc, char** argv) dfWriter->SetFileName(argv[4]); dfWriter->Update(); - typedef itk::WarpImageFilter<InputImageType, InputImageType, - DisplacementFieldType> WarperType; - WarperType::Pointer warper = WarperType::New(); + typedef itk::WarpImageFilter<InputImageType, InputImageType, DisplacementFieldType> WarperType; + WarperType::Pointer warper = WarperType::New(); InputImageType::PixelType padValue = 4.0; @@ -265,8 +213,7 @@ int main(int argc, char** argv) warper->SetDisplacementField(registrator->GetOutputDisplacementField()); warper->SetEdgePaddingValue(padValue); - typedef itk::RescaleIntensityImageFilter<MetricImageType, - OutputImageType> MetricRescalerType; + typedef itk::RescaleIntensityImageFilter<MetricImageType, OutputImageType> MetricRescalerType; MetricRescalerType::Pointer metricRescaler = MetricRescalerType::New(); metricRescaler->SetInput(registrator->GetOutput()); @@ -281,7 +228,7 @@ int main(int argc, char** argv) writer1->Update(); typedef itk::CastImageFilter<InputImageType, OutputImageType> CastFilterType; - CastFilterType::Pointer caster = CastFilterType::New(); + CastFilterType::Pointer caster = CastFilterType::New(); caster->SetInput(warper->GetOutput()); @@ -290,8 +237,6 @@ int main(int argc, char** argv) writer2->SetInput(caster->GetOutput()); writer2->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:FineCorrelationImageFilterOUTPUT} shows the result of // applying the \doxygen{otb}{FineRegistrationImageFilter}. // @@ -314,9 +259,6 @@ int main(int argc, char** argv) // } // \label{fig:FineCorrelationImageFilterOUTPUT} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/DisparityMap/NCCRegistrationFilterExample.cxx b/Examples/DisparityMap/NCCRegistrationFilterExample.cxx index 1b604564c791d8d4139f5c0dd2bd4336d1bc471a..3e30f466609364e9a84a0304a500ca9036d0defc 100644 --- a/Examples/DisparityMap/NCCRegistrationFilterExample.cxx +++ b/Examples/DisparityMap/NCCRegistrationFilterExample.cxx @@ -19,30 +19,29 @@ */ +/* Example usage: +./NCCRegistrationFilterExample Input/StereoFixed.png \ + Input/StereoMoving.png \ + Output/deformationFieldOutput-horizontal.png \ + Output/deformationFieldOutput-vertical.png \ + Output/resampledOutput2.png \ + 5 \ + 1.0 \ + 2 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {StereoFixed.png}, {StereoMoving.png} -// OUTPUTS: {deformationFieldOutput-horizontal.png}, {deformationFieldOutput-vertical.png}, {resampledOutput2.png} -// 5 1.0 2 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example demonstrates the use of the \doxygen{otb}{NCCRegistrationFilter}. This filter performs deformation estimation // by optimising a PDE based on the normalized correlation coefficient. It uses the finite difference solver hierarchy. // // The first step toward the use of these filters is to include the proper header files. -// -// Software Guide : EndLatex #include "otbImageFileWriter.h" #include "otbImageFileReader.h" -// Software Guide : BeginCodeSnippet #include "otbNCCRegistrationFilter.h" #include "itkRecursiveGaussianImageFilter.h" #include "itkWarpImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageOfVectorsToMonoChannelExtractROI.h" #include "itkUnaryFunctorImageFilter.h" @@ -55,14 +54,13 @@ int main(int argc, char** argv) { if (argc != 9) - { + { std::cerr << "Usage: " << argv[0]; - std::cerr << - " fixedFileName movingFileName fieldOutNameHorizontal fieldOutNameVertical imageOutName "; + std::cerr << " fixedFileName movingFileName fieldOutNameHorizontal fieldOutNameVertical imageOutName "; std::cerr << "explorationSize bluringSigma nbIterations "; return EXIT_FAILURE; - } + } const unsigned int ImageDimension = 2; @@ -72,82 +70,53 @@ int main(int argc, char** argv) typedef unsigned char OutputPixelType; typedef otb::Image<OutputPixelType, ImageDimension> OutputImageType; - // Software Guide : BeginLatex - // // Several type of \doxygen{otb}{Image} are required to represent the reference image (fixed) // the image we want to register (moving) and the deformation field. - // - // Software Guide : EndLatex - //Allocate Images - // Software Guide : BeginCodeSnippet - typedef otb::Image<PixelType, ImageDimension> MovingImageType; - typedef otb::Image<PixelType, ImageDimension> FixedImageType; - typedef otb::Image<DisplacementPixelType, - ImageDimension> DisplacementFieldType; - // Software Guide : EndCodeSnippet + // Allocate Images + typedef otb::Image<PixelType, ImageDimension> MovingImageType; + typedef otb::Image<PixelType, ImageDimension> FixedImageType; + typedef otb::Image<DisplacementPixelType, ImageDimension> DisplacementFieldType; typedef otb::ImageFileReader<FixedImageType> FixedReaderType; - FixedReaderType::Pointer fReader = FixedReaderType::New(); + FixedReaderType::Pointer fReader = FixedReaderType::New(); fReader->SetFileName(argv[1]); typedef otb::ImageFileReader<MovingImageType> MovingReaderType; - MovingReaderType::Pointer mReader = MovingReaderType::New(); + MovingReaderType::Pointer mReader = MovingReaderType::New(); mReader->SetFileName(argv[2]); - // Software Guide : BeginLatex - // // To make the correlation estimation more robust, the first // required step is to blur the input images. This is done using the // \doxygen{itk}{RecursiveGaussianImageFilter}: - // - // Software Guide : EndLatex - //Blur input images - // Software Guide : BeginCodeSnippet - typedef itk::RecursiveGaussianImageFilter<FixedImageType, - FixedImageType> FixedBlurType; + // Blur input images + typedef itk::RecursiveGaussianImageFilter<FixedImageType, FixedImageType> FixedBlurType; FixedBlurType::Pointer fBlur = FixedBlurType::New(); fBlur->SetInput(fReader->GetOutput()); fBlur->SetSigma(std::stof(argv[7])); - typedef itk::RecursiveGaussianImageFilter<MovingImageType, - MovingImageType> MovingBlurType; + typedef itk::RecursiveGaussianImageFilter<MovingImageType, MovingImageType> MovingBlurType; MovingBlurType::Pointer mBlur = MovingBlurType::New(); mBlur->SetInput(mReader->GetOutput()); mBlur->SetSigma(std::stof(argv[7])); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now, we need to instantiate the NCCRegistrationFilter which is going to perform the registration: - // - // Software Guide : EndLatex - //Create the filter - // Software Guide : BeginCodeSnippet - typedef otb::NCCRegistrationFilter<FixedImageType, - MovingImageType, - DisplacementFieldType> - RegistrationFilterType; + // Create the filter + typedef otb::NCCRegistrationFilter<FixedImageType, MovingImageType, DisplacementFieldType> RegistrationFilterType; RegistrationFilterType::Pointer registrator = RegistrationFilterType::New(); registrator->SetMovingImage(mBlur->GetOutput()); registrator->SetFixedImage(fBlur->GetOutput()); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Some parameters need to be specified to the NCCRegistrationFilter: // \begin{itemize} // \item The area where the search is performed. This area is defined by its radius: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef RegistrationFilterType::RadiusType RadiusType; RadiusType radius; @@ -156,44 +125,29 @@ int main(int argc, char** argv) radius[1] = std::stoi(argv[6]); registrator->SetNCCRadius(radius); -// Software Guide : EndCodeSnippet std::cout << "NCC radius " << registrator->GetNCCRadius() << std::endl; - // Software Guide : BeginLatex - // // \item The number of iterations for the PDE resolution: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet registrator->SetNumberOfIterations(std::stoi(argv[8])); -// Software Guide : EndCodeSnippet -// registrator->GetDisplacementField(); + // registrator->GetDisplacementField(); - // Software Guide : BeginLatex - // // \end{itemize} // The execution of the NCCRegistrationFilter will be triggered by // the \code{Update()} call on the writer at the end of the // pipeline. Make sure to use a // \doxygen{otb}{ImageFileWriter} if you want to benefit // from the streaming features. - // - // Software Guide : EndLatex - typedef otb::ImageOfVectorsToMonoChannelExtractROI<DisplacementFieldType, - MovingImageType> - ChannelExtractionFilterType; - ChannelExtractionFilterType::Pointer channelExtractor = - ChannelExtractionFilterType::New(); + typedef otb::ImageOfVectorsToMonoChannelExtractROI<DisplacementFieldType, MovingImageType> ChannelExtractionFilterType; + ChannelExtractionFilterType::Pointer channelExtractor = ChannelExtractionFilterType::New(); channelExtractor->SetInput(registrator->GetOutput()); channelExtractor->SetChannel(1); - typedef itk::RescaleIntensityImageFilter<MovingImageType, - OutputImageType> RescalerType; - RescalerType::Pointer fieldRescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<MovingImageType, OutputImageType> RescalerType; + RescalerType::Pointer fieldRescaler = RescalerType::New(); fieldRescaler->SetInput(channelExtractor->GetOutput()); fieldRescaler->SetOutputMaximum(255); @@ -210,9 +164,8 @@ int main(int argc, char** argv) dfWriter->SetFileName(argv[4]); dfWriter->Update(); - typedef itk::WarpImageFilter<MovingImageType, MovingImageType, - DisplacementFieldType> WarperType; - WarperType::Pointer warper = WarperType::New(); + typedef itk::WarpImageFilter<MovingImageType, MovingImageType, DisplacementFieldType> WarperType; + WarperType::Pointer warper = WarperType::New(); MovingImageType::PixelType padValue = 4.0; @@ -221,7 +174,7 @@ int main(int argc, char** argv) warper->SetEdgePaddingValue(padValue); typedef itk::CastImageFilter<MovingImageType, OutputImageType> CastFilterType; - CastFilterType::Pointer caster = CastFilterType::New(); + CastFilterType::Pointer caster = CastFilterType::New(); caster->SetInput(warper->GetOutput()); typedef otb::ImageFileWriter<OutputImageType> WriterType; @@ -231,8 +184,6 @@ int main(int argc, char** argv) writer->SetInput(caster->GetOutput()); writer->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:NCCRegistrationFilterOUTPUT} shows the result of // applying the disparity map estimation. // @@ -247,9 +198,6 @@ int main(int argc, char** argv) // estimated deformation field in the horizontal direction, estimated deformation field in the vertical direction.} // \label{fig:NCCRegistrationFilterOUTPUT} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/DisparityMap/StereoReconstructionExample.cxx b/Examples/DisparityMap/StereoReconstructionExample.cxx index 4b2dd1efe66367068a546c33700e4bc88bb5bf28..50ae95d22dd6ef428020b84a48b17f375fed5237 100644 --- a/Examples/DisparityMap/StereoReconstructionExample.cxx +++ b/Examples/DisparityMap/StereoReconstructionExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./StereoReconstructionExample Input/sensor_stereo_left.tif Input/sensor_stereo_right.tif Output/elevationOutput.tif Output/elevationOutputPrintable.png 140 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {sensor_stereo_left.tif}, {sensor_stereo_right.tif} -// OUTPUTS: {elevationOutput.tif},{elevationOutputPrintable.png} -// 140 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example demonstrates the use of the stereo reconstruction chain // from an image pair. The images are assumed to come from the same sensor // but with different positions. The approach presented here has the @@ -41,10 +37,6 @@ // a pose estimate for each image. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet #include "otbStereorectificationDisplacementFieldSource.h" #include "otbStreamingWarpImageFilter.h" #include "otbBandMathImageFilter.h" @@ -61,147 +53,106 @@ #include "otbImageListToVectorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" #include "otbDEMHandler.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " sensorImage1 sensorImage2 outputDEM outputDEMPNG"; std::cerr << "averageElevation " << std::endl; return EXIT_FAILURE; - } + } - typedef otb::Image<float,2> FloatImageType; - typedef otb::VectorImage<float,2> FloatVectorImageType; + typedef otb::Image<float, 2> FloatImageType; + typedef otb::VectorImage<float, 2> FloatVectorImageType; - typedef otb::ImageFileReader - <FloatImageType> ImageReaderType; + typedef otb::ImageFileReader<FloatImageType> ImageReaderType; - typedef otb::ImageFileWriter - <FloatImageType> WriterType; + typedef otb::ImageFileWriter<FloatImageType> WriterType; - typedef unsigned char OutputPixelType; - typedef otb::Image<OutputPixelType, 2> OutputImageType; + typedef unsigned char OutputPixelType; + typedef otb::Image<OutputPixelType, 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<FloatImageType, - OutputImageType> RescalerType; + typedef itk::RescaleIntensityImageFilter<FloatImageType, OutputImageType> RescalerType; - typedef otb::ImageFileWriter - <OutputImageType> OutputWriterType; -// Software Guide : BeginLatex -// This example demonstrates the use of the following filters : -// \begin{itemize} -// \item \doxygen{otb}{StereorectificationDisplacementFieldSource} -// \item \doxygen{otb}{StreamingWarpImageFilter} -// \item \doxygen{otb}{PixelWiseBlockMatchingImageFilter} -// \item \doxygen{otb}{otbSubPixelDisparityImageFilter} -// \item \doxygen{otb}{otbDisparityMapMedianFilter} -// \item \doxygen{otb}{DisparityMapToDEMFilter} -// \end{itemize} -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef otb::StereorectificationDisplacementFieldSource - <FloatImageType,FloatVectorImageType> DisplacementFieldSourceType; - - typedef itk::Vector<double,2> DisplacementType; - typedef otb::Image<DisplacementType> DisplacementFieldType; - - typedef itk::VectorCastImageFilter - <FloatVectorImageType, - DisplacementFieldType> DisplacementFieldCastFilterType; - - typedef otb::StreamingWarpImageFilter - <FloatImageType, - FloatImageType, - DisplacementFieldType> WarpFilterType; - - typedef otb::BCOInterpolateImageFunction - <FloatImageType> BCOInterpolationType; - - typedef otb::Functor::NCCBlockMatching - <FloatImageType,FloatImageType> NCCBlockMatchingFunctorType; - - typedef otb::PixelWiseBlockMatchingImageFilter - <FloatImageType, - FloatImageType, - FloatImageType, - FloatImageType, - NCCBlockMatchingFunctorType> NCCBlockMatchingFilterType; - - typedef otb::BandMathImageFilter - <FloatImageType> BandMathFilterType; - - typedef otb::SubPixelDisparityImageFilter - <FloatImageType, - FloatImageType, - FloatImageType, - FloatImageType, - NCCBlockMatchingFunctorType> NCCSubPixelDisparityFilterType; - - typedef otb::DisparityMapMedianFilter - <FloatImageType, - FloatImageType, - FloatImageType> MedianFilterType; - - typedef otb::DisparityMapToDEMFilter - <FloatImageType, - FloatImageType, - FloatImageType, - FloatVectorImageType, - FloatImageType> DisparityToElevationFilterType; -// Software Guide : EndCodeSnippet + typedef otb::ImageFileWriter<OutputImageType> OutputWriterType; + // This example demonstrates the use of the following filters : + // \begin{itemize} + // \item \doxygen{otb}{StereorectificationDisplacementFieldSource} + // \item \doxygen{otb}{StreamingWarpImageFilter} + // \item \doxygen{otb}{PixelWiseBlockMatchingImageFilter} + // \item \doxygen{otb}{otbSubPixelDisparityImageFilter} + // \item \doxygen{otb}{otbDisparityMapMedianFilter} + // \item \doxygen{otb}{DisparityMapToDEMFilter} + // \end{itemize} + + typedef otb::StereorectificationDisplacementFieldSource<FloatImageType, FloatVectorImageType> DisplacementFieldSourceType; + + typedef itk::Vector<double, 2> DisplacementType; + typedef otb::Image<DisplacementType> DisplacementFieldType; + + typedef itk::VectorCastImageFilter<FloatVectorImageType, DisplacementFieldType> DisplacementFieldCastFilterType; + + typedef otb::StreamingWarpImageFilter<FloatImageType, FloatImageType, DisplacementFieldType> WarpFilterType; + + typedef otb::BCOInterpolateImageFunction<FloatImageType> BCOInterpolationType; + + typedef otb::Functor::NCCBlockMatching<FloatImageType, FloatImageType> NCCBlockMatchingFunctorType; + + typedef otb::PixelWiseBlockMatchingImageFilter<FloatImageType, FloatImageType, FloatImageType, FloatImageType, NCCBlockMatchingFunctorType> + NCCBlockMatchingFilterType; + + typedef otb::BandMathImageFilter<FloatImageType> BandMathFilterType; + + typedef otb::SubPixelDisparityImageFilter<FloatImageType, FloatImageType, FloatImageType, FloatImageType, NCCBlockMatchingFunctorType> + NCCSubPixelDisparityFilterType; + + typedef otb::DisparityMapMedianFilter<FloatImageType, FloatImageType, FloatImageType> MedianFilterType; + + typedef otb::DisparityMapToDEMFilter<FloatImageType, FloatImageType, FloatImageType, FloatVectorImageType, FloatImageType> DisparityToElevationFilterType; double avgElevation = atof(argv[5]); otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(avgElevation); - ImageReaderType::Pointer leftReader = ImageReaderType::New(); - ImageReaderType::Pointer rightReader = ImageReaderType::New(); + ImageReaderType::Pointer leftReader = ImageReaderType::New(); + ImageReaderType::Pointer rightReader = ImageReaderType::New(); leftReader->SetFileName(argv[1]); rightReader->SetFileName(argv[2]); -// Software Guide : BeginLatex -// The image pair is supposed to be in sensor geometry. From two images covering -// nearly the same area, one can estimate a common epipolar geometry. In this geometry, -// an altitude variation corresponds to an horizontal shift between the two images. -// The filter \doxygen{otb}{StereorectificationDisplacementFieldSource} computes the -// deformation grids for each image. -// -// These grids are sampled in epipolar geometry. They have two bands, containing -// the position offset (in physical space units) between the current epipolar -// point and the corresponding sensor point in horizontal and vertical -// direction. They can be computed at a lower resolution than sensor -// resolution. The application \code{StereoRectificationGridGenerator} also -// provides a simple tool to generate the epipolar grids for your image pair. -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + // The image pair is supposed to be in sensor geometry. From two images covering + // nearly the same area, one can estimate a common epipolar geometry. In this geometry, + // an altitude variation corresponds to an horizontal shift between the two images. + // The filter \doxygen{otb}{StereorectificationDisplacementFieldSource} computes the + // deformation grids for each image. + // + // These grids are sampled in epipolar geometry. They have two bands, containing + // the position offset (in physical space units) between the current epipolar + // point and the corresponding sensor point in horizontal and vertical + // direction. They can be computed at a lower resolution than sensor + // resolution. The application \code{StereoRectificationGridGenerator} also + // provides a simple tool to generate the epipolar grids for your image pair. + DisplacementFieldSourceType::Pointer m_DisplacementFieldSource = DisplacementFieldSourceType::New(); m_DisplacementFieldSource->SetLeftImage(leftReader->GetOutput()); m_DisplacementFieldSource->SetRightImage(rightReader->GetOutput()); m_DisplacementFieldSource->SetGridStep(4); m_DisplacementFieldSource->SetScale(1.0); - //m_DisplacementFieldSource->SetAverageElevation(avgElevation); + // m_DisplacementFieldSource->SetAverageElevation(avgElevation); m_DisplacementFieldSource->Update(); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// Then, the sensor images can be resampled in epipolar geometry, using the -// \doxygen{otb}{StreamingWarpImageFilter}. The application -// \code{GridBasedImageResampling} also gives an easy access to this filter. The user -// can choose the epipolar region to resample, as well as the resampling step -// and the interpolator. -// -// Note that the epipolar image size can be retrieved from the stereo rectification grid -// filter. -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + + // Then, the sensor images can be resampled in epipolar geometry, using the + // \doxygen{otb}{StreamingWarpImageFilter}. The application + // \code{GridBasedImageResampling} also gives an easy access to this filter. The user + // can choose the epipolar region to resample, as well as the resampling step + // and the interpolator. + // + // Note that the epipolar image size can be retrieved from the stereo rectification grid + // filter. + FloatImageType::SpacingType epipolarSpacing; epipolarSpacing[0] = 1.0; epipolarSpacing[1] = 1.0; @@ -214,14 +165,10 @@ int main(int argc, char* argv[]) epipolarOrigin[1] = 0.0; FloatImageType::PixelType defaultValue = 0; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// The deformation grids are casted into deformation fields, then the left -// and right sensor images are resampled. -// Software Guide : EndLatex + // The deformation grids are casted into deformation fields, then the left + // and right sensor images are resampled. -// Software Guide : BeginCodeSnippet DisplacementFieldCastFilterType::Pointer m_LeftDisplacementFieldCaster = DisplacementFieldCastFilterType::New(); m_LeftDisplacementFieldCaster->SetInput(m_DisplacementFieldSource->GetLeftDisplacementFieldOutput()); m_LeftDisplacementFieldCaster->GetOutput()->UpdateOutputInformation(); @@ -253,60 +200,52 @@ int main(int argc, char* argv[]) m_RightWarpImageFilter->SetOutputSpacing(epipolarSpacing); m_RightWarpImageFilter->SetOutputOrigin(epipolarOrigin); m_RightWarpImageFilter->SetEdgePaddingValue(defaultValue); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// Since the resampling produces black regions around the image, it is useless -// to estimate disparities on these \textit{no-data} regions. We use a \doxygen{otb}{BandMathImageFilter} -// to produce a mask on left and right epipolar images. -// Software Guide : EndLatex + // Since the resampling produces black regions around the image, it is useless + // to estimate disparities on these \textit{no-data} regions. We use a \doxygen{otb}{BandMathImageFilter} + // to produce a mask on left and right epipolar images. -// Software Guide : BeginCodeSnippet BandMathFilterType::Pointer m_LBandMathFilter = BandMathFilterType::New(); - m_LBandMathFilter->SetNthInput(0,m_LeftWarpImageFilter->GetOutput(),"inleft"); - #ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS + m_LBandMathFilter->SetNthInput(0, m_LeftWarpImageFilter->GetOutput(), "inleft"); +#ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS std::string leftExpr = "inleft != 0 ? 255 : 0"; - #else - std::string leftExpr = "if(inleft != 0,255,0)"; - #endif +#else + std::string leftExpr = "if(inleft != 0,255,0)"; +#endif m_LBandMathFilter->SetExpression(leftExpr); BandMathFilterType::Pointer m_RBandMathFilter = BandMathFilterType::New(); - m_RBandMathFilter->SetNthInput(0,m_RightWarpImageFilter->GetOutput(),"inright"); + m_RBandMathFilter->SetNthInput(0, m_RightWarpImageFilter->GetOutput(), "inright"); - #ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS +#ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS std::string rightExpr = "inright != 0 ? 255 : 0"; - #else +#else std::string rightExpr = "if(inright != 0,255,0)"; - #endif +#endif m_RBandMathFilter->SetExpression(rightExpr); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// Once the two sensor images have been resampled in epipolar geometry, the -// disparity map can be computed. The approach presented here is a 2D matching -// based on a pixel-wise metric optimization. This approach doesn't give the best -// results compared to global optimization methods, but it is suitable for -// streaming and threading on large images. -// -// The major filter used for this step is \doxygen{otb}{PixelWiseBlockMatchingImageFilter}. -// The metric is computed on a window centered around the tested epipolar position. -// It performs a pixel-to-pixel matching between the two epipolar images. The output disparities -// are given as index offset from left to right position. The following features are available -// in this filter: -// \begin{itemize} -// \item Available metrics : SSD, NCC and $L^{p}$ pseudo norm (computed on a square window) -// \item Rectangular disparity exploration area. -// \item Input masks for left and right images (optional). -// \item Output metric values (optional). -// \item Possibility to use input disparity estimate (as a uniform value or a full map) and an -// exploration radius around these values to reduce the size of the exploration area (optional). -// \end{itemize} -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // Once the two sensor images have been resampled in epipolar geometry, the + // disparity map can be computed. The approach presented here is a 2D matching + // based on a pixel-wise metric optimization. This approach doesn't give the best + // results compared to global optimization methods, but it is suitable for + // streaming and threading on large images. + // + // The major filter used for this step is \doxygen{otb}{PixelWiseBlockMatchingImageFilter}. + // The metric is computed on a window centered around the tested epipolar position. + // It performs a pixel-to-pixel matching between the two epipolar images. The output disparities + // are given as index offset from left to right position. The following features are available + // in this filter: + // \begin{itemize} + // \item Available metrics : SSD, NCC and $L^{p}$ pseudo norm (computed on a square window) + // \item Rectangular disparity exploration area. + // \item Input masks for left and right images (optional). + // \item Output metric values (optional). + // \item Possibility to use input disparity estimate (as a uniform value or a full map) and an + // exploration radius around these values to reduce the size of the exploration area (optional). + // \end{itemize} + NCCBlockMatchingFilterType::Pointer m_NCCBlockMatcher = NCCBlockMatchingFilterType::New(); m_NCCBlockMatcher->SetLeftInput(m_LeftWarpImageFilter->GetOutput()); m_NCCBlockMatcher->SetRightInput(m_RightWarpImageFilter->GetOutput()); @@ -318,32 +257,24 @@ int main(int argc, char* argv[]) m_NCCBlockMatcher->MinimizeOff(); m_NCCBlockMatcher->SetLeftMaskInput(m_LBandMathFilter->GetOutput()); m_NCCBlockMatcher->SetRightMaskInput(m_RBandMathFilter->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// Some other filters have been added to enhance these \textit{pixel-to-pixel} disparities. The filter -// \doxygen{otb}{SubPixelDisparityImageFilter} can estimate the disparities with sub-pixel -// precision. Several interpolation methods can be used : parabolic fit, triangular fit, and -// dichotomy search. -// Software Guide : EndLatex + // Some other filters have been added to enhance these \textit{pixel-to-pixel} disparities. The filter + // \doxygen{otb}{SubPixelDisparityImageFilter} can estimate the disparities with sub-pixel + // precision. Several interpolation methods can be used : parabolic fit, triangular fit, and + // dichotomy search. -// Software Guide : BeginCodeSnippet NCCSubPixelDisparityFilterType::Pointer m_NCCSubPixFilter = NCCSubPixelDisparityFilterType::New(); m_NCCSubPixFilter->SetInputsFromBlockMatchingFilter(m_NCCBlockMatcher); m_NCCSubPixFilter->SetRefineMethod(NCCSubPixelDisparityFilterType::DICHOTOMY); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// The filter \doxygen{otb}{DisparityMapMedianFilter} can be used to remove outliers. It has two -// parameters: -// \begin{itemize} -// \item The radius of the local neighborhood to compute the median -// \item An incoherence threshold to reject disparities whose distance from the local median -// is superior to the threshold. -// \end{itemize} -// Software Guide : EndLatex + // The filter \doxygen{otb}{DisparityMapMedianFilter} can be used to remove outliers. It has two + // parameters: + // \begin{itemize} + // \item The radius of the local neighborhood to compute the median + // \item An incoherence threshold to reject disparities whose distance from the local median + // is superior to the threshold. + // \end{itemize} -// Software Guide : BeginCodeSnippet MedianFilterType::Pointer m_HMedianFilter = MedianFilterType::New(); m_HMedianFilter->SetInput(m_NCCSubPixFilter->GetHorizontalDisparityOutput()); m_HMedianFilter->SetRadius(2); @@ -355,33 +286,29 @@ int main(int argc, char* argv[]) m_VMedianFilter->SetRadius(2); m_VMedianFilter->SetIncoherenceThreshold(2.0); m_VMedianFilter->SetMaskInput(m_LBandMathFilter->GetOutput()); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// The application \code{PixelWiseBlockMatching} contains all these filters and -// provides a single interface to compute your disparity maps. -// -// The disparity map obtained with the previous step usually gives a good idea of -// the altitude profile. However, it is more useful to study altitude with a DEM (Digital -// Elevation Model) representation. -// -// The filter \doxygen{otb}{DisparityMapToDEMFilter} performs this last step. The behavior -// of this filter is to : -// \begin{itemize} -// \item Compute the DEM extent from the left sensor image envelope (spacing is set by the user) -// \item Compute the left and right rays corresponding to each valid disparity -// \item Compute the intersection with the \textit{mid-point} method -// \item If the 3D point falls inside a DEM cell and has a greater elevation than the -// current height, the cell height is updated -// \end{itemize} -// The rule of keeping the highest elevation makes sense for buildings seen from the side -// because the roof edges elevation has to be kept. However this rule is not suited for -// noisy disparities. -// -// The application \code{DisparityMapToElevationMap} also gives an example of use. -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + + // The application \code{PixelWiseBlockMatching} contains all these filters and + // provides a single interface to compute your disparity maps. + // + // The disparity map obtained with the previous step usually gives a good idea of + // the altitude profile. However, it is more useful to study altitude with a DEM (Digital + // Elevation Model) representation. + // + // The filter \doxygen{otb}{DisparityMapToDEMFilter} performs this last step. The behavior + // of this filter is to : + // \begin{itemize} + // \item Compute the DEM extent from the left sensor image envelope (spacing is set by the user) + // \item Compute the left and right rays corresponding to each valid disparity + // \item Compute the intersection with the \textit{mid-point} method + // \item If the 3D point falls inside a DEM cell and has a greater elevation than the + // current height, the cell height is updated + // \end{itemize} + // The rule of keeping the highest elevation makes sense for buildings seen from the side + // because the roof edges elevation has to be kept. However this rule is not suited for + // noisy disparities. + // + // The application \code{DisparityMapToElevationMap} also gives an example of use. + DisparityToElevationFilterType::Pointer m_DispToElev = DisparityToElevationFilterType::New(); m_DispToElev->SetHorizontalDisparityMapInput(m_HMedianFilter->GetOutput()); m_DispToElev->SetVerticalDisparityMapInput(m_VMedianFilter->GetOutput()); @@ -389,11 +316,11 @@ int main(int argc, char* argv[]) m_DispToElev->SetRightInput(rightReader->GetOutput()); m_DispToElev->SetLeftEpipolarGridInput(m_DisplacementFieldSource->GetLeftDisplacementFieldOutput()); m_DispToElev->SetRightEpipolarGridInput(m_DisplacementFieldSource->GetRightDisplacementFieldOutput()); - m_DispToElev->SetElevationMin(avgElevation-10.0); - m_DispToElev->SetElevationMax(avgElevation+80.0); + m_DispToElev->SetElevationMin(avgElevation - 10.0); + m_DispToElev->SetElevationMax(avgElevation + 80.0); m_DispToElev->SetDEMGridStep(2.5); m_DispToElev->SetDisparityMaskInput(m_LBandMathFilter->GetOutput()); - //m_DispToElev->SetAverageElevation(avgElevation); + // m_DispToElev->SetAverageElevation(avgElevation); WriterType::Pointer m_DEMWriter = WriterType::New(); m_DEMWriter->SetInput(m_DispToElev->GetOutput()); @@ -409,10 +336,7 @@ int main(int argc, char* argv[]) fieldWriter->SetInput(fieldRescaler->GetOutput()); fieldWriter->SetFileName(argv[4]); fieldWriter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:STEREORECONSTRUCTIONOUTPUT} shows the result of applying // terrain reconstruction based using pixel-wise block matching, sub-pixel // interpolation and DEM estimation using a pair of Pleiades images over the @@ -423,8 +347,6 @@ int main(int argc, char* argv[]) // \itkcaption[From stereo pair to elevation]{DEM image estimated from the disparity.} // \label{fig:STEREORECONSTRUCTIONOUTPUT} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/AsymmetricFusionOfLineDetectorExample.cxx b/Examples/FeatureExtraction/AsymmetricFusionOfLineDetectorExample.cxx index 877df9f53f40a3cbfa6730046fc7204a742cc926..99a929dc673a1586f400c0da8da6f8e803be3ecf 100644 --- a/Examples/FeatureExtraction/AsymmetricFusionOfLineDetectorExample.cxx +++ b/Examples/FeatureExtraction/AsymmetricFusionOfLineDetectorExample.cxx @@ -19,24 +19,16 @@ */ +/* Example usage: +./AsymmetricFusionOfLineDetectorExample Input/amst2.png Output/amstLineFusion.png 5 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {amst2.png} -// OUTPUTS: {amstLineFusion.png} -// 5 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{AssymmetricFusionOfLineDetectorImageFilter}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbAsymmetricFusionOfLineDetectorImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -44,184 +36,108 @@ #include "itkRescaleIntensityImageFilter.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputEdgesImageFile length width" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We // choose to make all computations with floating point precision // and rescale the results between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef float InternalPixelType; - typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet + typedef float InternalPixelType; + typedef unsigned char OutputPixelType; - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Image<InternalPixelType, 2> InternalImageType; - typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet + typedef otb::Image<InternalPixelType, 2> InternalImageType; + typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : BeginLatex - // // The filter can be instantiated using the image types defined above. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::AsymmetricFusionOfLineDetectorImageFilter<InternalImageType, - InternalImageType> - FilterType; - // Software Guide : EndCodeSnippet + typedef otb::AsymmetricFusionOfLineDetectorImageFilter<InternalImageType, InternalImageType> FilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read // image data from a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InternalImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the // output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The intensity rescaling of the results will be carried out by the // \code{itk::RescaleIntensityImageFilter} which is templated by the // input and output image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InternalImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InternalImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // Both the filter and the reader are created by invoking their \code{New()} // methods and assigning the result to SmartPointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The same is done for the rescaler and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet RescalerType::Pointer rescaler = RescalerType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \code{itk::RescaleIntensityImageFilter} needs to know which // is the minimu and maximum values of the output generated // image. Those can be chosen in a generic way by using the // \code{NumericTraits} functions, since they are templated over // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the // \doxygen{otb}{AsymmetricFusionOfDetectorImageFilter}. The pipeline is built as follows. // // \index{otb::AsymmetricFusionOfDetectorImageFilter!SetInput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The methods \code{SetLengthLine()} and \code{SetWidthLine()} // allow setting the minimum length and the typical witdh of the // lines which are to be detected. // // \index{otb::AsymmetricFusionOfDetector!SetWidthLine()} // \index{otb::AsymmetricFusionOfDetector!SetLengthLine()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetLengthLine(atoi(argv[3])); filter->SetWidthLine(atoi(argv[4])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter is executed by invoking the \code{Update()} method. If the // filter is part of a larger image processing pipeline, calling // \code{Update()} on a downstream filter will also trigger update of this // filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { filter->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return -1; - } - // Software Guide : EndCodeSnippet + } writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:LINEFUSION_FILTER} // shows the result of applying the AsymmetricFusionOf edge detector filter // to a SAR image. \begin{figure} \center @@ -230,8 +146,6 @@ int main(int argc, char * argv[]) // \itkcaption[Line Correlation Detector Application]{Result of applying // the \doxygen{otb}{AsymmetricFusionOfDetectorImageFilter} to a SAR // image. From left to right : original image, line intensity.} \label{fig:LINEFUSION_FILTER} \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/CloudDetectionExample.cxx b/Examples/FeatureExtraction/CloudDetectionExample.cxx index facd6f78fd1a3bcfc4776730a73febc154b034f9..286feb1f26494a35dededc3bcb8ac268b62302e1 100644 --- a/Examples/FeatureExtraction/CloudDetectionExample.cxx +++ b/Examples/FeatureExtraction/CloudDetectionExample.cxx @@ -19,15 +19,21 @@ */ +/* Example usage: +./CloudDetectionExample Input/CloudsOnReunion.tif \ + Output/CloudDetectionOutput.tif \ + Output/pretty_CloudsOnReunion.png \ + Output/pretty_CloudDetectionOutput.png \ + 553 \ + 467 \ + 734 \ + 581 \ + 0.4 \ + 0.6 \ + 1.0 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {CloudsOnReunion.tif} -// OUTPUTS: {CloudDetectionOutput.tif} , {pretty_CloudsOnReunion.png} , {pretty_CloudDetectionOutput.png} -// 553 467 734 581 0.4 0.6 1.0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // The cloud detection functor is a processing chain composed by the // computation of a spectral angle (with SpectralAngleFunctor). The // result is multiplied by a gaussian factor (with @@ -42,12 +48,8 @@ // // The first step toward the use of this filter is the inclusion of // the proper header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbCloudDetectionFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -56,116 +58,70 @@ #include "otbVectorRescaleIntensityImageFilter.h" #include "otbMultiChannelExtractROI.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 12) - { + { std::cerr << "Usage: " << argv[0]; - std::cerr << - "inputFileName outputFileName printableInputFileName printableOutputFileName"; - std::cerr << - "firstPixelComponent secondPixelComponent thirdPixelComponent fourthPixelComponent "; + std::cerr << "inputFileName outputFileName printableInputFileName printableOutputFileName"; + std::cerr << "firstPixelComponent secondPixelComponent thirdPixelComponent fourthPixelComponent "; std::cerr << "variance "; std::cerr << "minThreshold maxThreshold " << std::endl; return EXIT_FAILURE; - } + } const unsigned int Dimension = 2; - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the images. We choose to do // all the computations in double precision. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef double InputPixelType; typedef double OutputPixelType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the // dimension. Please note that the // \doxygen{otb}{CloudDetectionFilter} needs an // \doxygen{otb}{VectorImage} as input to handle multispectral // images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<InputPixelType, Dimension> VectorImageType; typedef VectorImageType::PixelType VectorPixelType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the functor type that the filter will use. We use the // \doxygen{otb}{CloudDetectionFunctor}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Functor::CloudDetectionFunctor<VectorPixelType, - OutputPixelType> FunctorType; - // Software Guide : EndCodeSnippet + typedef otb::Functor::CloudDetectionFunctor<VectorPixelType, OutputPixelType> FunctorType; - // Software Guide : BeginLatex - // // Now we can define the \doxygen{otb}{CloudDetectionFilter} that // takes a multi-spectral image as input and produces a binary // image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::CloudDetectionFilter<VectorImageType, OutputImageType, - FunctorType> CloudDetectionFilterType; - // Software Guide : EndCodeSnippet + typedef otb::CloudDetectionFilter<VectorImageType, OutputImageType, FunctorType> CloudDetectionFilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in // order to read image data from a file. Then, an // \doxygen{otb}{ImageFileWriter} is instantiated in order to write // the output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<VectorImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The different filters composing our pipeline are created by invoking their // \code{New()} methods, assigning the results to smart pointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); - CloudDetectionFilterType::Pointer cloudDetection = - CloudDetectionFilterType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + ReaderType::Pointer reader = ReaderType::New(); + CloudDetectionFilterType::Pointer cloudDetection = CloudDetectionFilterType::New(); + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); cloudDetection->SetInput(reader->GetOutput()); - // Software Guide : BeginLatex - // // The \doxygen{otb}{CloudDetectionFilter} needs to have a reference // pixel corresponding to the spectral content likely to represent a // cloud. This is done by passing a pixel to the filter. Here we // suppose that the input image has four spectral bands. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet VectorPixelType referencePixel; referencePixel.SetSize(4); referencePixel.Fill(0.); @@ -174,40 +130,23 @@ int main(int argc, char * argv[]) referencePixel[2] = (atof(argv[7])); referencePixel[3] = (atof(argv[8])); cloudDetection->SetReferencePixel(referencePixel); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We must also set the variance parameter of the filter and the // parameter of the gaussian functor. The bigger the value, the // more tolerant the detector will be. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet cloudDetection->SetVariance(atof(argv[9])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The minimum and maximum thresholds are set to binarise the final result. // These values have to be between 0 and 1. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet cloudDetection->SetMinThreshold(atof(argv[10])); cloudDetection->SetMaxThreshold(atof(argv[11])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginCodeSnippet writer->SetFileName(argv[2]); writer->SetInput(cloudDetection->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:CLOUDDETECTION_FILTER} shows the result of applying // the cloud detection filter to a cloudy image. // \begin{figure} \center @@ -216,31 +155,17 @@ int main(int argc, char * argv[]) // \itkcaption[Cloud Detection Example]{From left to right : original image, cloud mask resulting from processing.} // \label{fig:CLOUDDETECTION_FILTER} // \end{figure} - // - // Software Guide : EndLatex // Pretty image creation for printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::VectorImage<unsigned char, - Dimension> - InputPrettyImageType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyOutputType; - typedef otb::ImageFileWriter<InputPrettyImageType> - WriterPrettyInputType; - typedef itk::RescaleIntensityImageFilter<OutputImageType, - OutputPrettyImageType> - RescalerOutputType; - typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, - InputPrettyImageType> - RescalerInputType; - typedef otb::MultiChannelExtractROI<InputPixelType, - InputPixelType> - ChannelExtractorType; - - ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::VectorImage<unsigned char, Dimension> InputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyOutputType; + typedef otb::ImageFileWriter<InputPrettyImageType> WriterPrettyInputType; + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputPrettyImageType> RescalerOutputType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, InputPrettyImageType> RescalerInputType; + typedef otb::MultiChannelExtractROI<InputPixelType, InputPixelType> ChannelExtractorType; + + ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); RescalerInputType::Pointer inputRescaler = RescalerInputType::New(); WriterPrettyInputType::Pointer prettyInputWriter = WriterPrettyInputType::New(); selecter->SetInput(reader->GetOutput()); @@ -259,8 +184,7 @@ int main(int argc, char * argv[]) prettyInputWriter->SetInput(inputRescaler->GetOutput()); RescalerOutputType::Pointer outputRescaler = RescalerOutputType::New(); - WriterPrettyOutputType::Pointer prettyOutputWriter = - WriterPrettyOutputType::New(); + WriterPrettyOutputType::Pointer prettyOutputWriter = WriterPrettyOutputType::New(); outputRescaler->SetInput(cloudDetection->GetOutput()); outputRescaler->SetOutputMinimum(0); outputRescaler->SetOutputMaximum(255); diff --git a/Examples/FeatureExtraction/ComplexMomentPathExample.cxx b/Examples/FeatureExtraction/ComplexMomentPathExample.cxx index fae478332fd7926854526341182470f913e6b9bf..909b582f5a269fa7c85996a178558bd1745b13f0 100644 --- a/Examples/FeatureExtraction/ComplexMomentPathExample.cxx +++ b/Examples/FeatureExtraction/ComplexMomentPathExample.cxx @@ -19,18 +19,16 @@ */ - #include "itkMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" -// Software Guide : BeginCommandLineArgs -// 1 1 -// Software Guide : EndCommandLineArgs +/* Example usage: +./ComplexMomentPathExample 1 1 +*/ + -// Software Guide : BeginLatex -// // The complex moments can be computed on images, but sometimes we are // interested in computing them on shapes extracted from images by // segmentation algorithms. These shapes can be represented by @@ -39,35 +37,26 @@ // complex geometric moments on ITK paths. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbComplexMomentPathFunction.h" -// Software Guide : EndCodeSnippet #include "itkPolyLineParametricPath.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " p q" << std::endl; return EXIT_FAILURE; - } + } - unsigned int P((unsigned char) ::atoi(argv[1])); - unsigned int Q((unsigned char) ::atoi(argv[2])); + unsigned int P((unsigned char)::atoi(argv[1])); + unsigned int Q((unsigned char)::atoi(argv[2])); - // Software Guide : BeginLatex - // // The \doxygen{otb}{ComplexMomentPathFunction} is templated over the // input path type and the output complex type value, so we start by // defining: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef itk::PolyLineParametricPath<Dimension> PathType; @@ -76,7 +65,6 @@ int main(int argc, char * argv[]) typedef otb::ComplexMomentPathFunction<PathType, ComplexType> CMType; CMType::Pointer cmFunction = CMType::New(); - // Software Guide : EndCodeSnippet PathType::Pointer path = PathType::New(); @@ -103,35 +91,23 @@ int main(int argc, char * argv[]) cindex[1] = 30; path->AddVertex(cindex); - // Software Guide : BeginLatex - // // Next, we set the parameters of the plug the input path into the complex moment function // and we set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet cmFunction->SetInputPath(path); cmFunction->SetQ(Q); cmFunction->SetP(P); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Since the paths are defined in physical coordinates, we do not // need to set the center for the moment computation as we did // with the \doxygen{otb}{ComplexMomentImageFunction}. The same // applies for the size of the neighborhood around the // center pixel for the moment computation. The moment computation // is triggered by calling the \code{Evaluate} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ComplexType Result = cmFunction->Evaluate(); - std::cout << "The moment of order (" << P << "," << Q << - ") is equal to " << Result << std::endl; - // Software Guide : EndCodeSnippet + std::cout << "The moment of order (" << P << "," << Q << ") is equal to " << Result << std::endl; return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/ComplexMomentsImageFunctionExample.cxx b/Examples/FeatureExtraction/ComplexMomentsImageFunctionExample.cxx index ee4bd32afd161b62c08e914f4c83a8d71264ce5d..538b99338765a845c93fe2dacf452773f12778c7 100644 --- a/Examples/FeatureExtraction/ComplexMomentsImageFunctionExample.cxx +++ b/Examples/FeatureExtraction/ComplexMomentsImageFunctionExample.cxx @@ -19,46 +19,39 @@ */ - #include "itkMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// 2 2 -// Software Guide : EndCommandLineArgs +/* Example usage: +./ComplexMomentsImageFunctionExample Input/ROISpot5.png 2 2 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{ComplexMomentsImageFunction}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbComplexMomentsImageFunction.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " p q" << std::endl; return EXIT_FAILURE; - } + } - const char * inputFilename = argv[1]; + const char* inputFilename = argv[1]; - unsigned int P((unsigned char) ::atoi(argv[2])); - unsigned int Q((unsigned char) ::atoi(argv[3])); + unsigned int P((unsigned char)::atoi(argv[2])); + unsigned int Q((unsigned char)::atoi(argv[3])); - typedef unsigned char InputPixelType; - const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef unsigned char InputPixelType; + const unsigned int Dimension = 2; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; @@ -66,67 +59,41 @@ int main(int argc, char * argv[]) reader->SetFileName(inputFilename); - // Software Guide : BeginLatex - // // The \doxygen{otb}{ComplexMomentImageFunction} is templated over the // input image type and the output complex type value, so we start by // defining: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ComplexMomentsImageFunction<InputImageType> CMType; - typedef CMType::OutputType OutputType; + typedef CMType::OutputType OutputType; CMType::Pointer cmFunction = CMType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Next, we plug the input image into the complex moment function // and we set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->Update(); cmFunction->SetInputImage(reader->GetOutput()); cmFunction->SetQmax(Q); cmFunction->SetPmax(P); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // We can chose the pixel of the image which will used as center // for the moment computation - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InputImageType::IndexType center; center[0] = 50; center[1] = 50; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // We can also choose the size of the neighborhood around the // center pixel for the moment computation. - // - // Software Guide : EndLatex cmFunction->SetNeighborhoodRadius(15); - // Software Guide : BeginLatex // In order to get the value of the moment, we call the // \code{EvaluateAtIndex} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet OutputType Result = cmFunction->EvaluateAtIndex(center); - std::cout << "The moment of order (" << P << "," << Q << - ") is equal to " << Result.at(P).at(Q) << std::endl; - // Software Guide : EndCodeSnippet + std::cout << "The moment of order (" << P << "," << Q << ") is equal to " << Result.at(P).at(Q) << std::endl; return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/CorrelationLineDetectorExample.cxx b/Examples/FeatureExtraction/CorrelationLineDetectorExample.cxx index 57141eefb43c03b4866d2250d0dd601b08c3d99a..cfa79e5bf6b13cd74f59cc526d65ef75cd641896 100644 --- a/Examples/FeatureExtraction/CorrelationLineDetectorExample.cxx +++ b/Examples/FeatureExtraction/CorrelationLineDetectorExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./CorrelationLineDetectorExample Input/amst2.png Output/amstLineCorrelations.png Output/amstLineCorrelationDirections.png 5 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {amst2.png} -// OUTPUTS: {amstLineCorrelations.png}, {amstLineCorrelationDirections.png} -// 5 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{CorrelationLineDetectorImageFilter}. // This filter is used for line detection in SAR images. Its principle // is described in \cite{tup-98}: a line is detected if two parallel @@ -35,12 +31,8 @@ // correlation of means detector. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbLineCorrelationDetectorImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -48,188 +40,108 @@ #include "itkRescaleIntensityImageFilter.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; - std::cerr << - " outputEdgesImageFile outputDirectionsImageFile length width" << std::endl; + std::cerr << " outputEdgesImageFile outputDirectionsImageFile length width" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We // choose to make all computations with floating point precision // and rescale the results between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef float InternalPixelType; - typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet + typedef float InternalPixelType; + typedef unsigned char OutputPixelType; - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Image<InternalPixelType, 2> InternalImageType; - typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet + typedef otb::Image<InternalPixelType, 2> InternalImageType; + typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : BeginLatex - // // The filter can be instantiated using the image types defined above. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::LineCorrelationDetectorImageFilter<InternalImageType, - InternalImageType> - FilterType; - // Software Guide : EndCodeSnippet + typedef otb::LineCorrelationDetectorImageFilter<InternalImageType, InternalImageType> FilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read // image data from a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InternalImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the // output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The intensity rescaling of the results will be carried out by the // \code{itk::RescaleIntensityImageFilter} which is templated by the // input and output image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InternalImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InternalImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // Both the filter and the reader are created by invoking their \code{New()} // methods and assigning the result to SmartPointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The same is done for the rescaler and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet RescalerType::Pointer rescaler = RescalerType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \code{itk::RescaleIntensityImageFilter} needs to know which // is the minimu and maximum values of the output generated // image. Those can be chosen in a generic way by using the // \code{NumericTraits} functions, since they are templated over // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the // \doxygen{otb}{LineCorrelationDetectorImageFilter}. The pipeline is built as follows. // // \index{otb::LineCorrelationDetectorImageFilter!SetInput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The methods \code{SetLengthLine()} and \code{SetWidthLine()} // allow setting the minimum length and the typical witdh of the // lines which are to be detected. // // \index{otb::LineCorrelationDetector!SetWidthLine()} // \index{otb::LineCorrelationDetector!SetLengthLine()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetLengthLine(atoi(argv[4])); filter->SetWidthLine(atoi(argv[5])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter is executed by invoking the \code{Update()} method. If the // filter is part of a larger image processing pipeline, calling // \code{Update()} on a downstream filter will also trigger update of this // filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->Update(); - // Software Guide : EndCodeSnippet writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex // We can also obtain the direction of the lines by invoking the // \code{GetOutputDirections()} method. - // Software Guide : EndLatex writer->SetFileName(argv[3]); - // Software Guide : BeginCodeSnippet rescaler->SetInput(filter->GetOutputDirection()); writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex Figure~\ref{fig:LINECORRELATION_FILTER} + // Figure~\ref{fig:LINECORRELATION_FILTER} // shows the result of applying the LineCorrelation edge detector filter // to a SAR image. \begin{figure} \center // \includegraphics[width=0.25\textwidth]{amst.eps} @@ -244,7 +156,6 @@ int main(int argc, char * argv[]) // \begin{itemize} // \item \doxygen{otb}{LineCorrelationDetectorImageFilter} // \end{itemize} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/EdgeDensityExample.cxx b/Examples/FeatureExtraction/EdgeDensityExample.cxx index 30ac52153132f94958eee01e6e8a967f21de8200..655469d5e13173fdcd6ddd323eb9f43107784bff 100644 --- a/Examples/FeatureExtraction/EdgeDensityExample.cxx +++ b/Examples/FeatureExtraction/EdgeDensityExample.cxx @@ -25,14 +25,11 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {suburb2.jpeg} -// OUTPUTS: {EdgeDensityOutput.tif}, {PrettyEdgeDensityOutput.png} -// 7 50 10 1.0 0.01 -// Software Guide : EndCommandLineArgs +/* Example usage: +./EdgeDensityExample Input/suburb2.jpeg Output/EdgeDensityOutput.tif Output/PrettyEdgeDensityOutput.png 7 50 10 1.0 0.01 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{EdgeDensityImageFilter}. // This filter computes a local density of edges on an image and can @@ -42,151 +39,90 @@ // computed can be chosen by the user. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbEdgeDensityImageFilter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // We will also include the header files for the edge detector (a // Canny filter) and the density estimation (a simple count on a // binary image). // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkCannyEdgeDetectionImageFilter.h" #include "otbBinaryImageDensityFunction.h" -// Software Guide : EndCodeSnippet int main(int itkNotUsed(argc), char* argv[]) { - const char * infname = argv[1]; - const char * outfname = argv[2]; - const char * prettyfilename = argv[3]; + const char* infname = argv[1]; + const char* outfname = argv[2]; + const char* prettyfilename = argv[3]; - const unsigned int radius = atoi(argv[4]); + const unsigned int radius = atoi(argv[4]); /*--*/ const unsigned int Dimension = 2; - typedef float PixelType; + typedef float PixelType; /** Variables for the canny detector*/ - const PixelType upperThreshold = static_cast<PixelType>(atof(argv[5])); - const PixelType lowerThreshold = static_cast<PixelType>(atof(argv[6])); - const double variance = atof(argv[7]); - const double maximumError = atof(argv[8]); + const PixelType upperThreshold = static_cast<PixelType>(atof(argv[5])); + const PixelType lowerThreshold = static_cast<PixelType>(atof(argv[6])); + const double variance = atof(argv[7]); + const double maximumError = atof(argv[8]); - // Software Guide : BeginLatex - // // As usual, we start by defining the types for the images, the reader // and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define now the type for the function which will be used by the // edge density filter to estimate this density. Here we choose a // function which counts the number of non null pixels per area. The // function takes as template the type of the image to be processed. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::BinaryImageDensityFunction<ImageType> CountFunctionType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // These {\em non null pixels} will be the result of an edge // detector. We use here the classical Canny edge detector, which is // templated over the input and output image types. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef itk::CannyEdgeDetectionImageFilter<ImageType, ImageType> - CannyDetectorType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef itk::CannyEdgeDetectionImageFilter<ImageType, ImageType> CannyDetectorType; // Finally, we can define the type for the edge density filter which // takes as template the input and output image types, the edge // detector type, and the count function type.. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::EdgeDensityImageFilter<ImageType, ImageType, CannyDetectorType, - CountFunctionType> EdgeDensityFilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef otb::EdgeDensityImageFilter<ImageType, ImageType, CannyDetectorType, CountFunctionType> EdgeDensityFilterType; // We can now instantiate the different processing objects of the // pipeline using the \code{New()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); - EdgeDensityFilterType::Pointer filter = EdgeDensityFilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + EdgeDensityFilterType::Pointer filter = EdgeDensityFilterType::New(); CannyDetectorType::Pointer cannyFilter = CannyDetectorType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + WriterType::Pointer writer = WriterType::New(); // The edge detection filter needs to be instantiated because we // need to set its parameters. This is what we do here for the Canny // filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet cannyFilter->SetUpperThreshold(upperThreshold); cannyFilter->SetLowerThreshold(lowerThreshold); cannyFilter->SetVariance(variance); cannyFilter->SetMaximumError(maximumError); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // After that, we can pass the edge detector to the filter which // will be used it internally. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetDetector(cannyFilter); filter->SetNeighborhoodRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally, we set the file names for the input and the output // images and we plug the pipeline. The \code{Update()} method of // the writer will trigger the processing. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(infname); writer->SetFileName(outfname); filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:EDGEDENSITY_FILTER} shows the result of applying // the edge density filter to an image. // \begin{figure} @@ -198,15 +134,12 @@ int main(int itkNotUsed(argc), char* argv[]) // original image, edge density.} // \label{fig:EDGEDENSITY_FILTER} // \end{figure} - // - // Software Guide : EndLatex /************* Image for printing **************/ typedef otb::Image<unsigned char, 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> - RescalerType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; RescalerType::Pointer rescaler = RescalerType::New(); @@ -216,7 +149,7 @@ int main(int itkNotUsed(argc), char* argv[]) rescaler->SetInput(filter->GetOutput()); typedef otb::ImageFileWriter<OutputImageType> OutputWriterType; - OutputWriterType::Pointer outwriter = OutputWriterType::New(); + OutputWriterType::Pointer outwriter = OutputWriterType::New(); outwriter->SetFileName(prettyfilename); outwriter->SetInput(rescaler->GetOutput()); diff --git a/Examples/FeatureExtraction/ExtractRoadByStepsExample.cxx b/Examples/FeatureExtraction/ExtractRoadByStepsExample.cxx index d4a02cad14d8e35113cca49154d0200e9903ea77..54891d83c85169c20f0e82311a78b2d4aba5f986 100644 --- a/Examples/FeatureExtraction/ExtractRoadByStepsExample.cxx +++ b/Examples/FeatureExtraction/ExtractRoadByStepsExample.cxx @@ -19,15 +19,10 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates the details of the \doxygen{otb}{RoadExtractionFilter}. // This filter, described in the previous section, is a composite filter that includes // all the steps below. Individual filters can be replaced to design a road detector // targeted at SAR images for example. -// -// Software Guide : EndLatex #include "otbPolyLineParametricPathWithValue.h" #include "otbSpectralAngleDistanceImageFilter.h" @@ -63,21 +58,19 @@ #include "itkBinaryBallStructuringElement.h" #include "itkGrayscaleDilateImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {ExtractRoadByStepsExampleOutput.jpg}, {qb_ExtractRoad_pretty.jpg} -// 337 557 432 859 0.00005 1.0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract2.tif} -// OUTPUTS: {ExtractRoadByStepsExampleOutput2.jpg}, {qb_ExtractRoad_pretty2.jpg} -// 228 316 207 282 0.00005 1.0 -// Software Guide : EndCommandLineArgs - -int main(int itkNotUsed(argc), char * argv[]) +/* Example usage: +./ExtractRoadByStepsExample Input/qb_RoadExtract.tif Output/ExtractRoadByStepsExampleOutput.jpg Output/qb_ExtractRoad_pretty.jpg 337 557 432 859 0.00005 1.0 +*/ + +/* Example usage: +./ExtractRoadByStepsExample Input/qb_RoadExtract2.tif Output/ExtractRoadByStepsExampleOutput2.jpg Output/qb_ExtractRoad_pretty2.jpg 228 316 207 282 0.00005 1.0 +*/ + + +int main(int itkNotUsed(argc), char* argv[]) { - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double PixelType; typedef unsigned char OutputPixelType; typedef itk::CovariantVector<PixelType, Dimension> VectorPixelType; @@ -89,17 +82,14 @@ int main(int itkNotUsed(argc), char * argv[]) typedef otb::ImageFileReader<MultiSpectralImageType> MultispectralReaderType; - MultispectralReaderType::Pointer multispectralReader = - MultispectralReaderType::New(); + MultispectralReaderType::Pointer multispectralReader = MultispectralReaderType::New(); multispectralReader->SetFileName(argv[1]); // Create an 3 band image for the software guide - typedef otb::VectorImage<OutputPixelType, Dimension> OutputVectorImageType; - typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; - typedef otb::VectorRescaleIntensityImageFilter - <MultiSpectralImageType, OutputVectorImageType> VectorRescalerType; - typedef otb::MultiChannelExtractROI<unsigned char, - unsigned char> ChannelExtractorType; + typedef otb::VectorImage<OutputPixelType, Dimension> OutputVectorImageType; + typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; + typedef otb::VectorRescaleIntensityImageFilter<MultiSpectralImageType, OutputVectorImageType> VectorRescalerType; + typedef otb::MultiChannelExtractROI<unsigned char, unsigned char> ChannelExtractorType; // The GenerateOutputInformation() information is required here so // that the number of component per pixel is update and known to set @@ -107,10 +97,8 @@ int main(int itkNotUsed(argc), char * argv[]) multispectralReader->GenerateOutputInformation(); OutputVectorImageType::PixelType minimum, maximum; - minimum.SetSize( - multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel()); - maximum.SetSize( - multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel()); + minimum.SetSize(multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel()); + maximum.SetSize(multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel()); minimum.Fill(0); maximum.Fill(255); @@ -122,8 +110,7 @@ int main(int itkNotUsed(argc), char * argv[]) ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); selecter->SetInput(vr->GetOutput()); - selecter->SetExtractionRegion( - multispectralReader->GetOutput()->GetLargestPossibleRegion()); + selecter->SetExtractionRegion(multispectralReader->GetOutput()->GetLargestPossibleRegion()); selecter->SetChannel(3); selecter->SetChannel(2); selecter->SetChannel(1); @@ -140,11 +127,9 @@ int main(int itkNotUsed(argc), char * argv[]) pixelRef[2] = atoi(argv[6]); pixelRef[3] = atoi(argv[7]); - double resolution = 0.6; //to get directly from metadata - double alpha = atof(argv[9]); + double resolution = 0.6; // to get directly from metadata + double alpha = atof(argv[9]); - // Software Guide : BeginLatex - // // The spectral angle is used to compute a grayscale image from the // multispectral original image using // \doxygen{otb}{SpectralAngleDistanceImageFilter}. The spectral @@ -162,188 +147,101 @@ int main(int itkNotUsed(argc), char * argv[]) // \end{figure} // // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::SpectralAngleDistanceImageFilter<MultiSpectralImageType, - InternalImageType> SAFilterType; - SAFilterType::Pointer saFilter = SAFilterType::New(); + typedef otb::SpectralAngleDistanceImageFilter<MultiSpectralImageType, InternalImageType> SAFilterType; + SAFilterType::Pointer saFilter = SAFilterType::New(); saFilter->SetReferencePixel(pixelRef); saFilter->SetInput(multispectralReader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // A square root is applied to the spectral angle image in order to enhance contrast between // darker pixels (which are pixels of interest) with \doxygen{itk}{SqrtImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::SqrtImageFilter<InternalImageType, - InternalImageType> SqrtFilterType; - SqrtFilterType::Pointer sqrtFilter = SqrtFilterType::New(); + typedef itk::SqrtImageFilter<InternalImageType, InternalImageType> SqrtFilterType; + SqrtFilterType::Pointer sqrtFilter = SqrtFilterType::New(); sqrtFilter->SetInput(saFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Use the Gaussian gradient filter compute the gradient in x and y direction // respectively // (\doxygen{itk}{GradientRecursiveGaussianImageFilter}). - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - double sigma = alpha * (1.2 / resolution + 1); - typedef itk::GradientRecursiveGaussianImageFilter<InternalImageType, - VectorImageType> - GradientFilterType; - GradientFilterType::Pointer gradientFilter = GradientFilterType::New(); + + double sigma = alpha * (1.2 / resolution + 1); + typedef itk::GradientRecursiveGaussianImageFilter<InternalImageType, VectorImageType> GradientFilterType; + GradientFilterType::Pointer gradientFilter = GradientFilterType::New(); gradientFilter->SetSigma(sigma); gradientFilter->SetInput(sqrtFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Compute the scalar product of the neighboring pixels and keep the // minimum value and the direction with \doxygen{otb}{NeighborhoodScalarProductFilter}. // This is the line detector described // in \cite{Lacroix1998}. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::NeighborhoodScalarProductFilter<VectorImageType, - InternalImageType, - InternalImageType> - NeighborhoodScalarProductType; - NeighborhoodScalarProductType::Pointer scalarFilter - = NeighborhoodScalarProductType::New(); + + typedef otb::NeighborhoodScalarProductFilter<VectorImageType, InternalImageType, InternalImageType> NeighborhoodScalarProductType; + NeighborhoodScalarProductType::Pointer scalarFilter = NeighborhoodScalarProductType::New(); scalarFilter->SetInput(gradientFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The resulting image is passed to the \doxygen{otb}{RemoveIsolatedByDirectionFilter} // filter to remove pixels // with no neighbor having the same direction. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::RemoveIsolatedByDirectionFilter<InternalImageType, - InternalImageType, - InternalImageType> - RemoveIsolatedByDirectionType; - RemoveIsolatedByDirectionType::Pointer removeIsolatedByDirectionFilter - = RemoveIsolatedByDirectionType::New(); + + typedef otb::RemoveIsolatedByDirectionFilter<InternalImageType, InternalImageType, InternalImageType> RemoveIsolatedByDirectionType; + RemoveIsolatedByDirectionType::Pointer removeIsolatedByDirectionFilter = RemoveIsolatedByDirectionType::New(); removeIsolatedByDirectionFilter->SetInput(scalarFilter->GetOutput()); - removeIsolatedByDirectionFilter - ->SetInputDirection(scalarFilter->GetOutputDirection()); - // Software Guide : EndCodeSnippet + removeIsolatedByDirectionFilter->SetInputDirection(scalarFilter->GetOutputDirection()); - // Software Guide : BeginLatex - // // We remove pixels having a direction corresponding to bright lines // as we know that after the spectral angle, roads are in darker color // with the \doxygen{otb}{RemoveWrongDirectionFilter} filter. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::RemoveWrongDirectionFilter<InternalImageType, - InternalImageType, - InternalImageType> - RemoveWrongDirectionType; - RemoveWrongDirectionType::Pointer removeWrongDirectionFilter - = RemoveWrongDirectionType::New(); - removeWrongDirectionFilter->SetInput( - removeIsolatedByDirectionFilter->GetOutput()); - removeWrongDirectionFilter->SetInputDirection( - scalarFilter->GetOutputDirection()); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::RemoveWrongDirectionFilter<InternalImageType, InternalImageType, InternalImageType> RemoveWrongDirectionType; + RemoveWrongDirectionType::Pointer removeWrongDirectionFilter = RemoveWrongDirectionType::New(); + removeWrongDirectionFilter->SetInput(removeIsolatedByDirectionFilter->GetOutput()); + removeWrongDirectionFilter->SetInputDirection(scalarFilter->GetOutputDirection()); + // We remove pixels which are not maximum on the direction // perpendicular to the road direction with the \doxygen{otb}{NonMaxRemovalByDirectionFilter}. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::NonMaxRemovalByDirectionFilter<InternalImageType, - InternalImageType, - InternalImageType> - NonMaxRemovalByDirectionType; - NonMaxRemovalByDirectionType::Pointer nonMaxRemovalByDirectionFilter - = NonMaxRemovalByDirectionType::New(); - nonMaxRemovalByDirectionFilter->SetInput( - removeWrongDirectionFilter->GetOutput()); - nonMaxRemovalByDirectionFilter - ->SetInputDirection(scalarFilter->GetOutputDirection()); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::NonMaxRemovalByDirectionFilter<InternalImageType, InternalImageType, InternalImageType> NonMaxRemovalByDirectionType; + NonMaxRemovalByDirectionType::Pointer nonMaxRemovalByDirectionFilter = NonMaxRemovalByDirectionType::New(); + nonMaxRemovalByDirectionFilter->SetInput(removeWrongDirectionFilter->GetOutput()); + nonMaxRemovalByDirectionFilter->SetInputDirection(scalarFilter->GetOutputDirection()); + // Extracted road are vectorized into polylines with \doxygen{otb}{VectorizationPathListFilter}. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::VectorizationPathListFilter<InternalImageType, - InternalImageType, - PathType> VectorizationFilterType; - VectorizationFilterType::Pointer vectorizationFilter - = VectorizationFilterType::New(); + + typedef otb::VectorizationPathListFilter<InternalImageType, InternalImageType, PathType> VectorizationFilterType; + VectorizationFilterType::Pointer vectorizationFilter = VectorizationFilterType::New(); vectorizationFilter->SetInput(nonMaxRemovalByDirectionFilter->GetOutput()); vectorizationFilter->SetInputDirection(scalarFilter->GetOutputDirection()); vectorizationFilter->SetAmplitudeThreshold(atof(argv[8])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // However, this vectorization is too simple and need to be refined // to be usable. First, we remove all aligned points to make one segment with // \doxygen{otb}{SimplifyPathListFilter}. // Then we break the polylines which have sharp angles as they are probably // not road with \doxygen{otb}{BreakAngularPathListFilter}. // Finally we remove path which are too short with \doxygen{otb}{RemoveTortuousPathListFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::SimplifyPathListFilter<PathType> SimplifyPathType; - SimplifyPathType::Pointer simplifyPathListFilter = SimplifyPathType::New(); + SimplifyPathType::Pointer simplifyPathListFilter = SimplifyPathType::New(); simplifyPathListFilter->GetFunctor().SetTolerance(1.0); simplifyPathListFilter->SetInput(vectorizationFilter->GetOutput()); typedef otb::BreakAngularPathListFilter<PathType> BreakAngularPathType; - BreakAngularPathType::Pointer breakAngularPathListFilter - = BreakAngularPathType::New(); + BreakAngularPathType::Pointer breakAngularPathListFilter = BreakAngularPathType::New(); breakAngularPathListFilter->SetMaxAngle(otb::CONST_PI / 8.); breakAngularPathListFilter->SetInput(simplifyPathListFilter->GetOutput()); typedef otb::RemoveTortuousPathListFilter<PathType> RemoveTortuousPathType; - RemoveTortuousPathType::Pointer removeTortuousPathListFilter - = RemoveTortuousPathType::New(); + RemoveTortuousPathType::Pointer removeTortuousPathListFilter = RemoveTortuousPathType::New(); removeTortuousPathListFilter->GetFunctor().SetThreshold(1.0); removeTortuousPathListFilter->SetInput(breakAngularPathListFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Polylines within a certain range are linked (\doxygen{otb}{LinkPathListFilter}) to // try to fill gaps due to occultations by vehicules, trees, etc. before simplifying // polylines (\doxygen{otb}{SimplifyPathListFilter}) and // removing the shortest ones with \doxygen{otb}{RemoveTortuousPathListFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::LinkPathListFilter<PathType> LinkPathType; - LinkPathType::Pointer linkPathListFilter = LinkPathType::New(); + LinkPathType::Pointer linkPathListFilter = LinkPathType::New(); linkPathListFilter->SetDistanceThreshold(25.0 / resolution); linkPathListFilter->SetAngularThreshold(otb::CONST_PI / 8); linkPathListFilter->SetInput(removeTortuousPathListFilter->GetOutput()); @@ -352,118 +250,72 @@ int main(int itkNotUsed(argc), char * argv[]) simplifyPathListFilter2->GetFunctor().SetTolerance(1.0); simplifyPathListFilter2->SetInput(linkPathListFilter->GetOutput()); - RemoveTortuousPathType::Pointer removeTortuousPathListFilter2 - = RemoveTortuousPathType::New(); + RemoveTortuousPathType::Pointer removeTortuousPathListFilter2 = RemoveTortuousPathType::New(); removeTortuousPathListFilter2->GetFunctor().SetThreshold(10.0); removeTortuousPathListFilter2->SetInput(simplifyPathListFilter2->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // A value can be associated with each polyline according to pixel values // under the polyline with \doxygen{otb}{LikelihoodPathListFilter}. A higher value // will mean a higher Likelihood to be a road. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::LikelihoodPathListFilter<PathType, - InternalImageType> - PathListToPathListWithValueType; - PathListToPathListWithValueType::Pointer pathListConverter - = PathListToPathListWithValueType::New(); + + typedef otb::LikelihoodPathListFilter<PathType, InternalImageType> PathListToPathListWithValueType; + PathListToPathListWithValueType::Pointer pathListConverter = PathListToPathListWithValueType::New(); pathListConverter->SetInput(removeTortuousPathListFilter2->GetOutput()); pathListConverter->SetInputImage(nonMaxRemovalByDirectionFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // A black background image is built to draw the path on. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InternalImageType::Pointer output = InternalImageType::New(); output->CopyInformation(multispectralReader->GetOutput()); output->SetRegions(output->GetLargestPossibleRegion()); output->Allocate(); output->FillBuffer(0.0); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Polylines are drawn on a black background image with \doxygen{otb}{DrawPathListFilter}. // The \code{SetUseIternalValues()} tell the drawing filter to draw the path with its Likelihood // value. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::DrawPathListFilter<InternalImageType, PathType, - InternalImageType> DrawPathType; - DrawPathType::Pointer drawPathListFilter = DrawPathType::New(); + typedef otb::DrawPathListFilter<InternalImageType, PathType, InternalImageType> DrawPathType; + DrawPathType::Pointer drawPathListFilter = DrawPathType::New(); drawPathListFilter->SetInput(output); drawPathListFilter->SetInputPath(pathListConverter->GetOutput()); drawPathListFilter->SetUseInternalPathValue(true); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The output from the drawing filter contains very small values (Likelihood values). Therefore // the image has to be rescaled to be viewed. The whole pipeline is executed by invoking // the \code{Update()} method on this last filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InternalImageType, - InternalImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<InternalImageType, InternalImageType> RescalerType; + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetOutputMaximum(255); rescaler->SetOutputMinimum(0); rescaler->SetInput(drawPathListFilter->GetOutput()); rescaler->Update(); - // Software Guide : EndCodeSnippet // this small piece of code aims at producing a pretty RGB png result image. - typedef otb::MultiToMonoChannelExtractROI<OutputPixelType, - PixelType> - ChannelExtractionFilterType; - typedef itk::AddImageFilter<InternalImageType, InternalImageType, - InternalImageType> AddFilterType; - typedef itk::SubtractImageFilter<InternalImageType, InternalImageType, - InternalImageType> SubtractFilterType; - typedef itk::ThresholdImageFilter<InternalImageType> - ThresholdFilterType; - typedef itk::RGBPixel<OutputPixelType> - RGBPixelType; - typedef otb::Image<RGBPixelType, - Dimension> RGBImageType; - typedef itk::ComposeImageFilter<InternalImageType, - RGBImageType> ComposeFilterType; - typedef otb::ImageFileWriter<RGBImageType> - RGBWriterType; - typedef itk::BinaryBallStructuringElement<PixelType, - Dimension> StructuringElementType; - typedef itk::GrayscaleDilateImageFilter - <InternalImageType, InternalImageType, - StructuringElementType> DilateFilterType; + typedef otb::MultiToMonoChannelExtractROI<OutputPixelType, PixelType> ChannelExtractionFilterType; + typedef itk::AddImageFilter<InternalImageType, InternalImageType, InternalImageType> AddFilterType; + typedef itk::SubtractImageFilter<InternalImageType, InternalImageType, InternalImageType> SubtractFilterType; + typedef itk::ThresholdImageFilter<InternalImageType> ThresholdFilterType; + typedef itk::RGBPixel<OutputPixelType> RGBPixelType; + typedef otb::Image<RGBPixelType, Dimension> RGBImageType; + typedef itk::ComposeImageFilter<InternalImageType, RGBImageType> ComposeFilterType; + typedef otb::ImageFileWriter<RGBImageType> RGBWriterType; + typedef itk::BinaryBallStructuringElement<PixelType, Dimension> StructuringElementType; + typedef itk::GrayscaleDilateImageFilter<InternalImageType, InternalImageType, StructuringElementType> DilateFilterType; StructuringElementType se; se.SetRadius(1); se.CreateStructuringElement(); // Filters definitions - ChannelExtractionFilterType::Pointer channelExtractor1 = - ChannelExtractionFilterType::New(); - ChannelExtractionFilterType::Pointer channelExtractor2 = - ChannelExtractionFilterType::New(); - ChannelExtractionFilterType::Pointer channelExtractor3 = - ChannelExtractionFilterType::New(); - - AddFilterType::Pointer addFilter = AddFilterType::New(); - SubtractFilterType::Pointer subtract2 = SubtractFilterType::New(); - SubtractFilterType::Pointer subtract3 = SubtractFilterType::New(); + ChannelExtractionFilterType::Pointer channelExtractor1 = ChannelExtractionFilterType::New(); + ChannelExtractionFilterType::Pointer channelExtractor2 = ChannelExtractionFilterType::New(); + ChannelExtractionFilterType::Pointer channelExtractor3 = ChannelExtractionFilterType::New(); + + AddFilterType::Pointer addFilter = AddFilterType::New(); + SubtractFilterType::Pointer subtract2 = SubtractFilterType::New(); + SubtractFilterType::Pointer subtract3 = SubtractFilterType::New(); ThresholdFilterType::Pointer threshold11 = ThresholdFilterType::New(); ThresholdFilterType::Pointer threshold21 = ThresholdFilterType::New(); ThresholdFilterType::Pointer threshold31 = ThresholdFilterType::New(); @@ -472,7 +324,7 @@ int main(int itkNotUsed(argc), char * argv[]) ThresholdFilterType::Pointer threshold32 = ThresholdFilterType::New(); ComposeFilterType::Pointer composer = ComposeFilterType::New(); - RGBWriterType::Pointer writer = RGBWriterType::New(); + RGBWriterType::Pointer writer = RGBWriterType::New(); DilateFilterType::Pointer dilater = DilateFilterType::New(); @@ -530,8 +382,6 @@ int main(int itkNotUsed(argc), char * argv[]) writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex - // // Figures~\ref{fig:ROADEXTRACTIONBYSTEPS} and \ref{fig:ROADEXTRACTIONBYSTEPS2} // show the result of applying // the road extraction by steps to a fusionned Quickbird image. The result image @@ -559,7 +409,6 @@ int main(int itkNotUsed(argc), char * argv[]) // Likelihood values.} // \label{fig:ROADEXTRACTIONBYSTEPS2} // \end{figure} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/ExtractRoadExample.cxx b/Examples/FeatureExtraction/ExtractRoadExample.cxx index 7953e93a1c3860fdb70b5ff3fc8fbe49367bc254..94c4361e0d20c29ea24a6461e2248374e7047524 100644 --- a/Examples/FeatureExtraction/ExtractRoadExample.cxx +++ b/Examples/FeatureExtraction/ExtractRoadExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./ExtractRoadExample Input/qb_RoadExtract.tif Output/ExtractRoadOutput.png 337 557 432 859 1.0 0.00005 1.0 0.39269 1.0 10.0 25. +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {ExtractRoadOutput.png} -// 337 557 432 859 1.0 0.00005 1.0 0.39269 1.0 10.0 25. -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // The easiest way to use the road extraction filter provided by OTB is to use the composite // filter. If a modification in the pipeline is required to adapt to a particular situation, // the step by step example, described in the next section can be adapted. @@ -38,14 +34,10 @@ // proposed in \cite{Lacroix1998}. // // The first step toward the use of this filter is the inclusion of the proper header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbPolyLineParametricPathWithValue.h" #include "otbRoadExtractionFilter.h" #include "otbDrawPathListFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -57,142 +49,81 @@ #include "itkGrayscaleDilateImageFilter.h" #include "itkBinaryBallStructuringElement.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 14) - { + { std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputFileName outputFileName firstPixelComponent secondPixelComponent "; - std::cerr << - "thirdPixelComponent fourthPixelComponent alpha amplitudeThrehsold tolerance "; - std::cerr << - "angularThreshold-maxAngle firstMeanDistanceThreshold secondMeanDistanceThreshold "; + std::cerr << " inputFileName outputFileName firstPixelComponent secondPixelComponent "; + std::cerr << "thirdPixelComponent fourthPixelComponent alpha amplitudeThrehsold tolerance "; + std::cerr << "angularThreshold-maxAngle firstMeanDistanceThreshold secondMeanDistanceThreshold "; std::cerr << "distanceThreshold" << std::endl; return EXIT_FAILURE; - } + } const unsigned int Dimension = 2; - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We choose to do // all the computation in floating point precision and rescale the results // between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef double InputPixelType; typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the dimension. Please note that // the \doxygen{otb}{RoadExtractionFilter} needs an \doxygen{otb}{VectorImage} as input // to handle multispectral images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorImage<InputPixelType, Dimension> InputVectorImageType; typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type of the polyline that the filter produces. We use the // \doxygen{otb}{PolyLineParametricPathWithValue}, which allows the filter to produce // a likehood value along with each polyline. The filter is able to produce // \doxygen{itk}{PolyLineParametricPath} as well. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::PolyLineParametricPathWithValue<InputPixelType, - Dimension> PathType; - // Software Guide : EndCodeSnippet + typedef otb::PolyLineParametricPathWithValue<InputPixelType, Dimension> PathType; - // Software Guide : BeginLatex - // // Now we can define the \doxygen{otb}{RoadExtractionFilter} that takes a multi-spectral // image as input and produces a list of polylines. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::RoadExtractionFilter<InputVectorImageType, - PathType> RoadExtractionFilterType; - // Software Guide : EndCodeSnippet + typedef otb::RoadExtractionFilter<InputVectorImageType, PathType> RoadExtractionFilterType; - // Software Guide : BeginLatex - // // We also define an \doxygen{otb}{DrawPathListFilter} to draw the output // polylines on an image, taking their likehood values into account. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::DrawPathListFilter<InputImageType, PathType, - InputImageType> DrawPathFilterType; - // Software Guide : EndCodeSnippet + typedef otb::DrawPathListFilter<InputImageType, PathType, InputImageType> DrawPathFilterType; - // Software Guide : BeginLatex - // // The intensity rescaling of the results will be carried out by the // \doxygen{itk}{RescaleIntensityImageFilter} which is templated by the // input and output image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InputImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read // image data from a file. Then, an \doxygen{otb}{ImageFileWriter} // is instantiated in order to write the output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputVectorImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The different filters composing our pipeline are created by invoking their // \code{New()} methods, assigning the results to smart pointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); - RoadExtractionFilterType::Pointer roadExtractionFilter - = RoadExtractionFilterType::New(); - DrawPathFilterType::Pointer drawingFilter = DrawPathFilterType::New(); - RescalerType::Pointer rescaleFilter = RescalerType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + ReaderType::Pointer reader = ReaderType::New(); + RoadExtractionFilterType::Pointer roadExtractionFilter = RoadExtractionFilterType::New(); + DrawPathFilterType::Pointer drawingFilter = DrawPathFilterType::New(); + RescalerType::Pointer rescaleFilter = RescalerType::New(); + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \doxygen{otb}{RoadExtractionFilter} needs to have a reference pixel // corresponding to the spectral content likely to represent a road. This is done // by passing a pixel to the filter. Here we suppose that the input image // has four spectral bands. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InputVectorImageType::PixelType ReferencePixel; ReferencePixel.SetSize(4); ReferencePixel.SetElement(0, ::atof(argv[3])); @@ -200,162 +131,87 @@ int main(int argc, char * argv[]) ReferencePixel.SetElement(2, ::atof(argv[5])); ReferencePixel.SetElement(3, ::atof(argv[6])); roadExtractionFilter->SetReferencePixel(ReferencePixel); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We must also set the alpha parameter of the filter which allows us to tune the width of the roads // we want to extract. Typical value is $1.0$ and should be working in most situations. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetAlpha(atof(argv[7])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // All other parameter should not influence the results too much in most situation and can // be kept at the default value. // // The amplitude threshold parameter tunes the sensitivity of the vectorization step. A typical // value is $5 \cdot 10^{-5}$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetAmplitudeThreshold(atof(argv[8])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The tolerance threshold tunes the sensitivity of the path simplification step. // Typical value is $1.0$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetTolerance(atof(argv[9])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Roads are not likely to have sharp turns. Therefore we set the max angle parameter, // as well as the link angular threshold. The value is typically $\frac{\pi}{8}$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetMaxAngle(atof(argv[10])); roadExtractionFilter->SetAngularThreshold(atof(argv[10])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{RoadExtractionFilter} performs two odd path removing operations at different stage of // its execution. The first mean distance threshold and the second mean distance threshold set their criterion // for removal. Path are removed if their mean distance between nodes is to small, since such path coming // from previous filters are likely to be tortuous. The first removal operation as a typical mean distance // threshold parameter of $1.0$, and the second of $10.0$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetFirstMeanDistanceThreshold(atof(argv[11])); roadExtractionFilter->SetSecondMeanDistanceThreshold(atof(argv[12])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{RoadExtractionFilter} is able to link path whose ends are near // according to an euclidean distance criterion. The threshold for this distance // to link a path is the distance threshold parameter. A typical value is $25$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetDistanceThreshold(atof(argv[13])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We will now create a black background image to draw the resulting polyline on. // To achieve this we need to know the size of our input image. Therefore we trigger the // \code{GenerateOutputInformation()} of the reader. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->GenerateOutputInformation(); InputImageType::Pointer blackBackground = InputImageType::New(); blackBackground->CopyInformation(reader->GetOutput()); blackBackground->SetRegions(blackBackground->GetLargestPossibleRegion()); blackBackground->Allocate(); blackBackground->FillBuffer(0); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We tell the \doxygen{otb}{DrawPathListFilter} to try to use the likehood value // embedded within the polyline as a value for drawing this polyline if possible. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet drawingFilter->UseInternalPathValueOn(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // // The \code{itk::RescaleIntensityImageFilter} needs to know which // is the minimum and maximum values of the output generated // image. Those can be chosen in a generic way by using the // \code{NumericTraits} functions, since they are templated over // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaleFilter->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaleFilter->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now it is time for some pipeline wiring. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet roadExtractionFilter->SetInput(reader->GetOutput()); drawingFilter->SetInput(blackBackground); drawingFilter->SetInputPath(roadExtractionFilter->GetOutput()); rescaleFilter->SetInput(drawingFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The update of the pipeline is triggered by the \code{Update()} method // of the rescale intensity filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaleFilter->Update(); - // Software Guide : EndCodeSnippet // output image enhancement - typedef itk::BinaryBallStructuringElement<OutputPixelType, - Dimension> - StructuringElementType; - typedef itk::GrayscaleDilateImageFilter<OutputImageType, OutputImageType, - StructuringElementType> - DilateFilterType; - typedef itk::InvertIntensityImageFilter<OutputImageType, - OutputImageType> - InvertFilterType; + typedef itk::BinaryBallStructuringElement<OutputPixelType, Dimension> StructuringElementType; + typedef itk::GrayscaleDilateImageFilter<OutputImageType, OutputImageType, StructuringElementType> DilateFilterType; + typedef itk::InvertIntensityImageFilter<OutputImageType, OutputImageType> InvertFilterType; StructuringElementType se; se.SetRadius(1); @@ -373,8 +229,6 @@ int main(int argc, char * argv[]) writer->SetInput(invertFilter->GetOutput()); writer->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:ROADEXTRACTION_FILTER} shows the result of applying // the road extraction filter to a fusionned Quickbird image. // \begin{figure} @@ -387,8 +241,6 @@ int main(int argc, char * argv[]) // likehood values (color are inverted for display).} // \label{fig:ROADEXTRACTION_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/FlusserMomentsImageFunctionExample.cxx b/Examples/FeatureExtraction/FlusserMomentsImageFunctionExample.cxx index 1e903966afcbf99f49edd0b74937febbd9f34744..7c78689593781fe0b440fa057e17d10b8b81d097 100644 --- a/Examples/FeatureExtraction/FlusserMomentsImageFunctionExample.cxx +++ b/Examples/FeatureExtraction/FlusserMomentsImageFunctionExample.cxx @@ -19,45 +19,38 @@ */ - #include "itkMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// 2 -// Software Guide : EndCommandLineArgs +/* Example usage: +./FlusserMomentsImageFunctionExample Input/ROISpot5.png 2 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{FlusserMomentsImageFunction}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbFlusserMomentsImageFunction.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " neighborhood_radius" << std::endl; return EXIT_FAILURE; - } + } - const char * inputFilename = argv[1]; - const unsigned int radius = atoi(argv[2]); + const char* inputFilename = argv[1]; + const unsigned int radius = atoi(argv[2]); typedef unsigned char InputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; @@ -65,37 +58,27 @@ int main(int argc, char * argv[]) reader->SetFileName(inputFilename); - // Software Guide : BeginLatex - // // The \doxygen{otb}{FlusserMomentsImageFunction} is templated over the // input image type and the output (real) type value, so we start by // defining: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::FlusserMomentsImageFunction<InputImageType> FlusserType; - typedef FlusserType::OutputType MomentType; + typedef otb::FlusserMomentsImageFunction<InputImageType> FlusserType; + typedef FlusserType::OutputType MomentType; FlusserType::Pointer fmFunction = FlusserType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // We can choose the region and the pixel of the image which will // used as coordinate origin // for the moment computation - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InputImageType::RegionType region; InputImageType::SizeType size; InputImageType::IndexType start; start[0] = 0; start[1] = 0; - size[0] = 50; - size[1] = 50; + size[0] = 50; + size[1] = 50; reader->Update(); InputImageType::Pointer image = reader->GetOutput(); @@ -109,44 +92,27 @@ int main(int argc, char * argv[]) InputImageType::IndexType center; center[0] = start[0] + size[0] / 2; center[1] = start[1] + size[1] / 2; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Next, we plug the input image into the complex moment function // and we set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet fmFunction->SetInputImage(image); fmFunction->SetNeighborhoodRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // In order to get the value of the moment, we call the // \code{EvaluateAtIndex} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet MomentType Result = fmFunction->EvaluateAtIndex(center); - for (unsigned int j=0; j<11; ++j) - { - std::cout << "The moment of order " << j+1 << - " is equal to " << Result[j] << std::endl; - } - // Software Guide : EndCodeSnippet + for (unsigned int j = 0; j < 11; ++j) + { + std::cout << "The moment of order " << j + 1 << " is equal to " << Result[j] << std::endl; + } - // Software Guide : BeginLatex - // // \relatedClasses // \begin{itemize} // \item \doxygen{otb}{FlusserPathFunction} // \end{itemize} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/HarrisExample.cxx b/Examples/FeatureExtraction/HarrisExample.cxx index 7e8516c789c431f968795a9e3878ba14bc7614e7..62cc413105b759a9e7b22a0b26c95e0d051af1ff 100644 --- a/Examples/FeatureExtraction/HarrisExample.cxx +++ b/Examples/FeatureExtraction/HarrisExample.cxx @@ -19,77 +19,61 @@ */ - #include "itkMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5Harris.png} -// 1.5 2 0.1 -// Software Guide : EndCommandLineArgs +/* Example usage: +./HarrisExample Input/ROISpot5.png Output/ROISpot5Harris.png 1.5 2 0.1 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{HarrisImageFilter}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet #include "otbHarrisImageToPointSetFilter.h" #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " outputHarrisImageFile sigmaD sigmaI alpha" << std::endl; return EXIT_FAILURE; - } + } - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; - double SigmaD((double) ::atof(argv[3])); - double SigmaI((double) ::atof(argv[4])); - double Alpha((double) ::atof(argv[5])); + double SigmaD((double)::atof(argv[3])); + double SigmaI((double)::atof(argv[4])); + double Alpha((double)::atof(argv[5])); - typedef float InputPixelType; - const unsigned int Dimension = 2; + typedef float InputPixelType; + const unsigned int Dimension = 2; typedef unsigned char OutputPixelType; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; - // Software Guide : BeginLatex - // // The \doxygen{otb}{HarrisImageFilter} is templated over the // input and output image types, so we start by // defining: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::HarrisImageFilter<InputImageType, - InputImageType> HarrisFilterType; - // Software Guide : EndCodeSnippet - typedef itk::RescaleIntensityImageFilter - <InputImageType, OutputImageType> RescalerType; + typedef otb::HarrisImageFilter<InputImageType, InputImageType> HarrisFilterType; + typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> RescalerType; typedef otb::ImageFileWriter<OutputImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - HarrisFilterType::Pointer harris = HarrisFilterType::New(); + HarrisFilterType::Pointer harris = HarrisFilterType::New(); RescalerType::Pointer rescaler = RescalerType::New(); reader->SetFileName(inputFilename); @@ -97,8 +81,6 @@ int main(int argc, char *argv[]) harris->SetInput(reader->GetOutput()); - // Software Guide : BeginLatex - // // The \doxygen{otb}{HarrisImageFilter} needs some parameters to // operate. The derivative computation is performed by a // convolution with the derivative of a Gaussian kernel of @@ -113,14 +95,10 @@ int main(int argc, char *argv[]) // L_y^2(\mathbf{x},\sigma_D) \end{array}\right] // \end{equation} // The output of the detector is $$det(\mu) - \alpha trace^2(\mu).$$ - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet harris->SetSigmaD(SigmaD); harris->SetSigmaI(SigmaI); harris->SetAlpha(Alpha); - // Software Guide : EndCodeSnippet rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); @@ -129,7 +107,6 @@ int main(int argc, char *argv[]) writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:Harris} shows the result of applying the interest // point detector to a small patch extracted from a Spot 5 image. // \begin{figure} @@ -149,76 +126,49 @@ int main(int argc, char *argv[]) // \doxygen{otb}{HarrisImageToPointSetFilter}. This filter is only // templated over the input image type, the output being a // \doxygen{itk}{PointSet} with pixel type equal to the image pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::HarrisImageToPointSetFilter<InputImageType> FunctionType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare now the filter and a pointer to the output point set. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef FunctionType::OutputPointSetType OutputPointSetType; - FunctionType::Pointer harrisPoints = FunctionType::New(); - OutputPointSetType::Pointer pointSet = OutputPointSetType::New(); - // Software Guide : EndCodeSnippet + FunctionType::Pointer harrisPoints = FunctionType::New(); + OutputPointSetType::Pointer pointSet = OutputPointSetType::New(); - // Software Guide : BeginLatex - // // The \doxygen{otb}{HarrisImageToPointSetFilter} takes the same // parameters as the \doxygen{otb}{HarrisImageFilter} and an // additional parameter : the threshold for the point selection. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet harrisPoints->SetInput(0, reader->GetOutput()); harrisPoints->SetSigmaD(SigmaD); harrisPoints->SetSigmaI(SigmaI); harrisPoints->SetAlpha(Alpha); harrisPoints->SetLowerThreshold(10); pointSet = harrisPoints->GetOutput(); - // Software Guide : EndCodeSnippet harrisPoints->Update(); - // Software Guide : BeginLatex - // // We can now iterate through the obtained pointset and access // the coordinates of the points. We start by accessing the // container of the points which is encapsulated into the point // set (see section \ref{sec:PointSetSection} for more // information on using \doxygen{itk}{PointSet}s) and declaring // an iterator to it. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef OutputPointSetType::PointsContainer ContainerType; - ContainerType* pointsContainer = pointSet->GetPoints(); - typedef ContainerType::Iterator IteratorType; - IteratorType itList = pointsContainer->Begin(); - // Software Guide : EndCodeSnippet + ContainerType* pointsContainer = pointSet->GetPoints(); + typedef ContainerType::Iterator IteratorType; + IteratorType itList = pointsContainer->Begin(); - // Software Guide : BeginLatex - // // And we get the points coordinates - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet while (itList != pointsContainer->End()) - { + { typedef OutputPointSetType::PointType OutputPointType; - OutputPointType pCoordinate = (itList.Value()); + OutputPointType pCoordinate = (itList.Value()); std::cout << pCoordinate << std::endl; ++itList; - } - // Software Guide : EndCodeSnippet + } return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/HuMomentsImageFunctionExample.cxx b/Examples/FeatureExtraction/HuMomentsImageFunctionExample.cxx index d0aab9ffaebc057b0d6d8db06ea29c4c393c721f..b98812c6814e3ea6587dfc6cd97f8f7a1cfe0a67 100644 --- a/Examples/FeatureExtraction/HuMomentsImageFunctionExample.cxx +++ b/Examples/FeatureExtraction/HuMomentsImageFunctionExample.cxx @@ -19,45 +19,38 @@ */ - #include "itkMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// 2 -// Software Guide : EndCommandLineArgs +/* Example usage: +./HuMomentsImageFunctionExample Input/ROISpot5.png 2 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{HuMomentsImageFunction}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbHuMomentsImageFunction.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " moment_number" << std::endl; return EXIT_FAILURE; - } + } - const char * inputFilename = argv[1]; - const unsigned int radius = atoi(argv[2]); + const char* inputFilename = argv[1]; + const unsigned int radius = atoi(argv[2]); typedef unsigned char InputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; @@ -65,37 +58,27 @@ int main(int argc, char * argv[]) reader->SetFileName(inputFilename); - // Software Guide : BeginLatex - // // The \doxygen{otb}{HuImageFunction} is templated over the // input image type and the output (real) type value, so we start by // defining: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::HuMomentsImageFunction<InputImageType> HuType; - typedef HuType::OutputType MomentType; + typedef otb::HuMomentsImageFunction<InputImageType> HuType; + typedef HuType::OutputType MomentType; HuType::Pointer hmFunction = HuType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // We can choose the region and the pixel of the image which will // used as coordinate origin // for the moment computation - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InputImageType::RegionType region; InputImageType::SizeType size; InputImageType::IndexType start; start[0] = 0; start[1] = 0; - size[0] = 50; - size[1] = 50; + size[0] = 50; + size[1] = 50; reader->Update(); InputImageType::Pointer image = reader->GetOutput(); @@ -109,44 +92,27 @@ int main(int argc, char * argv[]) InputImageType::IndexType center; center[0] = start[0] + size[0] / 2; center[1] = start[1] + size[1] / 2; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Next, we plug the input image into the complex moment function // and we set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet hmFunction->SetInputImage(image); hmFunction->SetNeighborhoodRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // In order to get the value of the moment, we call the // \code{EvaluateAtIndex} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet MomentType Result = hmFunction->EvaluateAtIndex(center); - for (unsigned int j=0; j<7; ++j) - { - std::cout << "The moment of order " << j+1 << - " is equal to " << Result[j] << std::endl; - } - // Software Guide : EndCodeSnippet + for (unsigned int j = 0; j < 7; ++j) + { + std::cout << "The moment of order " << j + 1 << " is equal to " << Result[j] << std::endl; + } - // Software Guide : BeginLatex - // // \relatedClasses // \begin{itemize} // \item \doxygen{otb}{HuPathFunction} // \end{itemize} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx b/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx index 9dba61f8f97f922658b68bbf9cecd9d8d2ad1f88..f67425b9963b48eb08062faf10072693a8a2a515 100644 --- a/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx +++ b/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx @@ -24,27 +24,21 @@ #include "otbImageFileWriter.h" #include "otbVectorDataFileWriter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {Scene.png} -// OUTPUTS: {LSDOutput.shp} -// Software Guide : EndCommandLineArgs +/* Example usage: +./LineSegmentDetectorExample Input/Scene.png Output/LSDOutput.shp +*/ -// Software Guide : BeginLatex + +// Software Guide : BeginDescription // -// This example illustrates the use of the -// \doxygen{otb}{LineSegmentDetector}\cite{LSD}, also known as {\em Lucy in the -// Sky with Diamonds}. +// This example illustrates the use of the LineSegmentDetector. // This filter is designed to extract segments in mono channel images. // -// The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex +// Software Guide : EndDescription -// Software Guide : BeginCodeSnippet #include "otbLineSegmentDetector.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) { @@ -57,85 +51,44 @@ int main(int argc, char * argv[]) typedef unsigned char InputPixelType; typedef double PrecisionType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - // Software Guide : BeginLatex - // // As usual, we start by defining the types for the input image and // the image file reader. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::Image<InputPixelType, Dimension> ImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // We instantiate the reader and set the file name for the input image. - // - // Software Guide : EndLatex + typedef otb::Image<InputPixelType, Dimension> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; - // Software Guide : BeginCodeSnippet + // We instantiate the reader and set the file name for the input image. ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); reader->GenerateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define now the type for the segment detector filter. It is // templated over the input image type and the precision with which // the coordinates of the detected segments will be given. It is // recommended to set this precision to a real type. The output of the // filter will be a \doxygen{otb}{VectorData}. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet typedef otb::LineSegmentDetector<ImageType, PrecisionType> LsdFilterType; LsdFilterType::Pointer lsdFilter = LsdFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now define the type for the writer, instantiate it and set // the file name for the output vector data. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet typedef otb::VectorDataFileWriter<LsdFilterType::VectorDataType> WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outfname); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We plug the pipeline. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet lsdFilter->SetInput(reader->GetOutput()); writer->SetInput(lsdFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // Before calling the \code{Update()} method of the writer in order to + // Before calling the Update() method of the writer in order to // trigger the pipeline execution, we call the - // \code{GenerateOutputInformation()} of the reader, so the LSD + // GenerateOutputInformation() of the reader, so the LSD // filter gets the information about image size and spacing. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet reader->GenerateOutputInformation(); writer->Update(); - // Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/PanTexExample.cxx b/Examples/FeatureExtraction/PanTexExample.cxx index 4b19e875d81c022c2ad8060f497c5ad03c663420..9b2807b5fd1250328a820f485ef7ac4fc24d8c98 100644 --- a/Examples/FeatureExtraction/PanTexExample.cxx +++ b/Examples/FeatureExtraction/PanTexExample.cxx @@ -19,11 +19,10 @@ */ +/* Example usage: +./PanTexExample Input/ROI_QB_MUL_1.png Output/PanTexOutput.tif Output/pretty_PanTexInput.png Output/pretty_PanTexOutput.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1.png} -// OUTPUTS: {PanTexOutput.tif}, {pretty_PanTexInput.png}, {pretty_PanTexOutput.png} -// Software Guide : EndCommandLineArgs #include "itkMacro.h" #include "otbImage.h" @@ -32,8 +31,6 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{ScalarImageToPanTexTextureFilter}. This texture parameter was // first introduced in \cite{PanTex} and is very useful for urban area @@ -45,66 +42,47 @@ // \end{itemize} // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbScalarImageToPanTexTextureFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Parse command line parameters if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " <inputImage> "; std::cerr << " <outputImage> <inputRescaled> <outputRescaled> "; std::cerr << std::endl; return EXIT_FAILURE; - } + } - const char* infname = argv[1]; - const char* outfname = argv[2]; + const char* infname = argv[1]; + const char* outfname = argv[2]; const char* inprettyfname = argv[3]; - const char* outprettyfname = argv[4]; + const char* outprettyfname = argv[4]; - typedef double PixelType; - const int Dimension = 2; + typedef double PixelType; + const int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; - // Software Guide : BeginLatex -// -// After defining the types for the pixels and the images used in the -// example, we define the type for the PanTex filter. It is -// templated by the input and output image types. -// -// Software Guide : EndLatex + // After defining the types for the pixels and the images used in the + // example, we define the type for the PanTex filter. It is + // templated by the input and output image types. - // Software Guide : BeginCodeSnippet - typedef otb::ScalarImageToPanTexTextureFilter - <ImageType, ImageType> PanTexTextureFilterType; - // Software Guide : EndCodeSnippet - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; + typedef otb::ScalarImageToPanTexTextureFilter<ImageType, ImageType> PanTexTextureFilterType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<ImageType> WriterType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName(infname); writer->SetFileName(outfname); - // Software Guide : BeginLatex -// -// We can now instatiate the filter. -// -// Software Guide : EndLatex + // We can now instatiate the filter. - // Software Guide : BeginCodeSnippet PanTexTextureFilterType::Pointer textureFilter = PanTexTextureFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, we set the parameters of the filter.The radius of // the neighborhood to compute the texture. // The number of bins per axis for histogram generation (it is the @@ -112,32 +90,21 @@ int main(int argc, char * argv[]) // the Min/Max in the input image. In the example, image Min/Max is set // by the user to 0 and 255. Alternatively you can use the class \doxygen{itk}{MinimumMaximumImageCalculator} // to calculate these values. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet PanTexTextureFilterType::SizeType sradius; sradius.Fill(4); textureFilter->SetNumberOfBinsPerAxis(8); textureFilter->SetRadius(sradius); textureFilter->SetInputImageMinimum(0); textureFilter->SetInputImageMaximum(255); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now plug the pipeline and trigger the execution by calling // the \code{Update} method of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet textureFilter->SetInput(reader->GetOutput()); writer->SetInput(textureFilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:PANTEXFILTER} shows the result of applying // the PanTex computation. // \begin{figure} @@ -149,23 +116,15 @@ int main(int argc, char * argv[]) // original image, PanTex feature.} // \label{fig:PANTEXFILTER} // \end{figure} - // - // Software Guide : EndLatex // Pretty image creation for printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyOutputType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputPrettyImageType> - RescalerOutputType; + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyOutputType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputPrettyImageType> RescalerOutputType; RescalerOutputType::Pointer outputRescaler = RescalerOutputType::New(); - WriterPrettyOutputType::Pointer prettyOutputWriter = - WriterPrettyOutputType::New(); + WriterPrettyOutputType::Pointer prettyOutputWriter = WriterPrettyOutputType::New(); outputRescaler->SetInput(textureFilter->GetOutput()); outputRescaler->SetOutputMinimum(0); outputRescaler->SetOutputMaximum(255); diff --git a/Examples/FeatureExtraction/ParallelLineDetectionExample.cxx b/Examples/FeatureExtraction/ParallelLineDetectionExample.cxx index 6bb733a7476ef572163a1f9c1ea7fda6348291f3..305fd72b5ade098bd0ec217ee49a71b41c3211e6 100644 --- a/Examples/FeatureExtraction/ParallelLineDetectionExample.cxx +++ b/Examples/FeatureExtraction/ParallelLineDetectionExample.cxx @@ -19,18 +19,13 @@ */ +/* Example usage: +./ParallelLineDetectionExample Output/Lines.png Output/ParallelLines.png 20 2 10 +*/ -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {Lines.png}, {ParallelLines.png} -// 20 2 10 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the details of the \doxygen{otb}{ParallelLinePathListFilter}. // -// -// Software Guide : EndLatex #include "itkPolyLineParametricPath.h" #include "otbDrawPathListFilter.h" @@ -40,25 +35,23 @@ #include "otbImage.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " outputImage "; std::cerr << " outputParallelLineImage "; - std::cerr << - " distThreshParallel angThreshParallel commonDistThreshParallel" << - std::endl; + std::cerr << " distThreshParallel angThreshParallel commonDistThreshParallel" << std::endl; return EXIT_FAILURE; - } + } - double distThreshParallel = atof(argv[3]); - double angThreshParallel = atof(argv[4]); + double distThreshParallel = atof(argv[3]); + double angThreshParallel = atof(argv[4]); double commonDistThreshParallel = atof(argv[5]); - //We start by creating an empty image - const unsigned int Dimension = 2; + // We start by creating an empty image + const unsigned int Dimension = 2; typedef unsigned char PixelType; typedef otb::Image<PixelType, Dimension> ImageType; @@ -67,12 +60,12 @@ int main(int argc, char * argv[]) ImageType::IndexType start; - start[0] = 0; - start[1] = 0; + start[0] = 0; + start[1] = 0; ImageType::SizeType size; - size[0] = 600; - size[1] = 300; + size[0] = 600; + size[1] = 300; ImageType::RegionType region; @@ -89,7 +82,7 @@ int main(int argc, char * argv[]) PathListType::Pointer lineList = PathListType::New(); typedef PathType::ContinuousIndexType ContinuousIndexType; - ContinuousIndexType cindex; + ContinuousIndexType cindex; /*-----*/ PathType::Pointer aLine = PathType::New(); @@ -197,13 +190,13 @@ int main(int argc, char * argv[]) // Polylines are drawn on a black typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathType; - DrawPathType::Pointer drawPathListFilter = DrawPathType::New(); + DrawPathType::Pointer drawPathListFilter = DrawPathType::New(); drawPathListFilter->SetInput(image); drawPathListFilter->SetInputPath(lineList); drawPathListFilter->SetPathValue(itk::NumericTraits<PixelType>::max()); typedef otb::ImageFileWriter<ImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetInput(drawPathListFilter->GetOutput()); writer->SetFileName(argv[1]); writer->Update(); @@ -212,12 +205,10 @@ int main(int argc, char * argv[]) // threshold and a maximum distance threshold have to specified. // The input is a pathList of the previously extracted line segments. typedef otb::ParallelLinePathListFilter<PathType> ParallelLinePathType; - ParallelLinePathType::Pointer parallelLinePathListFilter = - ParallelLinePathType::New(); + ParallelLinePathType::Pointer parallelLinePathListFilter = ParallelLinePathType::New(); parallelLinePathListFilter->SetDistanceThreshold(distThreshParallel); parallelLinePathListFilter->SetAngularThreshold(angThreshParallel); - parallelLinePathListFilter->SetCommonDistanceThreshold( - commonDistThreshParallel); + parallelLinePathListFilter->SetCommonDistanceThreshold(commonDistThreshParallel); parallelLinePathListFilter->SetInput(lineList); parallelLinePathListFilter->Update(); @@ -230,11 +221,10 @@ int main(int argc, char * argv[]) // Parallel lines are drawn on a black background image with \doxygen{otb}{DrawPathListFilter}. // The \code{SetUseIternalValues()} tells the drawing filter to draw the path with its likelihood // value. - //typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathType; + // typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathType; DrawPathType::Pointer drawPathListFilterParallel = DrawPathType::New(); drawPathListFilterParallel->SetInput(outputParallel); - drawPathListFilterParallel->SetInputPath( - parallelLinePathListFilter->GetOutput()); + drawPathListFilterParallel->SetInputPath(parallelLinePathListFilter->GetOutput()); drawPathListFilter->SetPathValue(itk::NumericTraits<PixelType>::max()); drawPathListFilterParallel->SetUseInternalPathValue(false); diff --git a/Examples/FeatureExtraction/RatioLineDetectorExample.cxx b/Examples/FeatureExtraction/RatioLineDetectorExample.cxx index d4e413feeca44b3bdd1e20028627a0c7812e597d..51c519e07d7f6a62b7eb07502bba6d4edf3e6f84 100644 --- a/Examples/FeatureExtraction/RatioLineDetectorExample.cxx +++ b/Examples/FeatureExtraction/RatioLineDetectorExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./RatioLineDetectorExample Input/amst2.png Output/amstLineRatios.png Output/amstLineRatioDirections.png 5 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {amst2.png} -// OUTPUTS: {amstLineRatios.png}, {amstLineRatioDirections.png} -// 5 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{RatioLineDetectorImageFilter}. // This filter is used for line detection in SAR images. Its principle // is described in \cite{tup-98}: a line is detected if two parallel @@ -35,12 +31,8 @@ // ratio of means detector. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbLineRatioDetectorImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -48,187 +40,108 @@ #include "itkRescaleIntensityImageFilter.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; - std::cerr << - " outputEdgesImageFile outputDirectionsImageFile length width" << std::endl; + std::cerr << " outputEdgesImageFile outputDirectionsImageFile length width" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We // choose to make all computations with floating point precision // and rescale the results between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef float InternalPixelType; - typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet + typedef float InternalPixelType; + typedef unsigned char OutputPixelType; - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Image<InternalPixelType, 2> InternalImageType; - typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet + typedef otb::Image<InternalPixelType, 2> InternalImageType; + typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : BeginLatex - // // The filter can be instantiated using the image types defined above. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::LineRatioDetectorImageFilter - <InternalImageType, InternalImageType> FilterType; - // Software Guide : EndCodeSnippet + typedef otb::LineRatioDetectorImageFilter<InternalImageType, InternalImageType> FilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read // image data from a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InternalImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the // output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The intensity rescaling of the results will be carried out by the // \code{itk::RescaleIntensityImageFilter} which is templated by the // input and output image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InternalImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InternalImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // Both the filter and the reader are created by invoking their \code{New()} // methods and assigning the result to SmartPointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The same is done for the rescaler and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet RescalerType::Pointer rescaler = RescalerType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \code{itk::RescaleIntensityImageFilter} needs to know which // is the minimu and maximum values of the output generated // image. Those can be chosen in a generic way by using the // \code{NumericTraits} functions, since they are templated over // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the // \doxygen{otb}{LineRatioDetectorImageFilter}. The pipeline is built as follows. // // \index{otb::LineRatioDetectorImageFilter!SetInput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The methods \code{SetLengthLine()} and \code{SetWidthLine()} // allow setting the minimum length and the typical witdh of the // lines which are to be detected. // // \index{otb::LineRatioDetector!SetWidthLine()} // \index{otb::LineRatioDetector!SetLengthLine()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetLengthLine(atoi(argv[4])); filter->SetWidthLine(atoi(argv[5])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter is executed by invoking the \code{Update()} method. If the // filter is part of a larger image processing pipeline, calling // \code{Update()} on a downstream filter will also trigger update of this // filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->Update(); - // Software Guide : EndCodeSnippet writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex // We can also obtain the direction of the lines by invoking the // \code{GetOutputDirection()} method. - // Software Guide : EndLatex writer->SetFileName(argv[3]); - // Software Guide : BeginCodeSnippet rescaler->SetInput(filter->GetOutputDirection()); writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex Figure~\ref{fig:LINERATIO_FILTER} + // Figure~\ref{fig:LINERATIO_FILTER} // shows the result of applying the LineRatio edge detector filter // to a SAR image. \begin{figure} \center // \includegraphics[width=0.25\textwidth]{amst.eps} @@ -243,7 +156,6 @@ int main(int argc, char * argv[]) // \begin{itemize} // \item \doxygen{otb}{LineCorrelationDetectorImageFilter} // \end{itemize} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/RightAngleDetectionExample.cxx b/Examples/FeatureExtraction/RightAngleDetectionExample.cxx index 8671e67be9605061a3c3bd70e9275af0e011f123..db09ada8a90f02221e10ef3fde3c8491df7894f0 100644 --- a/Examples/FeatureExtraction/RightAngleDetectionExample.cxx +++ b/Examples/FeatureExtraction/RightAngleDetectionExample.cxx @@ -19,19 +19,15 @@ */ - #include "otbImageFileReader.h" #include "otbLineSegmentDetector.h" #include "otbVectorDataFileWriter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {Scene.png} -// OUTPUTS: {rightAngleOutput.shp} -// 0.1 20 -// Software Guide : EndCommandLineArgs +/* Example usage: +./RightAngleDetectionExample Input/Scene.png Output/rightAngleOutput.shp 0.1 20 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{VectorDataToRightAngleVectorDataFilter}. // This filter detects the right angles in an image by exploiting the @@ -41,14 +37,10 @@ // \cite{RightAngleDetection}. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVectorDataToRightAngleVectorDataFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 5) { @@ -61,7 +53,7 @@ int main(int argc, char * argv[]) double angleThreshold = atof(argv[3]); double distanceThreshold = atof(argv[4]); - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef unsigned char PixelType; typedef double PrecisionType; @@ -72,79 +64,42 @@ int main(int argc, char * argv[]) reader->SetFileName(infname); reader->GenerateOutputInformation(); - // Software Guide : BeginLatex - // // After defining, as usual, the types for the input image and the // image reader, we define the specific types needed for this // example. First of all, we will use a vector data // to store the detected lines which will be provided by the line // segment detector. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VectorData<PrecisionType> VectorDataType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + typedef otb::VectorData<PrecisionType> VectorDataType; // The right angle detector's output is a vector data where each point // gives the coordinate of the detected angle. // // Next, We define the type for the line segment detector. A detailed // example for this detector can be found in section \ref{sec:LSD}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::LineSegmentDetector<ImageType, PrecisionType> LsdFilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can finally define the type for the right angle detection // filter. This filter is templated over the input vector data type // provided by the line segment detector. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VectorDataToRightAngleVectorDataFilter<VectorDataType> - RightAngleFilterType; - // Software Guide : EndCodeSnippet + typedef otb::VectorDataToRightAngleVectorDataFilter<VectorDataType> RightAngleFilterType; - // Software Guide : BeginLatex - // // We instantiate the line segment detector and the right angle detector. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet auto lsdFilter = LsdFilterType::New(); auto rightAngleFilter = RightAngleFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We plug the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet lsdFilter->SetInput(reader->GetOutput()); rightAngleFilter->SetInput(lsdFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // You can choose how far the right angle segments can be, and the tolerance // to consider an angle between two segments as an right one. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rightAngleFilter->SetAngleThreshold(angleThreshold); rightAngleFilter->SetDistanceThreshold(distanceThreshold); - // Software Guide : EndCodeSnippet typedef otb::VectorDataFileWriter<LsdFilterType::VectorDataType> WriterType; @@ -153,19 +108,13 @@ int main(int argc, char * argv[]) rightAngleWriter->SetInput(rightAngleFilter->GetOutput()); rightAngleWriter->SetFileName(rightAngleOutputFilename); - // Software Guide : BeginLatex - // // Before calling the \code{Update()} method of the writers in order to // trigger the pipeline execution, we call the // \code{GenerateOutputInformation()} of the reader, so the // filter gets the information about image size and spacing. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->GenerateOutputInformation(); rightAngleWriter->Update(); - // Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/SFSExample.cxx b/Examples/FeatureExtraction/SFSExample.cxx index 4790b43b38fe7e885aad1e8ac315091a272427e0..cf546cc1f0f7da1a445f635e74301fd44d41a6c3 100644 --- a/Examples/FeatureExtraction/SFSExample.cxx +++ b/Examples/FeatureExtraction/SFSExample.cxx @@ -26,14 +26,28 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {suburb2.jpeg} -// OUTPUTS: {SFSLengthOutput.tif}, {SFSWidthOutput.tif}, {SFSMeanOutput.tif}, {SFSRatioOutput.tif}, {SFSSDOutput.tif}, {SFSPsiOutput.tif}, {SFSLengthPrettyOutput.tif}, {SFSWidthPrettyOutput.tif}, {SFSMeanPrettyOutput.tif}, {SFSRatioPrettyOutput.tif}, {SFSSDPrettyOutput.tif}, {SFSPsiPrettyOutput.tif} -// 20 50 8 4 0.6 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SFSExample Input/suburb2.jpeg \ + Output/SFSLengthOutput.tif \ + Output/SFSWidthOutput.tif \ + Output/SFSMeanOutput.tif \ + Output/SFSRatioOutput.tif \ + Output/SFSSDOutput.tif \ + Output/SFSPsiOutput.tif \ + Output/SFSLengthPrettyOutput.tif \ + Output/SFSWidthPrettyOutput.tif \ + Output/SFSMeanPrettyOutput.tif \ + Output/SFSRatioPrettyOutput.tif \ + Output/SFSSDPrettyOutput.tif \ + Output/SFSPsiPrettyOutput.tif \ + 20 \ + 50 \ + 8 \ + 4 \ + 0.6 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{SFSTexturesImageFilter}. // This filter computes the Structural Feature Set as described in @@ -42,16 +56,12 @@ // of the image. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSFSTexturesImageFilter.h" -// Software Guide : EndCodeSnippet -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { - typedef double PixelType; + typedef double PixelType; const unsigned int Dimension = 2; std::string inName = argv[1]; @@ -60,51 +70,34 @@ int main(int itkNotUsed(argc), char * argv[]) std::string outNameWMean = argv[4]; std::string outNameRatio = argv[5]; std::string outNameSD = argv[6]; - std::string outNamePsi = argv[7]; - std::string lengthprettyfname = argv[8]; - std::string widthprettyfname = argv[9]; - std::string wmeanprettyfname = argv[10]; - std::string ratioprettyfname = argv[11]; - std::string sdprettyfname = argv[12]; - std::string psiprettyfname = argv[13]; - PixelType spectThresh = atof(argv[14]); - unsigned int spatialThresh = atoi(argv[15]); - unsigned int dirNb = atoi(argv[16]); - unsigned int maxConsideration = atoi(argv[17]); - double alpha = atof(argv[18]); - -// Software Guide : BeginLatex -// -// As with every OTB program, we start by defining the types for the -// images, the readers and the writers. -// -// Software Guide : EndLatex + std::string outNamePsi = argv[7]; + std::string lengthprettyfname = argv[8]; + std::string widthprettyfname = argv[9]; + std::string wmeanprettyfname = argv[10]; + std::string ratioprettyfname = argv[11]; + std::string sdprettyfname = argv[12]; + std::string psiprettyfname = argv[13]; + PixelType spectThresh = atof(argv[14]); + unsigned int spatialThresh = atoi(argv[15]); + unsigned int dirNb = atoi(argv[16]); + unsigned int maxConsideration = atoi(argv[17]); + double alpha = atof(argv[18]); + + // As with every OTB program, we start by defining the types for the + // images, the readers and the writers. -// Software Guide : BeginCodeSnippet typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The we can instantiate the type for the SFS filter, which is -// templated over the input and output pixel types. -// -// Software Guide : EndLatex + // The we can instantiate the type for the SFS filter, which is + // templated over the input and output pixel types. -// Software Guide : BeginCodeSnippet typedef otb::SFSTexturesImageFilter<ImageType, ImageType> SFSFilterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// After that, we can instantiate the filter. We will also instantiate -// the reader and one writer for each output image, since the SFS -// filter generates 6 different features. -// -// Software Guide : EndLatex + // After that, we can instantiate the filter. We will also instantiate + // the reader and one writer for each output image, since the SFS + // filter generates 6 different features. -// Software Guide : BeginCodeSnippet - SFSFilterType::Pointer filter = SFSFilterType::New(); + SFSFilterType::Pointer filter = SFSFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writerLength = WriterType::New(); WriterType::Pointer writerWidth = WriterType::New(); @@ -112,55 +105,37 @@ int main(int itkNotUsed(argc), char * argv[]) WriterType::Pointer writerRatio = WriterType::New(); WriterType::Pointer writerSD = WriterType::New(); WriterType::Pointer writerPsi = WriterType::New(); -// Software Guide : EndCodeSnippet reader->SetFileName(inName); -// Software Guide : BeginLatex -// -// The SFS filter has several parameters which have to be -// selected. They are: -// \begin{enumerate} -// \item a spectral threshold to decide if 2 neighboring pixels are -// connected; -//\item a spatial threshold defining the maximum length for an -// extracted line; -//\item the number of directions which will be analyzed (the first -// one is to the right and they are equally distributed between 0 and -// $2\pi$); -// \item the $\alpha$ parameter fort the $\omega-mean$ feature; -// \item the RatioMax parameter fort the $\omega-mean$ feature. -// \end{enumerate} -// -// Software Guide : EndLatex + // The SFS filter has several parameters which have to be + // selected. They are: + // \begin{enumerate} + // \item a spectral threshold to decide if 2 neighboring pixels are + // connected; + //\item a spatial threshold defining the maximum length for an + // extracted line; + //\item the number of directions which will be analyzed (the first + // one is to the right and they are equally distributed between 0 and + // $2\pi$); + // \item the $\alpha$ parameter fort the $\omega-mean$ feature; + // \item the RatioMax parameter fort the $\omega-mean$ feature. + // \end{enumerate} -// Software Guide : BeginCodeSnippet filter->SetSpectralThreshold(spectThresh); filter->SetSpatialThreshold(spatialThresh); filter->SetNumberOfDirections(dirNb); filter->SetRatioMaxConsiderationNumber(maxConsideration); filter->SetAlpha(alpha); - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// In order to disable the computation of a feature, the -// \code{SetFeatureStatus} parameter can be used. The $true$ value -// enables the feature (default behavior) and the $false$ value -// disables the computation. Therefore, the following line is useless, -// but is given here as an example. -// -// Software Guide : EndLatex + // In order to disable the computation of a feature, the + // \code{SetFeatureStatus} parameter can be used. The $true$ value + // enables the feature (default behavior) and the $false$ value + // disables the computation. Therefore, the following line is useless, + // but is given here as an example. -// Software Guide : BeginCodeSnippet filter->SetFeatureStatus(SFSFilterType::PSI, true); - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Now, we plug the pipeline using all the writers. -// -// Software Guide : EndLatex + // Now, we plug the pipeline using all the writers. -// Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writerLength->SetFileName(outNameLength); @@ -186,8 +161,6 @@ int main(int itkNotUsed(argc), char * argv[]) writerPsi->SetFileName(outNamePsi); writerPsi->SetInput(filter->GetPSIOutput()); writerPsi->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:SFS_FILTER} shows the result of applying // the SFS computation to an image // \begin{figure} @@ -206,16 +179,11 @@ int main(int itkNotUsed(argc), char * argv[]) // original image, .} // \label{fig:SFS_FILTER} // \end{figure} - // - // Software Guide : EndLatex /************** pretty images for printing *********/ - typedef otb::Image<unsigned char, - 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescalerType; - typedef otb::ImageFileWriter<OutputImageType> - OutputWriterType; + typedef otb::Image<unsigned char, 2> OutputImageType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; + typedef otb::ImageFileWriter<OutputImageType> OutputWriterType; RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetOutputMinimum(0); diff --git a/Examples/FeatureExtraction/SURFExample.cxx b/Examples/FeatureExtraction/SURFExample.cxx index 8dc71211fbc0d2e265b9714b0d9067d6c047ecc7..0c1afa2a1d6a06704fe2a7a41ca03f77055f12f2 100644 --- a/Examples/FeatureExtraction/SURFExample.cxx +++ b/Examples/FeatureExtraction/SURFExample.cxx @@ -18,14 +18,11 @@ * limitations under the License. */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5SURF.png} -// 3 3 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SURFExample Input/ROISpot5.png Output/ROISpot5SURF.png 3 3 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{ImageToSURFKeyPointSetFilter}. The Speed-Up Robust // Features (or SURF) is an algorithm in computer vision to detect and @@ -34,12 +31,8 @@ // SIFT. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageToSURFKeyPointSetFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -50,295 +43,161 @@ #include <iostream> #include <fstream> -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 5) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " InputImage OutputImage octaves scales" << std::endl; return 1; - } - const char * infname = argv[1]; - const char * outputImageFilename = argv[2]; + } + const char* infname = argv[1]; + const char* outputImageFilename = argv[2]; const unsigned int octaves = atoi(argv[3]); - const unsigned int scales = atoi(argv[4]); + const unsigned int scales = atoi(argv[4]); const unsigned int Dimension = 2; -// Software Guide : BeginLatex -// -// We will start by defining the required types. We will work with a -// scalar image of float pixels. We also define the corresponding -// image reader. -// -// Software Guide : EndLatex + // We will start by defining the required types. We will work with a + // scalar image of float pixels. We also define the corresponding + // image reader. -// Software Guide : BeginCodeSnippet typedef float RealType; typedef otb::Image<RealType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The SURF descriptors will be stored in a point set containing the -// vector of features. -// -// Software Guide : EndLatex + // The SURF descriptors will be stored in a point set containing the + // vector of features. -// Software Guide : BeginCodeSnippet typedef itk::VariableLengthVector<RealType> RealVectorType; typedef itk::PointSet<RealVectorType, Dimension> PointSetType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The SURF filter itself is templated over the input image and the -// generated point set. -// -// Software Guide : EndLatex + // The SURF filter itself is templated over the input image and the + // generated point set. -// Software Guide : BeginCodeSnippet - typedef otb::ImageToSURFKeyPointSetFilter<ImageType, PointSetType> - ImageToFastSURFKeyPointSetFilterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the reader. -// -// Software Guide : EndLatex + typedef otb::ImageToSURFKeyPointSetFilter<ImageType, PointSetType> ImageToFastSURFKeyPointSetFilterType; + // We instantiate the reader. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the filter. -// -// Software Guide : EndLatex + // We instantiate the filter. -// Software Guide : BeginCodeSnippet - ImageToFastSURFKeyPointSetFilterType::Pointer filter = - ImageToFastSURFKeyPointSetFilterType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We plug the filter and set the number of scales for the SURF -// computation. We can afterwards run the processing with the -// \code{Update()} method. -// -// Software Guide : EndLatex + ImageToFastSURFKeyPointSetFilterType::Pointer filter = ImageToFastSURFKeyPointSetFilterType::New(); + // We plug the filter and set the number of scales for the SURF + // computation. We can afterwards run the processing with the + // \code{Update()} method. -// Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); filter->SetOctavesNumber(octaves); filter->SetScalesNumber(scales); filter->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Once the SURF are computed, we may want to draw them on top of the -// input image. In order to do this, we will create the following RGB -// image and the corresponding writer: -// -// Software Guide : EndLatex + // Once the SURF are computed, we may want to draw them on top of the + // input image. In order to do this, we will create the following RGB + // image and the corresponding writer: -// Software Guide : BeginCodeSnippet typedef unsigned char PixelType; typedef itk::RGBPixel<PixelType> RGBPixelType; typedef otb::Image<RGBPixelType, 2> OutputImageType; typedef otb::ImageFileWriter<OutputImageType> WriterType; OutputImageType::Pointer outputImage = OutputImageType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We set the regions of the image by copying the information from the -// input image and we allocate the memory for the output image. -// -// Software Guide : EndLatex + // We set the regions of the image by copying the information from the + // input image and we allocate the memory for the output image. -// Software Guide : BeginCodeSnippet outputImage->SetRegions(reader->GetOutput()->GetLargestPossibleRegion()); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now proceed to copy the input image into the output one -// using region iterators. The input image is a grey level one. The -// output image will be made of color crosses for each SURF on top of -// the grey level input image. So we start by copying the grey level -// values on each of the 3 channels of the color image. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - itk::ImageRegionIterator<OutputImageType> iterOutput( - outputImage, - outputImage-> - GetLargestPossibleRegion()); - itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), - reader->GetOutput()-> - GetLargestPossibleRegion()); - - for (iterOutput.GoToBegin(), iterInput.GoToBegin(); - !iterOutput.IsAtEnd(); - ++iterOutput, ++iterInput) - { + // We can now proceed to copy the input image into the output one + // using region iterators. The input image is a grey level one. The + // output image will be made of color crosses for each SURF on top of + // the grey level input image. So we start by copying the grey level + // values on each of the 3 channels of the color image. + + itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, outputImage->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion()); + + for (iterOutput.GoToBegin(), iterInput.GoToBegin(); !iterOutput.IsAtEnd(); ++iterOutput, ++iterInput) + { OutputImageType::PixelType rgbPixel; rgbPixel.SetRed(static_cast<PixelType>(iterInput.Get())); rgbPixel.SetGreen(static_cast<PixelType>(iterInput.Get())); rgbPixel.SetBlue(static_cast<PixelType>(iterInput.Get())); iterOutput.Set(rgbPixel); - } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We are now going to plot color crosses on the output image. We will -// need to define offsets (top, bottom, left and right) with respect -// to the SURF position in order to draw the cross segments. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - ImageType::OffsetType t = {{ 0, 1}}; - ImageType::OffsetType b = {{ 0, -1}}; - ImageType::OffsetType l = {{ 1, 0}}; + } + // We are now going to plot color crosses on the output image. We will + // need to define offsets (top, bottom, left and right) with respect + // to the SURF position in order to draw the cross segments. + + ImageType::OffsetType t = {{0, 1}}; + ImageType::OffsetType b = {{0, -1}}; + ImageType::OffsetType l = {{1, 0}}; ImageType::OffsetType r = {{-1, 0}}; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Now, we are going to access the point set generated by the SURF -// filter. The points are stored into a points container that we are -// going to walk through using an iterator. These are the types needed -// for this task: -// -// Software Guide : EndLatex + // Now, we are going to access the point set generated by the SURF + // filter. The points are stored into a points container that we are + // going to walk through using an iterator. These are the types needed + // for this task: -// Software Guide : BeginCodeSnippet typedef PointSetType::PointsContainer PointsContainerType; typedef PointsContainerType::Iterator PointsIteratorType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We set the iterator to the beginning of the point set. -// -// Software Guide : EndLatex + // We set the iterator to the beginning of the point set. -// Software Guide : BeginCodeSnippet PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We get the information about image size and spacing before drawing -// the crosses. -// -// Software Guide : EndLatex + // We get the information about image size and spacing before drawing + // the crosses. - // Software Guide : BeginCodeSnippet - ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing(); - ImageType::PointType origin = reader->GetOutput()->GetOrigin(); - //OutputImageType::SizeType size = outputImage->GetLargestPossibleRegion().GetSize(); + ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing(); + ImageType::PointType origin = reader->GetOutput()->GetOrigin(); + // OutputImageType::SizeType size = outputImage->GetLargestPossibleRegion().GetSize(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // And we iterate through the SURF set: - // - // Software Guide : EndLatex + // And we iterate through the SURF set: - // Software Guide : BeginCodeSnippet while (pIt != filter->GetOutput()->GetPoints()->End()) - { -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We get the pixel coordinates for each SURF by using the -// \code{Value()} method on the point set iterator. We use the -// information about size and spacing in order to convert the physical -// coordinates of the point into pixel coordinates. -// -// Software Guide : EndLatex + { + // We get the pixel coordinates for each SURF by using the + // \code{Value()} method on the point set iterator. We use the + // information about size and spacing in order to convert the physical + // coordinates of the point into pixel coordinates. -// Software Guide : BeginCodeSnippet ImageType::IndexType index; - index[0] = static_cast<unsigned int>(std::floor( - static_cast<double>( - (pIt.Value()[0] - - origin[0]) / spacing[0] + 0.5 - ))); - - index[1] = static_cast<unsigned int>(std::floor( - static_cast<double>( - (pIt.Value()[1] - - origin[1]) / spacing[1] + 0.5 - ))); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We create a green pixel. -// -// Software Guide : EndLatex + index[0] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[0] - origin[0]) / spacing[0] + 0.5))); + + index[1] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[1] - origin[1]) / spacing[1] + 0.5))); + // We create a green pixel. -// Software Guide : BeginCodeSnippet OutputImageType::PixelType keyPixel; keyPixel.SetRed(0); keyPixel.SetGreen(255); keyPixel.SetBlue(0); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We draw the crosses using the offsets and checking that we are -// inside the image, since SURFs on the image borders would cause an -// out of bounds pixel access. -// -// Software Guide : EndLatex + // We draw the crosses using the offsets and checking that we are + // inside the image, since SURFs on the image borders would cause an + // out of bounds pixel access. -// Software Guide : BeginCodeSnippet if (outputImage->GetLargestPossibleRegion().IsInside(index)) - { + { outputImage->SetPixel(index, keyPixel); - if (outputImage->GetLargestPossibleRegion().IsInside(index + - t)) - outputImage-> - SetPixel(index + t, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - b)) - outputImage-> - SetPixel(index + b, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - l)) - outputImage-> - SetPixel(index + l, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - r)) - outputImage-> - SetPixel(index + r, keyPixel); - } - ++pIt; + if (outputImage->GetLargestPossibleRegion().IsInside(index + t)) + outputImage->SetPixel(index + t, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + b)) + outputImage->SetPixel(index + b, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + l)) + outputImage->SetPixel(index + l, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + r)) + outputImage->SetPixel(index + r, keyPixel); } -// Software Guide : EndCodeSnippet + ++pIt; + } -// Software Guide : BeginLatex -// -// Finally, we write the image. -// -// Software Guide : EndLatex + // Finally, we write the image. -// Software Guide : BeginCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputImageFilename); writer->SetInput(outputImage); writer->Update(); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:SURFFast} shows the result of applying the SURF // point detector to a small patch extracted from a Spot 5 image. // \begin{figure} @@ -350,6 +209,5 @@ int main(int argc, char * argv[]) // image.} // \label{fig:SURFFast} // \end{figure} -// Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/SeamCarvingExample.cxx b/Examples/FeatureExtraction/SeamCarvingExample.cxx index 8dae6a2c46378ff4c3c8c9388feac29aeeeef155..854872a1b56ec802b03b13569154f4e1c2df596b 100644 --- a/Examples/FeatureExtraction/SeamCarvingExample.cxx +++ b/Examples/FeatureExtraction/SeamCarvingExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates the details of the seam carving operation. // References to this method can be found in \cite{Avidan07}. This example // details the use of \doxygen{otb}{ImageToCarvingPathFilter} and @@ -29,14 +26,11 @@ // // In this example, a loop is defined to remove a vertical or horizontal seam // at each step of the algorithm. The seam with the minimum energy is chosen. -// -// Software Guide : EndLatex -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {SeamCarvingExampleOutput.png} -// 50 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SeamCarvingExample Input/QB_Suburb.png Output/SeamCarvingExampleOutput.png 50 +*/ + #include "otbImage.h" #include "itkPolyLineParametricPath.h" @@ -52,97 +46,63 @@ #include "itkImageDuplicator.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { typedef float InputPixelType; typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::Image<InputPixelType, Dimension> ImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef itk::PolyLineParametricPath<Dimension> PathType; - typedef otb::ImageFileReader<ImageType> - ReaderType; - typedef otb::ImageFileWriter<OutputImageType> - WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescalerType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); RescalerType::Pointer rescaler = RescalerType::New(); - const char * filenamereader = argv[1]; + const char* filenamereader = argv[1]; reader->SetFileName(filenamereader); - const char * filenamewriter = argv[2]; + const char* filenamewriter = argv[2]; writer->SetFileName(filenamewriter); int iteration = atoi(argv[3]); - // Software Guide : BeginLatex - // // Energy is computed according to the gradient of the image, thus an // \doxygen{itk}{GradientMagnitudeImageFilter} is instantiated - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> GradientType; - GradientType::Pointer gradient = GradientType::New(); - // Software Guide : EndCodeSnippet + GradientType::Pointer gradient = GradientType::New(); - // Software Guide : BeginLatex - // // The \doxygen{otb}{ImageToCarvingPathFilter} compute the seam of minimum // energy according to lines or columns of the image. Later, as we will // choose the best option between the two, we need two of these filters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageToCarvingPathFilter<ImageType, PathType> CarvingFilterType; - CarvingFilterType::Pointer carvingFilterVert = CarvingFilterType::New(); - CarvingFilterType::Pointer carvingFilterHor = CarvingFilterType::New(); - // Software Guide : EndCodeSnippet + CarvingFilterType::Pointer carvingFilterVert = CarvingFilterType::New(); + CarvingFilterType::Pointer carvingFilterHor = CarvingFilterType::New(); - // Software Guide : BeginLatex - // // The \doxygen{otb}{RemoveCarvingPathFilter} will really resize the image // deleting the path. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::RemoveCarvingPathFilter - <ImageType, PathType, ImageType> RemoveCarvingPathFilterType; - RemoveCarvingPathFilterType::Pointer removeCarvingPath = - RemoveCarvingPathFilterType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::RemoveCarvingPathFilter<ImageType, PathType, ImageType> RemoveCarvingPathFilterType; + RemoveCarvingPathFilterType::Pointer removeCarvingPath = RemoveCarvingPathFilterType::New(); + // As we are going to iterate through the filters, we need to disconnect the // pipeline at one point and store the image somewhere. For that purpose, we // use an \doxygen{itk}{ImageDuplicator} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef itk::ImageDuplicator<ImageType> duplicatorType; - duplicatorType::Pointer duplicator = duplicatorType::New(); - // Software Guide : EndCodeSnippet + duplicatorType::Pointer duplicator = duplicatorType::New(); - // Software Guide : BeginLatex - // // Now that all elements have been instantiated, we start to plug the pipeline // and to define the loop. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); @@ -150,21 +110,15 @@ int main(int itkNotUsed(argc), char * argv[]) double energyVert, energyHor; for (int i = 0; i < iteration; ++i) - { + { gradient->SetInput(duplicator->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Two carving filters processed the gradient image to find the minimum // vertical seam and the minimum horizontal seam. Note that the // \code{UpdateLargestPossibleRegion()} need to be used as the size of the // input image will be different in each loop. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet carvingFilterVert->SetInput(gradient->GetOutput()); carvingFilterVert->SetDirection(0); carvingFilterVert->UpdateLargestPossibleRegion(); @@ -174,58 +128,36 @@ int main(int itkNotUsed(argc), char * argv[]) carvingFilterHor->SetDirection(1); carvingFilterHor->UpdateLargestPossibleRegion(); energyHor = carvingFilterHor->GetEnergyPerPix(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The vertical or the horizontal seam with the minimal energy is chosen. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet if (energyVert < energyHor) - { + { removeCarvingPath->SetInput(duplicator->GetOutput()); removeCarvingPath->SetInputPath(carvingFilterVert->GetOutput()); removeCarvingPath->SetDirection(0); removeCarvingPath->UpdateLargestPossibleRegion(); - } + } else - { + { removeCarvingPath->SetInput(duplicator->GetOutput()); removeCarvingPath->SetInputPath(carvingFilterHor->GetOutput()); removeCarvingPath->SetDirection(1); removeCarvingPath->UpdateLargestPossibleRegion(); - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // The duplicator filter keep the results for the next loop - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet duplicator->SetInputImage(removeCarvingPath->GetOutput()); duplicator->Update(); + } - } - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // // Finally, the resulting image is saved on an image file as usual - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetInput(duplicator->GetOutput()); writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:SEAMCARVING_FILTER} shows the result of applying // the seam carving filter to a satellite image. // \begin{figure} @@ -239,8 +171,6 @@ int main(int itkNotUsed(argc), char * argv[]) // seams with the lowest energy.} // \label{fig:SEAMCARVING_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx b/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx index 19362bd654be6fe7ae1ae2429666b1b4ffba29a7..f8ac6e4e1b794f09b246ba2105d9dff9333d823b 100644 --- a/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx +++ b/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{AddCarvingPathFilter}, // the opposite of the \doxygen{otb}{RemoveCarvingPathFilter}. // @@ -29,14 +26,11 @@ // output the image with the removed seam in white. // // Most of the code is similar to the previous example. -// -// Software Guide : EndLatex -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {SeamCarvingOtherExampleOutput.png} -// 50 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SeamCarvingOtherExample Input/QB_Suburb.png Output/SeamCarvingOtherExampleOutput.png 50 +*/ + #include "otbImage.h" #include "itkPolyLineParametricPath.h" @@ -54,94 +48,69 @@ #include "itkImageDuplicator.h" #include "otbObjectList.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { typedef float InputPixelType; typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::Image<InputPixelType, Dimension> ImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef itk::PolyLineParametricPath<Dimension> PathType; - // Software Guide : BeginLatex - // // We need to define a list to keep the path in memory until the end of // the seam carving process. This is done using an \doxygen{otb}{ObjectList} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ObjectList<PathType> PathListType; - PathListType::Pointer pathList = PathListType::New(); - // Software Guide : EndCodeSnippet - - typedef otb::ImageFileReader<ImageType> - ReaderType; - typedef otb::ImageFileWriter<OutputImageType> - WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescalerType; - - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + PathListType::Pointer pathList = PathListType::New(); + + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); RescalerType::Pointer rescaler = RescalerType::New(); - const char * filenamereader = argv[1]; + const char* filenamereader = argv[1]; reader->SetFileName(filenamereader); - const char * filenamewriter = argv[2]; + const char* filenamewriter = argv[2]; writer->SetFileName(filenamewriter); int iteration = atoi(argv[3]); - // Software Guide : BeginLatex - // // We instantiate the different filters of the pipeline as before. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> GradientType; - GradientType::Pointer gradient = GradientType::New(); + GradientType::Pointer gradient = GradientType::New(); typedef otb::ImageToCarvingPathFilter<ImageType, PathType> CarvingFilterType; - CarvingFilterType::Pointer carvingFilter = CarvingFilterType::New(); + CarvingFilterType::Pointer carvingFilter = CarvingFilterType::New(); - typedef otb::DrawPathFilter - <ImageType, PathType, ImageType> DrawPathFilterType; - DrawPathFilterType::Pointer drawPathFilter = DrawPathFilterType::New(); + typedef otb::DrawPathFilter<ImageType, PathType, ImageType> DrawPathFilterType; + DrawPathFilterType::Pointer drawPathFilter = DrawPathFilterType::New(); - typedef otb::RemoveCarvingPathFilter - <ImageType, PathType, ImageType> RemoveCarvingPathFilterType; - RemoveCarvingPathFilterType::Pointer removeCarvingPath = - RemoveCarvingPathFilterType::New(); + typedef otb::RemoveCarvingPathFilter<ImageType, PathType, ImageType> RemoveCarvingPathFilterType; + RemoveCarvingPathFilterType::Pointer removeCarvingPath = RemoveCarvingPathFilterType::New(); - typedef otb::AddCarvingPathFilter - <ImageType, PathType, ImageType> AddCarvingPathFilterType; - AddCarvingPathFilterType::Pointer addCarvingPath = - AddCarvingPathFilterType::New(); + typedef otb::AddCarvingPathFilter<ImageType, PathType, ImageType> AddCarvingPathFilterType; + AddCarvingPathFilterType::Pointer addCarvingPath = AddCarvingPathFilterType::New(); typedef itk::ImageDuplicator<ImageType> duplicatorType; - duplicatorType::Pointer duplicator = duplicatorType::New(); + duplicatorType::Pointer duplicator = duplicatorType::New(); reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The loop to shorten the image is similar to the previous one. Here we // decide to remove alternatively one vertical and one horizontal seam. At // each iteration, we save the seam on the list using the \code{PushBack()} // method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet for (int i = 0; i < iteration; ++i) - { + { gradient->SetInput(duplicator->GetOutput()); @@ -158,21 +127,14 @@ int main(int itkNotUsed(argc), char * argv[]) duplicator->SetInputImage(removeCarvingPath->GetOutput()); duplicator->Update(); + } - } - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // // The next loop will put back the seam using the // \doxygen{otb}{AddCarvingPathFilter} and drawing it with the // \doxygen{otb}{DrawPathFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet for (int i = iteration - 1; i >= 0; i--) - { + { addCarvingPath->SetInput(duplicator->GetOutput()); addCarvingPath->SetInputPath(pathList->GetNthElement(i)); @@ -185,23 +147,14 @@ int main(int itkNotUsed(argc), char * argv[]) duplicator->SetInputImage(drawPathFilter->GetOutput()); duplicator->Update(); - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // Finally, the resulting image is saved on an image file as usual - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetInput(duplicator->GetOutput()); writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:SEAMCARVING2_FILTER} shows the result of applying // the seam carving filter to a satellite image. // \begin{figure} @@ -214,8 +167,6 @@ int main(int itkNotUsed(argc), char * argv[]) // seams and the 25 horizontal seams.} // \label{fig:SEAMCARVING2_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/TextureExample.cxx b/Examples/FeatureExtraction/TextureExample.cxx index 284b5d582e2162a42150a46ad84b235b3fc84409..5705c69e64f14708a259f0274883f0ba4143af96 100644 --- a/Examples/FeatureExtraction/TextureExample.cxx +++ b/Examples/FeatureExtraction/TextureExample.cxx @@ -18,13 +18,9 @@ * limitations under the License. */ - - -// Software Guide : BeginCommandLineArgs -// INPUTS: {ADS40RoiSmall.png} -// OUTPUTS: {TextureOutput.tif}, {pretty_TextureOutput.png} -// 2 1 1 -// Software Guide : EndCommandLineArgs +/* Example usage: +./TextureExample Input/ADS40RoiSmall.png Output/TextureOutput.tif Output/pretty_TextureOutput.png 2 1 1 +*/ #include "itkMacro.h" #include "otbImage.h" @@ -36,75 +32,48 @@ #include "otbImageToVectorImageCastFilter.h" #include "otbVectorRescaleIntensityImageFilter.h" -// Software Guide : BeginLatex -// -// The first step required to use the filter is to include the header file. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet #include "otbScalarImageToTexturesFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Parse command line parameters if (argc != 7) - { + { std::cerr << "Usage: " << argv[0] << " <inputImage> "; std::cerr << " <outputImage> <outputRescaled> "; std::cerr << " <radius> <xOffset> <yOffset> "; std::cerr << std::endl; return EXIT_FAILURE; - } + } - const char* infname = argv[1]; - const char* outfname = argv[2]; - const char* outprettyfname = argv[3]; + const char* infname = argv[1]; + const char* outfname = argv[2]; + const char* outprettyfname = argv[3]; - const unsigned int radius = static_cast<unsigned int>(atoi(argv[4])); - const unsigned int xOffset = static_cast<unsigned int>(atoi(argv[5])); - const unsigned int yOffset = static_cast<unsigned int>(atoi(argv[6])); + const unsigned int radius = static_cast<unsigned int>(atoi(argv[4])); + const unsigned int xOffset = static_cast<unsigned int>(atoi(argv[5])); + const unsigned int yOffset = static_cast<unsigned int>(atoi(argv[6])); - typedef double PixelType; - const int Dimension = 2; + typedef double PixelType; + const int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; - // Software Guide : BeginLatex - // // After defining the types for the pixels and the images used in the // example, we define the types for the textures filter. It is // templated by the input and output image types. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::ScalarImageToTexturesFilter - <ImageType, ImageType> TexturesFilterType; - // Software Guide : EndCodeSnippet + typedef otb::ScalarImageToTexturesFilter<ImageType, ImageType> TexturesFilterType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<ImageType> WriterType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; - - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName(infname); writer->SetFileName(outfname); - // Software Guide : BeginLatex - // // We can now instantiate the filters. - // - // Software Guide : EndLatex + TexturesFilterType::Pointer texturesFilter = TexturesFilterType::New(); - // Software Guide : BeginCodeSnippet - TexturesFilterType::Pointer texturesFilter - = TexturesFilterType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // // The texture filters takes at least 2 parameters: the radius of the // neighborhood on which the texture will be computed and the offset // used. Texture features are bivariate statistics, that is, they are @@ -117,84 +86,47 @@ int main(int argc, char * argv[]) // // The offset is always an array of N values, where N is the number of // dimensions of the image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet + typedef ImageType::SizeType SizeType; - SizeType sradius; + SizeType sradius; sradius.Fill(radius); texturesFilter->SetRadius(sradius); typedef ImageType::OffsetType OffsetType; - OffsetType offset; - offset[0] = xOffset; - offset[1] = yOffset; + OffsetType offset; + offset[0] = xOffset; + offset[1] = yOffset; texturesFilter->SetOffset(offset); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The textures filter will automatically derive the optimal // bin size for co-occurences histogram, but they need to know // the input image minimum and maximum. These values can be set // like this : - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet + texturesFilter->SetInputImageMinimum(0); texturesFilter->SetInputImageMaximum(255); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To tune co-occurence histogram resolution, you can use // the SetNumberOfBinsPerAxis() method. - // - // Software Guide : EndLatex - // Software Guide : BeginLatex - // // We can now plug the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet texturesFilter->SetInput(reader->GetOutput()); - writer->SetInput(texturesFilter->GetInertiaOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // Figure~\ref{fig:TEXTUREFUNCTOR} shows the result of applying - // the contrast texture computation. - // \begin{figure} - // \center - // \includegraphics[width=0.40\textwidth]{ADS40RoiSmall.eps} - // \includegraphics[width=0.40\textwidth]{pretty_TextureOutput.eps} - // \itkcaption[Results of applying Haralick contrast]{Result of applying the - // \doxygen{otb}{ScalarImageToTexturesFilter} to an image. From left to right : - // original image, contrast.} - // \label{fig:TEXTUREFUNCTOR} - // \end{figure} - // - // Software Guide : EndLatex // Pretty image creation for printing + typedef otb::VectorImage<double, 2> VectorImageType; + typedef otb::VectorImage<unsigned char, 2> PrettyVectorImageType; + typedef otb::ImageFileWriter<PrettyVectorImageType> WriterPrettyOutputType; - typedef otb::VectorImage<double, 2> VectorImageType; - typedef otb::VectorImage<unsigned char, 2> PrettyVectorImageType; - typedef otb::ImageFileWriter<PrettyVectorImageType> - WriterPrettyOutputType; - - typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> VectorCastFilterType; - typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, PrettyVectorImageType> - RescalerOutputType; + typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> VectorCastFilterType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, PrettyVectorImageType> RescalerOutputType; RescalerOutputType::Pointer outputRescaler = RescalerOutputType::New(); - WriterPrettyOutputType::Pointer prettyOutputWriter = - WriterPrettyOutputType::New(); - VectorCastFilterType::Pointer vectorCastFilter = VectorCastFilterType::New(); + WriterPrettyOutputType::Pointer prettyOutputWriter = WriterPrettyOutputType::New(); + VectorCastFilterType::Pointer vectorCastFilter = VectorCastFilterType::New(); vectorCastFilter->SetInput(texturesFilter->GetInertiaOutput()); outputRescaler->SetInput(vectorCastFilter->GetOutput()); @@ -209,5 +141,4 @@ int main(int argc, char * argv[]) prettyOutputWriter->SetInput(outputRescaler->GetOutput()); prettyOutputWriter->Update(); - return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/TextureExample.rst b/Examples/FeatureExtraction/TextureExample.rst new file mode 100644 index 0000000000000000000000000000000000000000..9ec770a77913c5e14b2265d9b1581ddf8f7b3c75 --- /dev/null +++ b/Examples/FeatureExtraction/TextureExample.rst @@ -0,0 +1,3 @@ +.. figure:: /Output/pretty_TextureOutput.png + + Result of applying the ScalarImageToTexturesFilter to an image (contrast). diff --git a/Examples/FeatureExtraction/ThresholdToPointSetExample.cxx b/Examples/FeatureExtraction/ThresholdToPointSetExample.cxx index 6b2fe6ef8841810d6a8d5962a8ebaa61ddbd29f1..44f2645a1b5f3b3f4c62d26da35971acc1f6f4cf 100644 --- a/Examples/FeatureExtraction/ThresholdToPointSetExample.cxx +++ b/Examples/FeatureExtraction/ThresholdToPointSetExample.cxx @@ -20,14 +20,11 @@ */ +/* Example usage: +./ThresholdToPointSetExample Input/ROISpot5.png 250 252 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// 250 252 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // Sometimes, it may be more valuable not to get an image from the threshold // step but rather a list of coordinates. This can be done with the // \doxygen{otb}{ThresholdImageToPointSetFilter}. @@ -36,137 +33,86 @@ // \doxygen{otb}{ThresholdImageToPointSetFilter} which provide a list of points // within given thresholds. Points set are described in section // \ref{sec:PointSetSection} on page \pageref{sec:PointSetSection}. -// -// Software Guide : EndLatex #include "otbImage.h" #include "otbImageFileReader.h" -// Software Guide : BeginLatex -// // The first step required to use this filter is to include the header -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbThresholdImageToPointSetFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 3) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; std::cerr << " lowerThreshold upperThreshold" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // The next step is to decide which pixel types to use for the input image // and the Point Set as well as their dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned char PixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; typedef itk::PointSet<PixelType, Dimension> PointSetType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // A reader is instantiated to read the input image - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); - const char * filenamereader = argv[1]; + const char* filenamereader = argv[1]; reader->SetFileName(filenamereader); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We get the parameters from the command line for the threshold filter. The // lower and upper thresholds parameters are similar to those of the // \doxygen{itk}{BinaryThresholdImageFilter} (see Section // \ref{sec:BinaryThresholdingImageFilter} on page // \pageref{sec:BinaryThresholdingImageFilter} for more information). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet int lowerThreshold = atoi(argv[2]); int upperThreshold = atoi(argv[3]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then we create the ThresholdImageToPointSetFilter and we pass the // parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ThresholdImageToPointSetFilter - <ImageType, PointSetType> FilterThresholdType; - FilterThresholdType::Pointer filterThreshold = FilterThresholdType::New(); + typedef otb::ThresholdImageToPointSetFilter<ImageType, PointSetType> FilterThresholdType; + FilterThresholdType::Pointer filterThreshold = FilterThresholdType::New(); filterThreshold->SetLowerThreshold(lowerThreshold); filterThreshold->SetUpperThreshold(upperThreshold); filterThreshold->SetInput(0, reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To manipulate and display the result of this filter, we manually // instantiate a point set and we call the \code{Update()} method on the // threshold filter to trigger the pipeline execution. // // After this step, the \code{pointSet} variable contains the point set. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - PointSetType::Pointer pointSet = PointSetType::New(); - pointSet = filterThreshold->GetOutput(); + PointSetType::Pointer pointSet = PointSetType::New(); + pointSet = filterThreshold->GetOutput(); filterThreshold->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To display each point, we create an iterator on the list of points, // which is accessible through the method \code{GetPoints()} of the PointSet. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef PointSetType::PointsContainer ContainerType; - ContainerType* pointsContainer = pointSet->GetPoints(); - typedef ContainerType::Iterator IteratorType; - IteratorType itList = pointsContainer->Begin(); - // Software Guide : EndCodeSnippet + ContainerType* pointsContainer = pointSet->GetPoints(); + typedef ContainerType::Iterator IteratorType; + IteratorType itList = pointsContainer->Begin(); - // Software Guide : BeginLatex - // // A while loop enable us to through the list a display the coordinate of // each point. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet while (itList != pointsContainer->End()) - { + { std::cout << itList.Value() << std::endl; ++itList; - } - // Software Guide : EndCodeSnippet + } return EXIT_SUCCESS; } diff --git a/Examples/FeatureExtraction/TouziEdgeDetectorExample.cxx b/Examples/FeatureExtraction/TouziEdgeDetectorExample.cxx index d11eb71bd3bc2f98a7fe68c552d2c28ebbebf3ed..7db34e035577d2282f2e651be609566a51c115a5 100644 --- a/Examples/FeatureExtraction/TouziEdgeDetectorExample.cxx +++ b/Examples/FeatureExtraction/TouziEdgeDetectorExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./TouziEdgeDetectorExample Input/amst2.png Output/amstTouziEdges.png Output/amstTouziDirections.png 3 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {amst2.png} -// OUTPUTS: {amstTouziEdges.png}, {amstTouziDirections.png} -// 3 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{TouziEdgeDetectorImageFilter}. // This filter belongs to the family of the fixed false alarm rate // edge detectors but it is appropriate for SAR images, where the @@ -45,202 +41,118 @@ // response is kept. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbTouziEdgeDetectorImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 5) - { + { std::cerr << "Usage: " << argv[0] << " inputImageFile "; - std::cerr << " outputEdgesImageFile outputDirectionsImageFile radius" << - std::endl; + std::cerr << " outputEdgesImageFile outputDirectionsImageFile radius" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We // choose to make all computations with floating point precision // and rescale the results between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef float InternalPixelType; - typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet + typedef float InternalPixelType; + typedef unsigned char OutputPixelType; - // Software Guide : BeginLatex - // // The images are defined using the pixel type and the dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Image<InternalPixelType, 2> InternalImageType; - typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet + typedef otb::Image<InternalPixelType, 2> InternalImageType; + typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : BeginLatex - // // The filter can be instantiated using the image types defined above. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::TouziEdgeDetectorImageFilter<InternalImageType, - InternalImageType> FilterType; - // Software Guide : EndCodeSnippet + typedef otb::TouziEdgeDetectorImageFilter<InternalImageType, InternalImageType> FilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read // image data from a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InternalImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the // output image to a file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The intensity rescaling of the results will be carried out by the // \code{itk::RescaleIntensityImageFilter} which is templated by the // input and output image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<InternalImageType, - OutputImageType> RescalerType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InternalImageType, OutputImageType> RescalerType; - // Software Guide : BeginLatex - // // Both the filter and the reader are created by invoking their \code{New()} // methods and assigning the result to SmartPointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The same is done for the rescaler and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet RescalerType::Pointer rescaler = RescalerType::New(); - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); - // Software Guide : BeginLatex - // // The \code{itk::RescaleIntensityImageFilter} needs to know which // is the minimu and maximum values of the output generated // image. Those can be chosen in a generic way by using the // \code{NumericTraits} functions, since they are templated over // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image obtained with the reader is passed as input to the // \doxygen{otb}{TouziEdgeDetectorImageFilter}. The pipeline is built as follows. // // \index{otb::TouziEdgeDetectorImageFilter!SetInput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The method \code{SetRadius()} defines the size of the window to // be used for the computation of the local means. // // \index{otb::LeeImageFilter!SetRadius()} // \index{otb::LeeImageFilter!NbLooks()} // \index{SetNbLooks()!otb::LeeImageFilter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FilterType::SizeType Radius; Radius[0] = atoi(argv[4]); Radius[1] = atoi(argv[4]); filter->SetRadius(Radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter is executed by invoking the \code{Update()} method. If the // filter is part of a larger image processing pipeline, calling // \code{Update()} on a downstream filter will also trigger update of this // filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->Update(); - // Software Guide : EndCodeSnippet writer->SetFileName(argv[2]); writer->Update(); - // Software Guide : BeginLatex // We can also obtain the direction of the edges by invoking the // \code{GetOutputDirection()} method. - // Software Guide : EndLatex writer->SetFileName(argv[3]); - // Software Guide : BeginCodeSnippet rescaler->SetInput(filter->GetOutputDirection()); writer->SetInput(rescaler->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:TOUZI_FILTER} shows the result of applying the Touzi // edge detector // filter to a SAR image. @@ -254,8 +166,6 @@ int main(int argc, char * argv[]) // original image, edge intensity and edge orientation.} // \label{fig:TOUZI_FILTER} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Filtering/CompositeFilterExample.cxx b/Examples/Filtering/CompositeFilterExample.cxx index c00a4e10cca99849f38838608b8a0d7ed7fb39c3..3c1a73a752697b0866b24b7e6c23fb481d382c49 100644 --- a/Examples/Filtering/CompositeFilterExample.cxx +++ b/Examples/Filtering/CompositeFilterExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // The composite filter we will build combines three filters: a gradient // magnitude operator, which will calculate the first-order derivative of // the image; a thresholding step to select edges over a given strength; @@ -31,63 +28,39 @@ // // Since this filter takes an image and produces another image (of // identical type), we will specialize the ImageToImageFilter: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // Next we include headers for the component filters: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkUnaryFunctorImageFilter.h" #include "itkGradientMagnitudeImageFilter.h" #include "itkThresholdImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : EndCodeSnippet #include "itkNumericTraits.h" #include "otbImage.h" -// Software Guide : BeginLatex -// // Now we can declare the filter itself. It is within the OTB namespace, // and we decide to make it use the same image type for both input and // output, thus the template declaration needs only one parameter. // Deriving from \code{ImageToImageFilter} provides default behavior for // several important aspects, notably allocating the output image (and // making it the same dimensions as the input). -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet namespace otb { template <class TImageType> -class ITK_EXPORT CompositeExampleImageFilter : - public itk::ImageToImageFilter<TImageType, TImageType> +class ITK_EXPORT CompositeExampleImageFilter : public itk::ImageToImageFilter<TImageType, TImageType> { public: -// Software Guide : EndCodeSnippet + // Next we have the standard declarations, used for object creation with + // the object factory: -// Software Guide : BeginLatex -// -// Next we have the standard declarations, used for object creation with -// the object factory: -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet typedef CompositeExampleImageFilter Self; typedef itk::ImageToImageFilter<TImageType, TImageType> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; -// Software Guide : EndCodeSnippet /** Method for creation through object factory */ itkNewMacro(Self); @@ -98,100 +71,67 @@ public: /** Display */ void PrintSelf(std::ostream& os, itk::Indent indent) const override; -// Software Guide : BeginLatex -// -// Here we declare an alias (to save typing) for the image's pixel type, -// which determines the type of the threshold value. We then use the -// convenience macros to define the Get and Set methods for this parameter. -// -// Software Guide : EndLatex + // Here we declare an alias (to save typing) for the image's pixel type, + // which determines the type of the threshold value. We then use the + // convenience macros to define the Get and Set methods for this parameter. -// Software Guide : BeginCodeSnippet typedef typename TImageType::PixelType PixelType; itkGetMacro(Threshold, PixelType); itkSetMacro(Threshold, PixelType); -// Software Guide : EndCodeSnippet protected: - CompositeExampleImageFilter(); -// Software Guide : BeginLatex -// -// Now we can declare the component filter types, templated over the -// enclosing image type: -// -// Software Guide : EndLatex + // Now we can declare the component filter types, templated over the + // enclosing image type: -// Software Guide : BeginCodeSnippet protected: - - typedef itk::ThresholdImageFilter<TImageType> ThresholdType; - typedef itk::GradientMagnitudeImageFilter<TImageType, TImageType> - GradientType; - typedef itk::RescaleIntensityImageFilter<TImageType, TImageType> - RescalerType; -// Software Guide : EndCodeSnippet + typedef itk::ThresholdImageFilter<TImageType> ThresholdType; + typedef itk::GradientMagnitudeImageFilter<TImageType, TImageType> GradientType; + typedef itk::RescaleIntensityImageFilter<TImageType, TImageType> RescalerType; void GenerateData() override; private: + CompositeExampleImageFilter(Self&); // intentionally not implemented + void operator=(const Self&); // intentionally not implemented - CompositeExampleImageFilter(Self &); // intentionally not implemented - void operator =(const Self&); // intentionally not implemented + // The component filters are declared as data members, all using the smart + // pointer types. -// Software Guide : BeginLatex -// -// The component filters are declared as data members, all using the smart -// pointer types. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typename GradientType::Pointer m_GradientFilter; + typename GradientType::Pointer m_GradientFilter; typename ThresholdType::Pointer m_ThresholdFilter; - typename RescalerType::Pointer m_RescaleFilter; + typename RescalerType::Pointer m_RescaleFilter; PixelType m_Threshold; }; } /* namespace otb */ -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // The constructor sets up the pipeline, which involves creating the // stages, connecting them together, and setting default parameters. -// -// Software Guide : EndLatex namespace otb { -// Software Guide : BeginCodeSnippet template <class TImageType> -CompositeExampleImageFilter<TImageType> -::CompositeExampleImageFilter() +CompositeExampleImageFilter<TImageType>::CompositeExampleImageFilter() { - m_GradientFilter = GradientType::New(); + m_GradientFilter = GradientType::New(); m_ThresholdFilter = ThresholdType::New(); - m_RescaleFilter = RescalerType::New(); + m_RescaleFilter = RescalerType::New(); m_ThresholdFilter->SetInput(m_GradientFilter->GetOutput()); m_RescaleFilter->SetInput(m_ThresholdFilter->GetOutput()); m_Threshold = 1; - m_RescaleFilter->SetOutputMinimum( - itk::NumericTraits<PixelType>::NonpositiveMin()); + m_RescaleFilter->SetOutputMinimum(itk::NumericTraits<PixelType>::NonpositiveMin()); m_RescaleFilter->SetOutputMaximum(itk::NumericTraits<PixelType>::max()); } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // The \code{GenerateData()} is where the composite magic happens. First, // we connect the first component filter to the inputs of the composite // filter (the actual input, supplied by the upstream stage). Then we @@ -200,14 +140,9 @@ CompositeExampleImageFilter<TImageType> // pipeline to be processed by calling \code{Update()} on the final stage, // then graft the output back onto the output of the enclosing filter, so // it has the result available to the downstream filter. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet template <class TImageType> -void -CompositeExampleImageFilter<TImageType>:: -GenerateData() +void CompositeExampleImageFilter<TImageType>::GenerateData() { m_GradientFilter->SetInput(this->GetInput()); @@ -217,43 +152,28 @@ GenerateData() m_RescaleFilter->Update(); this->GraftOutput(m_RescaleFilter->GetOutput()); } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // Finally we define the \code{PrintSelf} method, which (by convention) // prints the filter parameters. Note how it invokes the superclass to // print itself first, and also how the indentation prefixes each line. // -// Software Guide : EndLatex -// -// Software Guide : BeginCodeSnippet template <class TImageType> -void -CompositeExampleImageFilter<TImageType>:: -PrintSelf(std::ostream& os, itk::Indent indent) const +void CompositeExampleImageFilter<TImageType>::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); - os - << indent << "Threshold:" << this->m_Threshold - << std::endl; + os << indent << "Threshold:" << this->m_Threshold << std::endl; } } /* end namespace otb */ -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // It is important to note that in the above example, none of the internal // details of the pipeline were exposed to users of the class. The interface // consisted of the Threshold parameter (which happened to change the value in // the component filter) and the regular ImageToImageFilter interface. This // example pipeline is illustrated in // Figure~\ref{fig:CompositeExamplePipeline}. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -261,11 +181,11 @@ PrintSelf(std::ostream& os, itk::Indent indent) const int main(int argc, char* argv[]) { if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl; return EXIT_FAILURE; - } + } typedef otb::Image<short, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; @@ -284,13 +204,13 @@ int main(int argc, char* argv[]) writer->SetFileName(argv[2]); try - { + { writer->Update(); - } - catch ( itk::ExceptionObject & e ) - { + } + catch (itk::ExceptionObject& e) + { std::cerr << "Error: " << e << std::endl; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Filtering/DanielssonDistanceMapImageFilter.cxx b/Examples/Filtering/DanielssonDistanceMapImageFilter.cxx index 032705f606dc982c813792590668e29eef913736..747e09f08cfdf74e21259fbc3fa4b67fcfa9e5ba 100644 --- a/Examples/Filtering/DanielssonDistanceMapImageFilter.cxx +++ b/Examples/Filtering/DanielssonDistanceMapImageFilter.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./DanielssonDistanceMapImageFilter Input/FivePoints.png Output/DanielssonDistanceMapImageFilterOutput1.png Output/DanielssonDistanceMapImageFilterOutput2.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {FivePoints.png} -// OUTPUTS: {DanielssonDistanceMapImageFilterOutput1.png} -// OUTPUTS: {DanielssonDistanceMapImageFilterOutput2.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{itk}{DanielssonDistanceMapImageFilter}. This filter generates a // distance map from the input image using the algorithm developed by @@ -42,13 +38,9 @@ // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!Header} // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkConnectedComponentImageFilter.h" #include "itkDanielssonDistanceMapImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -56,37 +48,29 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " inputImageFile outputDistanceMapImageFile "; std::cerr << " outputVoronoiMapImageFilter "; std::cerr << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel types to use for the input and output // images. Since the output will contain distances measured in pixels, the // pixel type should be able to represent at least the width of the image, // or said in $N-D$ terms, the maximum extension along all the dimensions. // The input and output image types are now defined using their respective // pixel type and dimension. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef unsigned char InputPixelType; - typedef unsigned short OutputPixelType; - typedef otb::Image<InputPixelType, 2> InputImageType; + typedef unsigned char InputPixelType; + typedef unsigned short OutputPixelType; + typedef otb::Image<InputPixelType, 2> InputImageType; typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter type can be instantiated using the input and output image // types defined above. A filter object is created with the \code{New()} // method. @@ -94,22 +78,15 @@ int main(int argc, char * argv[]) // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!instantiation} // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!New()} // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!Pointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::ConnectedComponentImageFilter< - InputImageType, InputImageType> ConnectedType; - ConnectedType::Pointer connectedComponents = ConnectedType::New(); + typedef itk::ConnectedComponentImageFilter<InputImageType, InputImageType> ConnectedType; + ConnectedType::Pointer connectedComponents = ConnectedType::New(); - typedef itk::DanielssonDistanceMapImageFilter< - InputImageType, OutputImageType, OutputImageType> FilterType; - FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet + typedef itk::DanielssonDistanceMapImageFilter<InputImageType, OutputImageType, OutputImageType> FilterType; + FilterType::Pointer filter = FilterType::New(); - typedef itk::RescaleIntensityImageFilter< - OutputImageType, OutputImageType> RescalerType; - RescalerType::Pointer scaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputImageType> RescalerType; + RescalerType::Pointer scaler = RescalerType::New(); // // Reader and Writer types are instantiated. @@ -123,41 +100,27 @@ int main(int argc, char * argv[]) reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : BeginLatex - // // The input to the filter is taken from a reader and its output is passed // to a \doxygen{itk}{RescaleIntensityImageFilter} and then to a writer. // // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!SetInput()} // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!GetOutput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet connectedComponents->SetInput(reader->GetOutput()); filter->SetInput(connectedComponents->GetOutput()); scaler->SetInput(filter->GetOutput()); writer->SetInput(scaler->GetOutput()); - // Software Guide : EndCodeSnippet scaler->SetOutputMaximum(65535L); scaler->SetOutputMinimum(0L); - // Software Guide : BeginLatex - // // The type of input image has to be specified. In this case, a binary // image is selected. // // \index{itk::Danielsson\-Distance\-MapImage\-Filter!InputIsBinaryOn()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->InputIsBinaryOff(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // \begin{figure} // \center // \includegraphics[width=0.32\textwidth]{FivePoints.eps} @@ -178,35 +141,23 @@ int main(int argc, char * argv[]) // // \index{Voronoi partitions} // \index{Voronoi partitions!itk::Danielsson\-Distance\-Map\-Image\-Filter} - // - // Software Guide : EndLatex writer->Update(); - const char * voronoiMapFileName = argv[3]; + const char* voronoiMapFileName = argv[3]; - // Software Guide : BeginLatex - // // The Voronoi map is obtained with the \code{GetVoronoiMap()} method. In // the lines below we connect this output to the intensity rescaler and // save the result in a file. // // \index{itk::Danielsson\-Distance\-Map\-Image\-Filter!GetVoronoiMap()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet scaler->SetInput(filter->GetVoronoiMap()); writer->SetFileName(voronoiMapFileName); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Execution of the writer is triggered by the invocation of the // \code{Update()} method. Since this method can potentially throw // exceptions it must be placed in a \code{try/catch} block. - // - // Software Guide : EndLatex return EXIT_SUCCESS; diff --git a/Examples/Filtering/SecondDerivativeRecursiveGaussianImageFilter.cxx b/Examples/Filtering/SecondDerivativeRecursiveGaussianImageFilter.cxx index d5b35dc41b171054f2d0ed7f06ad6cf114f1070f..580bd1cd15ea3c7bf9d989131578be38e3bedd4e 100644 --- a/Examples/Filtering/SecondDerivativeRecursiveGaussianImageFilter.cxx +++ b/Examples/Filtering/SecondDerivativeRecursiveGaussianImageFilter.cxx @@ -19,19 +19,13 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates how to compute second derivatives of // an image using the \doxygen{itk}{RecursiveGaussianImageFilter}. // // In this example, all the second derivatives are computed independently in // the same way as if they were intended to be used for building the Hessian // matrix of the image. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkRecursiveGaussianImageFilter.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -39,22 +33,22 @@ #include "otbImage.h" #include <string> -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImage outputPrefix [sigma] " << std::endl; return EXIT_FAILURE; - } + } typedef float PixelType; typedef float OutputPixelType; const unsigned int Dimension = 2; - typedef otb::Image<PixelType, Dimension> ImageType; + typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef otb::ImageFileReader<ImageType> ReaderType; @@ -62,14 +56,12 @@ int main(int argc, char * argv[]) typedef itk::ImageDuplicator<OutputImageType> DuplicatorType; - typedef itk::RecursiveGaussianImageFilter< - ImageType, - ImageType> FilterType; + typedef itk::RecursiveGaussianImageFilter<ImageType, ImageType> FilterType; - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); - DuplicatorType::Pointer duplicator = DuplicatorType::New(); + DuplicatorType::Pointer duplicator = DuplicatorType::New(); reader->SetFileName(argv[1]); @@ -77,15 +69,15 @@ int main(int argc, char * argv[]) std::string outputFileName; try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& excp) - { + { std::cerr << "Problem reading the input file" << std::endl; std::cerr << excp << std::endl; return EXIT_FAILURE; - } + } FilterType::Pointer ga = FilterType::New(); FilterType::Pointer gb = FilterType::New(); @@ -96,12 +88,12 @@ int main(int argc, char * argv[]) gc->SetDirection(2); if (argc > 3) - { + { const float sigma = atof(argv[3]); ga->SetSigma(sigma); gb->SetSigma(sigma); gc->SetSigma(sigma); - } + } ga->SetZeroOrder(); gb->SetZeroOrder(); @@ -125,8 +117,8 @@ int main(int argc, char * argv[]) writer->SetFileName(outputFileName); writer->Update(); - gc->SetDirection(1); // gc now works along Y - gb->SetDirection(2); // gb now works along Z + gc->SetDirection(1); // gc now works along Y + gb->SetDirection(2); // gb now works along Z gc->Update(); duplicator->Update(); @@ -138,8 +130,8 @@ int main(int argc, char * argv[]) writer->SetFileName(outputFileName); writer->Update(); - gc->SetDirection(0); // gc now works along X - ga->SetDirection(1); // ga now works along Y + gc->SetDirection(0); // gc now works along X + ga->SetDirection(1); // ga now works along Y gc->Update(); duplicator->Update(); @@ -204,7 +196,6 @@ int main(int argc, char * argv[]) outputFileName = outputPrefix + "-Ixy.hdr"; writer->SetFileName(outputFileName); writer->Update(); - // Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/Fusion/BayesianFusionImageFilter.cxx b/Examples/Fusion/BayesianFusionImageFilter.cxx index d215328b7969065f23336b5e9ac4e6b879c2e1de..bfc9b5a94634edce50e7ca3b08ce2ed5e31fb9fc 100644 --- a/Examples/Fusion/BayesianFusionImageFilter.cxx +++ b/Examples/Fusion/BayesianFusionImageFilter.cxx @@ -20,21 +20,32 @@ */ +/* Example usage: +./BayesianFusionImageFilter Input/multiSpect.tif \ + Input/multiSpectInterp.tif \ + Input/panchro.tif \ + Output/BayesianFusion_0.9999.tif \ + Output/pretty_BayesianFusion_0.9999.png \ + Output/pretty_multiSpect_0.9999.png \ + Output/pretty_multiSpectInterp_0.9999.png \ + Output/pretty_panchro_0.9999.png \ + 0.9999 +*/ + + +/* Example usage: +./BayesianFusionImageFilter Input/multiSpect.tif \ + Input/multiSpectInterp.tif \ + Input/panchro.tif \ + Output/BayesianFusion_0.5.tif \ + Output/pretty_BayesianFusion_0.5.png \ + Output/pretty_multiSpect_0.5.png \ + Output/pretty_multiSpectInterp_0.5.png \ + Output/pretty_panchro_0.5.png \ + 0.5 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {multiSpect.tif} , {multiSpectInterp.tif}, {panchro.tif} -// OUTPUTS: {BayesianFusion_0.9999.tif} , {pretty_BayesianFusion_0.9999.png} , {pretty_multiSpect_0.9999.png} , {pretty_multiSpectInterp_0.9999.png} , {pretty_panchro_0.9999.png} -// 0.9999 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {multiSpect.tif} , {multiSpectInterp.tif}, {panchro.tif} -// OUTPUTS: {BayesianFusion_0.5.tif} , {pretty_BayesianFusion_0.5.png} , {pretty_multiSpect_0.5.png} , {pretty_multiSpectInterp_0.5.png} , {pretty_panchro_0.5.png} -// 0.5 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// // \index{otb::BayesianFusionFilter} // \index{otb::BayesianFusionFilter!header} // @@ -65,11 +76,8 @@ // // Let's look at the minimal code required to use this algorithm. First, the following header // defining the otb::BayesianFusionFilter class must be included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbBayesianFusionFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "itkCastImageFilter.h" @@ -79,142 +87,94 @@ #include "otbVectorRescaleIntensityImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 10) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; std::cerr << " inputMultiSpectralImage inputMultiSpectralInterpolatedImage " << "inputPanchromatiqueImage outputImage outputImagePrinted " - << "msPrinted msiPrinted panchroPrinted lambda" - << std::endl; + << "msPrinted msiPrinted panchroPrinted lambda" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // The image types are now defined using pixel types and particular // dimension. The panchromatic image is defined as an \doxygen{otb}{Image} // and the multispectral one as \doxygen{otb}{VectorImage}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef double InternalPixelType; - const unsigned int Dimension = 2; + typedef double InternalPixelType; + const unsigned int Dimension = 2; typedef otb::Image<InternalPixelType, Dimension> PanchroImageType; typedef otb::VectorImage<InternalPixelType, Dimension> MultiSpecImageType; - // Software Guide : EndCodeSnippet typedef double OutputPixelType; typedef otb::VectorImage<OutputPixelType, Dimension> OutputImageType; // We instantiate reader and writer types // - typedef otb::ImageFileReader<MultiSpecImageType> ReaderVectorType; - typedef otb::ImageFileReader<PanchroImageType> ReaderType; - typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef otb::ImageFileReader<MultiSpecImageType> ReaderVectorType; + typedef otb::ImageFileReader<PanchroImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; ReaderVectorType::Pointer multiSpectReader = ReaderVectorType::New(); ReaderVectorType::Pointer multiSpectInterpReader = ReaderVectorType::New(); - ReaderType::Pointer panchroReader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + ReaderType::Pointer panchroReader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); multiSpectReader->SetFileName(argv[1]); multiSpectInterpReader->SetFileName(argv[2]); panchroReader->SetFileName(argv[3]); writer->SetFileName(argv[4]); - // Software Guide : BeginLatex - // // The Bayesian data fusion filter type is instantiated using the images types as // a template parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::BayesianFusionFilter<MultiSpecImageType, - MultiSpecImageType, - PanchroImageType, - OutputImageType> - BayesianFusionFilterType; - // Software Guide : EndCodeSnippet + typedef otb::BayesianFusionFilter<MultiSpecImageType, MultiSpecImageType, PanchroImageType, OutputImageType> BayesianFusionFilterType; - // Software Guide : BeginLatex - // // Next the filter is created by invoking the \code{New()} method and // assigning the result to a \doxygen{itk}{SmartPointer}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - BayesianFusionFilterType::Pointer bayesianFilter = - BayesianFusionFilterType::New(); - // Software Guide : EndCodeSnippet + BayesianFusionFilterType::Pointer bayesianFilter = BayesianFusionFilterType::New(); - // Software Guide : BeginLatex - // // Now the multi spectral image, the interpolated multi spectral image and // the panchromatic image are given as inputs to the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet bayesianFilter->SetMultiSpect(multiSpectReader->GetOutput()); bayesianFilter->SetMultiSpectInterp(multiSpectInterpReader->GetOutput()); bayesianFilter->SetPanchro(panchroReader->GetOutput()); writer->SetInput(bayesianFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The BayesianFusionFilter requires defining one parameter : $\lambda$. // The $\lambda$ parameter can be used to tune the fusion toward either a high color // consistency or sharp details. Typical $\lambda$ value range in $[0.5, 1[$, where higher // values yield sharper details. by default $\lambda$ is set at 0.9999. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet bayesianFilter->SetLambda(atof(argv[9])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The invocation of the \code{Update()} method on the writer triggers the // execution of the pipeline. It is recommended to place update calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } // Create an 3 band images for the software guide - typedef unsigned char OutputPixelType2; - typedef otb::VectorImage<OutputPixelType2, Dimension> OutputVectorImageType; - typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; - typedef otb::VectorRescaleIntensityImageFilter<MultiSpecImageType, - OutputVectorImageType> - VectorRescalerType; - typedef otb::VectorRescaleIntensityImageFilter<OutputImageType, - OutputVectorImageType> - VectorRescalerBayesianType; - typedef otb::ImageToVectorImageCastFilter<PanchroImageType, - MultiSpecImageType> CasterType; - typedef otb::MultiChannelExtractROI<OutputPixelType2, - OutputPixelType2> - ChannelExtractorType; + typedef unsigned char OutputPixelType2; + typedef otb::VectorImage<OutputPixelType2, Dimension> OutputVectorImageType; + typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; + typedef otb::VectorRescaleIntensityImageFilter<MultiSpecImageType, OutputVectorImageType> VectorRescalerType; + typedef otb::VectorRescaleIntensityImageFilter<OutputImageType, OutputVectorImageType> VectorRescalerBayesianType; + typedef otb::ImageToVectorImageCastFilter<PanchroImageType, MultiSpecImageType> CasterType; + typedef otb::MultiChannelExtractROI<OutputPixelType2, OutputPixelType2> ChannelExtractorType; multiSpectReader->GenerateOutputInformation(); multiSpectInterpReader->GenerateOutputInformation(); @@ -257,24 +217,24 @@ int main(int argc, char *argv[]) rp->SetOutputMaximum(maximum); rp->SetClampThreshold(0.01); - ChannelExtractorType::Pointer selecterms = ChannelExtractorType::New(); + ChannelExtractorType::Pointer selecterms = ChannelExtractorType::New(); ChannelExtractorType::Pointer selectermsi = ChannelExtractorType::New(); - ChannelExtractorType::Pointer selecterf = ChannelExtractorType::New(); + ChannelExtractorType::Pointer selecterf = ChannelExtractorType::New(); selecterms->SetInput(vrms->GetOutput()); -// selecterms->SetExtractionRegion(multiSpectReader->GetOutput()->GetLargestPossibleRegion()); + // selecterms->SetExtractionRegion(multiSpectReader->GetOutput()->GetLargestPossibleRegion()); selecterms->SetChannel(2); selecterms->SetChannel(3); selecterms->SetChannel(4); selectermsi->SetInput(vrmsi->GetOutput()); -// selectermsi->SetExtractionRegion(multiSpectInterpReader->GetOutput()->GetLargestPossibleRegion()); + // selectermsi->SetExtractionRegion(multiSpectInterpReader->GetOutput()->GetLargestPossibleRegion()); selectermsi->SetChannel(2); selectermsi->SetChannel(3); selectermsi->SetChannel(4); selecterf->SetInput(vrb->GetOutput()); - //selecterf->SetExtractionRegion(bayesianFilter->GetOutput()->GetLargestPossibleRegion()); + // selecterf->SetExtractionRegion(bayesianFilter->GetOutput()->GetLargestPossibleRegion()); selecterf->SetChannel(2); selecterf->SetChannel(3); selecterf->SetChannel(4); @@ -294,25 +254,23 @@ int main(int argc, char *argv[]) vectWriterp->SetInput(rp->GetOutput()); try - { + { vectWriterms->Update(); vectWritermsi->Update(); vectWriterf->Update(); vectWriterp->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Let's now run this example using as input the images // \code{multiSpect.tif} , \code{multiSpectInterp.tif} and \code{panchro.tif} // provided in the directory \code{Examples/Data}. The results @@ -337,8 +295,6 @@ int main(int argc, char *argv[]) // \label{fig:BayesianImageFusionFilterOutput} // \end{figure} // - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Fusion/PanSharpeningExample.cxx b/Examples/Fusion/PanSharpeningExample.cxx index 0b3ccf8672694bdde64daa81af641f0891fcb4bd..5be6ba95c95770f62d6c9cc3796b2b03c605d98f 100644 --- a/Examples/Fusion/PanSharpeningExample.cxx +++ b/Examples/Fusion/PanSharpeningExample.cxx @@ -19,18 +19,15 @@ * limitations under the License. */ +/* Example usage: +./example Input/QB_Toulouse_Ortho_PAN.tif \ + Input/QB_Toulouse_Ortho_XS.tif \ + Output/QB_Toulouse_Ortho_PXS.tif \ + Output/pretty_QB_Toulouse_Ortho_PXS.png \ + Output/pretty_QB_Toulouse_Ortho_PAN.png \ + Output/pretty_QB_Toulouse_Ortho_XS.png +*/ - -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Toulouse_Ortho_PAN.tif}, {QB_Toulouse_Ortho_XS.tif} -// OUTPUTS: {QB_Toulouse_Ortho_PXS.tif} -// OUTPUTS: {pretty_QB_Toulouse_Ortho_PXS.png} -// OUTPUTS: {pretty_QB_Toulouse_Ortho_PAN.png} -// OUTPUTS: {pretty_QB_Toulouse_Ortho_XS.png} -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// // Here we are illustrating the use of the // \doxygen{otb}{SimpleRcsPanSharpeningFusionImageFilter} for PAN-sharpening. // This example takes a PAN and the corresponding XS images as input. These @@ -41,11 +38,7 @@ // \begin{equation} // \frac{XS}{\mathrm{Filtered}(PAN)} PAN // \end{equation} -// -// Software Guide : EndLatex -// Software Guide : BeginLatex -// // Figure~\ref{fig:PANSHARP_FILTER} shows the result of applying // this PAN sharpening filter to a Quickbird image. // \begin{figure} @@ -60,108 +53,69 @@ // result of the PAN sharpening} // \label{fig:PANSHARP_FILTER} // \end{figure} -// -// Software Guide : EndLatex -// Software Guide : BeginLatex -// // We start by including the required header and declaring the main function: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbSimpleRcsPanSharpeningFusionImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbPrintableImageFilter.h" #include "itkRescaleIntensityImageFilter.h" #include "otbImageToVectorImageCastFilter.h" -// Software Guide : BeginCodeSnippet int main(int argc, char* argv[]) { -// Software Guide : EndCodeSnippet if (argc < 7) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputPanchromatiqueImage inputMultiSpectralImage outputImage outputImagePrinted panchroPrinted msPrinted" - << std::endl; + std::cerr << " inputPanchromatiqueImage inputMultiSpectralImage outputImage outputImagePrinted panchroPrinted msPrinted" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // We declare the different image type used here as well as the image reader. // Note that, the reader for the PAN image is templated by an // \doxygen{otb}{Image} while the XS reader uses an // \doxygen{otb}{VectorImage}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<double, 2> ImageType; typedef otb::VectorImage<double, 2> VectorImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileReader<VectorImageType> ReaderVectorType; typedef otb::VectorImage<unsigned short int, 2> VectorIntImageType; - ReaderVectorType::Pointer readerXS = ReaderVectorType::New(); + ReaderVectorType::Pointer readerXS = ReaderVectorType::New(); ReaderType::Pointer readerPAN = ReaderType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We pass the filenames to the readers - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet readerPAN->SetFileName(argv[1]); readerXS->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare the fusion filter an set its inputs using the readers: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::SimpleRcsPanSharpeningFusionImageFilter - <ImageType, VectorImageType, VectorIntImageType> FusionFilterType; - FusionFilterType::Pointer fusion = FusionFilterType::New(); + typedef otb::SimpleRcsPanSharpeningFusionImageFilter<ImageType, VectorImageType, VectorIntImageType> FusionFilterType; + FusionFilterType::Pointer fusion = FusionFilterType::New(); fusion->SetPanInput(readerPAN->GetOutput()); fusion->SetXsInput(readerXS->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And finally, we declare the writer and call its \code{Update()} method to // trigger the full pipeline execution. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<VectorIntImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[3]); writer->SetInput(fusion->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet typedef otb::PrintableImageFilter<VectorIntImageType> PrintableImageType; - PrintableImageType::Pointer printable = PrintableImageType::New(); + PrintableImageType::Pointer printable = PrintableImageType::New(); - typedef otb::VectorImage<unsigned char, - 2> - VectorCharImageType; + typedef otb::VectorImage<unsigned char, 2> VectorCharImageType; typedef otb::ImageFileWriter<VectorCharImageType> PNGWriterType; - PNGWriterType::Pointer pngwriter = PNGWriterType::New(); + PNGWriterType::Pointer pngwriter = PNGWriterType::New(); printable->SetInput(fusion->GetOutput()); printable->SetChannel(3); @@ -172,7 +126,7 @@ int main(int argc, char* argv[]) pngwriter->Update(); typedef otb::PrintableImageFilter<VectorImageType> PrintableImageType2; - PrintableImageType2::Pointer printable2 = PrintableImageType2::New(); + PrintableImageType2::Pointer printable2 = PrintableImageType2::New(); printable2->SetInput(readerXS->GetOutput()); printable2->SetChannel(3); printable2->SetChannel(2); @@ -183,8 +137,8 @@ int main(int argc, char* argv[]) typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> VectorCastFilterType; - VectorCastFilterType::Pointer vectorCastFilter = VectorCastFilterType::New(); - PNGWriterType::Pointer pngwriterPan = PNGWriterType::New(); + VectorCastFilterType::Pointer vectorCastFilter = VectorCastFilterType::New(); + PNGWriterType::Pointer pngwriterPan = PNGWriterType::New(); vectorCastFilter->SetInput(readerPAN->GetOutput()); PrintableImageType2::Pointer printable3 = PrintableImageType2::New(); diff --git a/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx b/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx index 0bdd084a115e70ec9fa9751ec32683f2fd351267..1ac712bbbdd0e0c2e20fece72f3b33cda8a2d2cf 100644 --- a/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx +++ b/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx @@ -24,85 +24,66 @@ #include "itkRescaleIntensityImageFilter.h" #include "otbVectorRescaleIntensityImageFilter.h" #include "otbMultiToMonoChannelExtractROI.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {Indian_pines_corrected.tif} -// OUTPUTS: {Indian_pines_Unmixing_Output.tif}, {UnmixingbandOutput1.png}, {UnmixingbandOutput2.png}, {UnmixingbandOutput3.png} -// 16 -// Software Guide : EndCommandLineArgs +/* Example usage: +./HyperspectralUnmixingExample Input/Indian_pines_corrected.tif \ + Output/Indian_pines_Unmixing_Output.tif \ + Output/UnmixingbandOutput1.png \ + Output/UnmixingbandOutput2.png \ + Output/UnmixingbandOutput3.png \ + 16 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{VcaImageFilter} and \doxygen{otb}{UnConstrainedLeastSquareImageFilter}. // The VCA filter computes endmembers using the Vertex Component Analysis // and UCLS performs unmixing on the input image using these endmembers. // // The first step required to use these filters is to include its header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVcaImageFilter.h" #include "otbUnConstrainedLeastSquareImageFilter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 7) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << "inputFileName outputFileName outputPrettyFilename1 outputPrettyFilename2 outputPrettyFilename3 EstimatenumberOfEndmembers" << std::endl; return EXIT_FAILURE; - } + } - const char * infname = argv[1]; - const char * outfname = argv[2]; + const char* infname = argv[1]; + const char* outfname = argv[2]; const unsigned int estimateNumberOfEndmembers = atoi(argv[6]); - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - typedef double PixelType; - // Software Guide : BeginLatex - // + typedef double PixelType; // We start by defining the types for the images and the reader and // the writer. We choose to work with a \doxygen{otb}{VectorImage}, // since we will produce a multi-channel image (the principal // components) from a multi-channel input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VectorImage<PixelType, Dimension> ImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet + typedef otb::VectorImage<PixelType, Dimension> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<ImageType> WriterType; typedef otb::VectorRescaleIntensityImageFilter<ImageType, ImageType> RescalerType; - typedef otb::VectorImageToMatrixImageFilter<ImageType> VectorImageToMatrixImageFilterType; + typedef otb::VectorImageToMatrixImageFilter<ImageType> VectorImageToMatrixImageFilterType; - // Software Guide : BeginLatex - // // We instantiate now the image reader and we set the image file name. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); - // Software Guide : EndCodeSnippet reader->UpdateOutputInformation(); - // Software Guide : BeginLatex - // // For now we need to rescale the input image between 0 and 1 to // perform the unmixing algorithm. We use the // \doxygen{otb}{VectorRescaleIntensityImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - RescalerType::Pointer rescaler = RescalerType::New(); + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetInput(reader->GetOutput()); ImageType::PixelType minPixel, maxPixel; @@ -113,71 +94,43 @@ int main(int argc, char * argv[]) rescaler->SetOutputMinimum(minPixel); rescaler->SetOutputMaximum(maxPixel); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define the type for the VCA filter. It is templated over the input // image type. The only parameter is the number of endmembers which // needs to be estimated. // We can now the instantiate the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VCAImageFilter<ImageType> VCAFilterType; - VCAFilterType::Pointer vca = VCAFilterType::New(); + typedef otb::VCAImageFilter<ImageType> VCAFilterType; + VCAFilterType::Pointer vca = VCAFilterType::New(); vca->SetNumberOfEndmembers(estimateNumberOfEndmembers); vca->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We transform the output estimate endmembers to a matrix representation - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - VectorImageToMatrixImageFilterType::Pointer - endMember2Matrix = VectorImageToMatrixImageFilterType::New(); + VectorImageToMatrixImageFilterType::Pointer endMember2Matrix = VectorImageToMatrixImageFilterType::New(); endMember2Matrix->SetInput(vca->GetOutput()); endMember2Matrix->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now procedd to the unmixing algorithm.Parameters // needed are the input image and the endmembers matrix. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::UnConstrainedLeastSquareImageFilter<ImageType, ImageType, double> UCLSUnmixingFilterType; - UCLSUnmixingFilterType::Pointer - unmixer = UCLSUnmixingFilterType::New(); + UCLSUnmixingFilterType::Pointer unmixer = UCLSUnmixingFilterType::New(); unmixer->SetInput(rescaler->GetOutput()); unmixer->SetMatrix(endMember2Matrix->GetMatrix()); - // Software Guide : EndCodeSnippet unmixer->SetNumberOfThreads(1); // FIXME : currently buggy - // Software Guide : BeginLatex - // // We now instantiate the writer and set the file name for the // output image and trigger the unmixing computation with the \code{Update()} of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetInput(unmixer->GetOutput()); writer->SetFileName(outfname); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:UNMIXING_FILTER} shows the result of applying unmixing // to an AVIRIS image (220 bands). This dataset is freely available // at \url{http://www.ehu.es/ccwintco/index.php/Hyperspectral_Remote_Sensing_Scenes#Indian_Pines} @@ -192,21 +145,18 @@ int main(int argc, char * argv[]) // first abundance map band, second abundance map band, third abundance map band.} // \label{fig:UNMIXING_FILTER} // \end{figure} - // - // Software Guide : EndLatex - typedef otb::Image<PixelType, Dimension> MonoImageType; - typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> ExtractROIFilterType; - typedef otb::Image<unsigned char, 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<MonoImageType, - OutputImageType> PrettyRescalerType; - typedef otb::ImageFileWriter<OutputImageType> WriterType2; + typedef otb::Image<PixelType, Dimension> MonoImageType; + typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> ExtractROIFilterType; + typedef otb::Image<unsigned char, 2> OutputImageType; + typedef itk::RescaleIntensityImageFilter<MonoImageType, OutputImageType> PrettyRescalerType; + typedef otb::ImageFileWriter<OutputImageType> WriterType2; for (unsigned int cpt = 0; cpt < 3; ++cpt) - { + { ExtractROIFilterType::Pointer extractROIFilter = ExtractROIFilterType::New(); - PrettyRescalerType::Pointer prettyRescaler = PrettyRescalerType::New(); - WriterType2::Pointer writer2 = WriterType2::New(); + PrettyRescalerType::Pointer prettyRescaler = PrettyRescalerType::New(); + WriterType2::Pointer writer2 = WriterType2::New(); extractROIFilter->SetInput(unmixer->GetOutput()); extractROIFilter->SetChannel(cpt + 1); @@ -218,7 +168,7 @@ int main(int argc, char * argv[]) writer2->SetInput(prettyRescaler->GetOutput()); writer2->SetFileName(argv[cpt + 3]); writer2->Update(); - } + } return EXIT_SUCCESS; } diff --git a/Examples/IO/ComplexImageReadWrite.cxx b/Examples/IO/ComplexImageReadWrite.cxx index 7083cace6da663407d11713d2e724260243d8efe..1db668a546f06a5ab84a998b08fe1f38c5a6b4ad 100644 --- a/Examples/IO/ComplexImageReadWrite.cxx +++ b/Examples/IO/ComplexImageReadWrite.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates how to read and write an image of pixel type // \code{std::complex}. The complex type is defined as an integral part of the // C++ language. @@ -35,109 +32,71 @@ // \index{Complex images!Instantiation} // \index{Complex images!Reading} // \index{Complex images!Writing} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include <complex> #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters in the command line if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// The image dimension and pixel type must be declared. In this case we use the -// \code{std::complex<>} as the pixel type. Using the dimension and pixel type -// we proceed to instantiate the image type. -// -// Software Guide : EndLatex + // The image dimension and pixel type must be declared. In this case we use the + // \code{std::complex<>} as the pixel type. Using the dimension and pixel type + // we proceed to instantiate the image type. -// Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef std::complex<float> PixelType; typedef otb::Image<PixelType, Dimension> ImageType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The image file reader and writer types are instantiated using the image -// type. We can then create objects for both of them. -// -// Software Guide : EndLatex + // The image file reader and writer types are instantiated using the image + // type. We can then create objects for both of them. -// Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Filenames should be provided for both the reader and the writer. In this -// particular example we take those filenames from the command line arguments. -// -// Software Guide : EndLatex + // Filenames should be provided for both the reader and the writer. In this + // particular example we take those filenames from the command line arguments. -// Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Here we simply connect the output of the reader as input to the writer. -// This simple program could be used for converting complex images from one -// fileformat to another. -// -// Software Guide : EndLatex + // Here we simply connect the output of the reader as input to the writer. + // This simple program could be used for converting complex images from one + // fileformat to another. -// Software Guide : BeginCodeSnippet writer->SetInput(reader->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The execution of this short pipeline is triggered by invoking the Update() -// method of the writer. This invocation must be placed inside a try/catch -// block since its execution may result in exceptions being thrown. -// -// Software Guide : EndLatex + // The execution of this short pipeline is triggered by invoking the Update() + // method of the writer. This invocation must be placed inside a try/catch + // block since its execution may result in exceptions being thrown. -// Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// For a more interesting use of this code, you may want to add a filter in -// between the reader and the writer and perform any complex image to complex -// image operation. -// -// Software Guide : EndLatex + // For a more interesting use of this code, you may want to add a filter in + // between the reader and the writer and perform any complex image to complex + // image operation. return EXIT_SUCCESS; } diff --git a/Examples/IO/DEMHandlerExample.cxx b/Examples/IO/DEMHandlerExample.cxx index 249adf77b0c7b181a358ad8cee4b44fd60422162..4e8d529a4717b77aed7bea3e0da4f933045f7af3 100644 --- a/Examples/IO/DEMHandlerExample.cxx +++ b/Examples/IO/DEMHandlerExample.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./DEMHandlerExample Input/DEM/srtm_directory Input/DEM/egm96.grd 40 8.434583 44.647083 383.580313671 0.001 +*/ -// Software Guide : BeginCommandLineArgs -// ${OTB_DATA_ROOT}/Input/srtm_directory ${OTB_DATA_ROOT}/Input/DEM/egm96.grd -// 40 8.434583 44.647083 383.580313671 0.001 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // OTB relies on OSSIM for elevation handling. Since release 3.16, there is a // single configuration class \doxygen{otb}{DEMHandler} to manage elevation (in // image projections or localization functions for example). This configuration @@ -35,64 +32,48 @@ // filters or functionalities. Ossim internal accesses to elevation are also // configured by this class and this will ensure consistency throughout the // library. -// -// Software Guide : EndLatex #include "otbDEMHandler.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { -if(argc!=8) - { - std::cerr<<"Usage: "<<argv[0]<<" demdir[path|no] geoid[path|no] defaultHeight longitude latitude targetValue tolerance"<<std::endl; + if (argc != 8) + { + std::cerr << "Usage: " << argv[0] << " demdir[path|no] geoid[path|no] defaultHeight longitude latitude targetValue tolerance" << std::endl; return EXIT_FAILURE; - } - - std::string demdir = argv[1]; - std::string geoid = argv[2]; - double defaultHeight = atof(argv[3]); - double longitude = atof(argv[4]); - double latitude = atof(argv[5]); - double target = atof(argv[6]); - double tolerance = atof(argv[7]); - -// Software Guide : BeginLatex -// -// This class is a singleton, the New() method is deprecated and will be removed -// in future release. We need to use the \code{Instance()} method instead. -// -// Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet + } + + std::string demdir = argv[1]; + std::string geoid = argv[2]; + double defaultHeight = atof(argv[3]); + double longitude = atof(argv[4]); + double latitude = atof(argv[5]); + double target = atof(argv[6]); + double tolerance = atof(argv[7]); + + // This class is a singleton, the New() method is deprecated and will be removed + // in future release. We need to use the \code{Instance()} method instead. + otb::DEMHandler::Pointer demHandler = otb::DEMHandler::Instance(); - // Software Guide : EndCodeSnippet bool fail = false; -// Software Guide : BeginLatex -// -// It allows configuring a directory containing DEM tiles (DTED or SRTM -// supported) using the \code{OpenDEMDirectory()} method. The \code{OpenGeoidFile()} method -// allows inputting a geoid file as well. Last, a default height above ellipsoid -// can be set using the \code{SetDefaultHeightAboveEllipsoid()} method. -// -// Software Guide : EndLatex + // It allows configuring a directory containing DEM tiles (DTED or SRTM + // supported) using the \code{OpenDEMDirectory()} method. The \code{OpenGeoidFile()} method + // allows inputting a geoid file as well. Last, a default height above ellipsoid + // can be set using the \code{SetDefaultHeightAboveEllipsoid()} method. - // Software Guide : BeginCodeSnippet demHandler->SetDefaultHeightAboveEllipsoid(defaultHeight); - if(!demHandler->IsValidDEMDirectory(demdir.c_str())) - { - std::cerr<<"IsValidDEMDirectory("<<demdir<<") = false"<<std::endl; + if (!demHandler->IsValidDEMDirectory(demdir.c_str())) + { + std::cerr << "IsValidDEMDirectory(" << demdir << ") = false" << std::endl; fail = true; - } + } demHandler->OpenDEMDirectory(demdir); demHandler->OpenGeoidFile(geoid); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now retrieve height above ellipsoid or height above Mean Sea Level // (MSL) using the methods \code{GetHeightAboveEllipsoid()} and // \code{GetHeightAboveMSL()}. Outputs of these methods depend on the @@ -116,10 +97,7 @@ if(argc!=8) // \item DEM available, but no geoid: srtm\_value // \item No DEM and no geoid available: $0$ // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet otb::DEMHandler::PointType point; point[0] = longitude; point[1] = latitude; @@ -127,41 +105,37 @@ if(argc!=8) double height = -32768; height = demHandler->GetHeightAboveMSL(point); - std::cout<<"height above MSL ("<<longitude<<"," - <<latitude<<") = "<<height<<" meters"<<std::endl; + std::cout << "height above MSL (" << longitude << "," << latitude << ") = " << height << " meters" << std::endl; height = demHandler->GetHeightAboveEllipsoid(point); - std::cout<<"height above ellipsoid ("<<longitude - <<", "<<latitude<<") = "<<height<<" meters"<<std::endl; - // Software Guide : EndCodeSnippet - // - // Software Guide : BeginLatex + std::cout << "height above ellipsoid (" << longitude << ", " << latitude << ") = " << height << " meters" << std::endl; // // Note that OSSIM internal calls for sensor // modelling use the height above ellipsoid, and follow the same logic as the // \code{GetHeightAboveEllipsoid()} method. // - //Software Guide : EndLatex + // Software Guide : EndLatex // Check for Nan - if(vnl_math_isnan(height)) - { - std::cerr<<"Computed value is NaN"<<std::endl; + if (vnl_math_isnan(height)) + { + std::cerr << "Computed value is NaN" << std::endl; fail = true; - } + } - double error = std::abs(height-target); + double error = std::abs(height - target); - if(error>tolerance) - { - std::cerr<<"Target value is "<<target<<" meters, computed value is "<<height<<" meters. error ("<<error<<" meters) > tolerance ("<<tolerance<<" meters)"<<std::endl; + if (error > tolerance) + { + std::cerr << "Target value is " << target << " meters, computed value is " << height << " meters. error (" << error << " meters) > tolerance (" << tolerance + << " meters)" << std::endl; fail = true; - } + } - if(fail) - { + if (fail) + { return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Examples/IO/DEMToImageGenerator.cxx b/Examples/IO/DEMToImageGenerator.cxx index c74120532bb785a86c75c0dedabc01fea6a38917..04e1ea3d6a33beffc9773b6ea1ed32d5daf07f81 100644 --- a/Examples/IO/DEMToImageGenerator.cxx +++ b/Examples/IO/DEMToImageGenerator.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./DEMToImageGenerator Output/DEMToImageGenerator.tif Output/pretty_DEMToImageGenerator.png 6.5 45.5 500 500 0.002 -0.002 Input/DEM_srtm +*/ -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {DEMToImageGenerator.tif} -// OUTPUTS: {pretty_DEMToImageGenerator.png} -// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Input/DEM_srtm -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // \index{otb::DEMToImageGenerator} // \index{otb::DEMHandler} // @@ -40,11 +36,8 @@ // // Let's look at the minimal code required to use this algorithm. First, the following header // defining the \doxygen{otb}{DEMToImageGenerator} class must be included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbDEMToImageGenerator.h" -// Software Guide : EndCodeSnippet #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" @@ -52,159 +45,101 @@ #include "itkMacro.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 10) - { - std::cout << argv[0] << - " output filename , pretty output filename , Longitude Output Origin point , Latitude Output Origin point , X Output Size, Y Output size , X Spacing , Y Spacing, DEM folder path" + { + std::cout << argv[0] + << " output filename , pretty output filename , Longitude Output Origin point , Latitude Output Origin point , X Output Size, Y Output size , X " + "Spacing , Y Spacing, DEM folder path" << std::endl; return EXIT_FAILURE; - } - // Software Guide : BeginLatex - // + } // The image type is now defined using pixel type and // dimension. The output image is defined as an \doxygen{otb}{Image}. - // - // Software Guide : EndLatex - char * folderPath = argv[9]; - char * outputName = argv[1]; - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + char* folderPath = argv[9]; + char* outputName = argv[1]; + const unsigned int Dimension = 2; typedef otb::Image<double, Dimension> ImageType; - // Software Guide : EndCodeSnippet // The writer is defined typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : BeginLatex - // // The DEMToImageGenerator is defined using the image pixel // type as a template parameter. After that, the object can be instancied. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::DEMToImageGenerator<ImageType> DEMToImageGeneratorType; DEMToImageGeneratorType::Pointer object = DEMToImageGeneratorType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Input parameter types are defined to set the value in the \doxygen{otb}{DEMToImageGenerator}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef DEMToImageGeneratorType::SizeType SizeType; - typedef DEMToImageGeneratorType::SpacingType SpacingType; - typedef DEMToImageGeneratorType::PointType PointType; - // Software Guide : EndCodeSnippet + typedef DEMToImageGeneratorType::SizeType SizeType; + typedef DEMToImageGeneratorType::SpacingType SpacingType; + typedef DEMToImageGeneratorType::PointType PointType; // Instantiating writer WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex - // // The path to the DEM folder is given to the \doxygen{otb}{DEMHandler}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet otb::DEMHandler::Instance()->OpenDEMDirectory(folderPath); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The origin (Longitude/Latitude) of the output image in the DEM is given to the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet PointType origin; origin[0] = ::atof(argv[3]); origin[1] = ::atof(argv[4]); object->SetOutputOrigin(origin); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The size (in Pixel) of the output image is given to the filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SizeType size; size[0] = ::atoi(argv[5]); size[1] = ::atoi(argv[6]); object->SetOutputSize(size); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The spacing (step between to consecutive pixel) is given to the filter. // By default, this spacing is set at 0.001. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SpacingType spacing; spacing[0] = ::atof(argv[7]); spacing[1] = ::atof(argv[8]); object->SetOutputSpacing(spacing); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The output image name is given to the writer and // the filter output is linked to the writer input. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetFileName(outputName); writer->SetInput(object->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The invocation of the \code{Update()} method on the writer triggers the // execution of the pipeline. It is recommended to place update calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; std::cout << err << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception thrown !" << std::endl; return EXIT_FAILURE; - } + } // Pretty image creation for the printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyType; - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputPrettyImageType> RescalerType; - typedef itk::ThresholdImageFilter<ImageType> - ThresholderType; + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputPrettyImageType> RescalerType; + typedef itk::ThresholdImageFilter<ImageType> ThresholderType; ThresholderType::Pointer thresholder = ThresholderType::New(); RescalerType::Pointer rescaler = RescalerType::New(); @@ -222,24 +157,22 @@ int main(int argc, char * argv[]) prettyWriter->SetInput(rescaler->GetOutput()); try - { + { prettyWriter->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; - // Software Guide : BeginLatex - // // Let's now run this example using as input the SRTM data contained in // \code{DEM\_srtm} folder. Figure \ref{fig:DEMToImageGenerator} // shows the obtained DEM. Invalid data values -- hidden areas due @@ -251,7 +184,4 @@ int main(int argc, char * argv[]) // \itkcaption[DEM To Image generator Example]{DEMToImageGenerator image.} // \label{fig:DEMToImageGenerator} // \end{figure} - // - // Software Guide : EndLatex - } diff --git a/Examples/IO/ExtractROI.cxx b/Examples/IO/ExtractROI.cxx index 45118673a81921deaa046695ae8525cb7f903814..5d5d0a5c34509488caf3d0e93e1f45f50ec0e071 100644 --- a/Examples/IO/ExtractROI.cxx +++ b/Examples/IO/ExtractROI.cxx @@ -20,15 +20,11 @@ */ +/* Example usage: +./ExtractROI Input/IMAGERY_SSECH.tif Output/ROI_IMAGERY_RGB.png Output/ROI_IMAGERY_MIR.png 0 0 100 100 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {IMAGERY_SSECH.tif} -// OUTPUTS: {ROI_IMAGERY_RGB.png}, {ROI_IMAGERY_MIR.png} -// 0 0 100 100 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example shows the use of the // \doxygen{otb}{MultiChannelExtractROI} and // \doxygen{otb}{MultiToMonoChannelExtractROI} which allow the @@ -42,157 +38,94 @@ // We start by including the needed header files. // \index{otb::ExtractROI!header} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbMultiChannelExtractROI.h" #include "otbMultiToMonoChannelExtractROI.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // R\'ecuperation de arguments if (argc < 7) - { + { std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] << - " inputImageFile outputImageFileRGB outputImageFileLastBand startX startY sizeX sizeY" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFileRGB outputImageFileLastBand startX startY sizeX sizeY" << std::endl; return EXIT_FAILURE; - } - -// Software Guide : BeginLatex -// -// The program arguments define the image file names as well as the -// rectangular area to be extracted. -// -// Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - const char * inputFilename = argv[1]; - const char * outputFilenameRGB = argv[2]; - const char * outputFilenameMIR = argv[3]; - - unsigned int startX((unsigned int) ::atoi(argv[4])); - unsigned int startY((unsigned int) ::atoi(argv[5])); - unsigned int sizeX((unsigned int) ::atoi(argv[6])); - unsigned int sizeY((unsigned int) ::atoi(argv[7])); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + } + + // The program arguments define the image file names as well as the + // rectangular area to be extracted. + + const char* inputFilename = argv[1]; + const char* outputFilenameRGB = argv[2]; + const char* outputFilenameMIR = argv[3]; + + unsigned int startX((unsigned int)::atoi(argv[4])); + unsigned int startY((unsigned int)::atoi(argv[5])); + unsigned int sizeX((unsigned int)::atoi(argv[6])); + unsigned int sizeY((unsigned int)::atoi(argv[7])); + // As usual, we define the input and output pixel types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef unsigned char InputPixelType; - typedef unsigned char OutputPixelType; - // Software Guide : EndCodeSnippet + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; - // Software Guide : BeginLatex - // // First of all, we extract the multiband part by using the // \doxygen{otb}{MultiChannelExtractROI} class, which is templated // over the input and output pixel types. This class in not // templated over the images types in order to force these images // to be of \doxygen{otb}{VectorImage} type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MultiChannelExtractROI<InputPixelType, - OutputPixelType> ExtractROIFilterType; - // Software Guide : EndCodeSnippet + typedef otb::MultiChannelExtractROI<InputPixelType, OutputPixelType> ExtractROIFilterType; - // Software Guide : BeginLatex - // // We create the extractor filter by using the \code{New} method of // the class and we set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ExtractROIFilterType::Pointer extractROIFilter = ExtractROIFilterType::New(); extractROIFilter->SetStartX(startX); extractROIFilter->SetStartY(startY); extractROIFilter->SetSizeX(sizeX); extractROIFilter->SetSizeY(sizeY); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We must tell the filter which are the channels to be used. When // selecting contiguous bands, we can use the // \code{SetFirstChannel} and the \code{SetLastChannel}. Otherwise, // we select individual channels by using the \code{SetChannel} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet extractROIFilter->SetFirstChannel(1); extractROIFilter->SetLastChannel(3); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We will use the OTB readers and writers for file access. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ExtractROIFilterType::InputImageType> ReaderType; typedef otb::ImageFileWriter<ExtractROIFilterType::InputImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Since the number of bands of the input image is dynamically set // at runtime, the \code{UpdateOutputInformation} method of the reader must be // called before using the extractor filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(inputFilename); reader->UpdateOutputInformation(); writer->SetFileName(outputFilenameRGB); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can then build the pipeline as usual. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet extractROIFilter->SetInput(reader->GetOutput()); writer->SetInput(extractROIFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And execute the pipeline by calling the \code{Update} method of // the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The usage of the \doxygen{otb}{MultiToMonoChannelExtractROI} is // similar to the one of the \doxygen{otb}{MultiChannelExtractROI} // described above. @@ -207,39 +140,24 @@ int main(int argc, char * argv[]) // \doxygen{otb}{VectorImage}. This is useful from a computing and // memory usage point of view. // This class is also templated over the pixel types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MultiToMonoChannelExtractROI<InputPixelType, - OutputPixelType> - ExtractROIMonoFilterType; - // Software Guide : EndCodeSnippet + typedef otb::MultiToMonoChannelExtractROI<InputPixelType, OutputPixelType> ExtractROIMonoFilterType; - ExtractROIMonoFilterType::Pointer extractROIMonoFilter = - ExtractROIMonoFilterType::New(); + ExtractROIMonoFilterType::Pointer extractROIMonoFilter = ExtractROIMonoFilterType::New(); extractROIMonoFilter->SetStartX(startX); extractROIMonoFilter->SetStartY(startY); extractROIMonoFilter->SetSizeX(sizeX); extractROIMonoFilter->SetSizeY(sizeY); - // Software Guide : BeginLatex - // // For this filter, only one output channel has to be selected. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet extractROIMonoFilter->SetChannel(4); - // Software Guide : EndCodeSnippet - typedef otb::ImageFileReader<ExtractROIMonoFilterType::InputImageType> - monoReaderType; - typedef otb::ImageFileWriter<ExtractROIMonoFilterType::OutputImageType> - monoWriterType; - monoReaderType::Pointer monoReader = monoReaderType::New(); - monoWriterType::Pointer monoWriter = monoWriterType::New(); + typedef otb::ImageFileReader<ExtractROIMonoFilterType::InputImageType> monoReaderType; + typedef otb::ImageFileWriter<ExtractROIMonoFilterType::OutputImageType> monoWriterType; + monoReaderType::Pointer monoReader = monoReaderType::New(); + monoWriterType::Pointer monoWriter = monoWriterType::New(); monoReader->SetFileName(inputFilename); monoReader->Update(); // Needed to know the number of channels in the image @@ -249,8 +167,6 @@ int main(int argc, char * argv[]) monoWriter->SetInput(extractROIMonoFilter->GetOutput()); monoWriter->Update(); - // Software Guide : BeginLatex - // // \begin{figure} // \center // \includegraphics[width=0.44\textwidth]{IMAGERY_SSECH.eps} @@ -271,9 +187,6 @@ int main(int argc, char * argv[]) // Figure \ref{fig:ROI_IMAGERY} illustrates the result of the // application of both extraction filters on the image presented in // figure \ref{fig:IMAGERY_SSECH}. - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/IO/ImageReadCastWrite.cxx b/Examples/IO/ImageReadCastWrite.cxx index c4c6cc2b021cd17c2e7f3e91da63a3e68797e6cd..3c1d2e8144d711a991f0fee03275a25ffbbf2351 100644 --- a/Examples/IO/ImageReadCastWrite.cxx +++ b/Examples/IO/ImageReadCastWrite.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // Given that \href{http://www.itk.org}{ITK} and OTB are based on the Generic // Programming paradigm, most of the types are defined at compilation // time. It is sometimes important to anticipate conversion between different @@ -38,119 +35,81 @@ // \index{otb::ImageFileReader!header} // \index{otb::ImageFileWriter!header} // \index{itk::RescaleIntensityImageFilter!header} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters in the command line if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then, as usual, a decision should be made about the pixel type that // should be used to represent the images. Note that when reading an // image, this pixel type \textbf{is not necessarily} the pixel type of // the image stored in the file. Instead, it is the type that will be // used to store the image as soon as it is read into memory. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef float InputPixelType; typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now instantiate the types of the reader and writer. These two // classes are parameterized over the image type. // // \index{otb::ImageFileReader!Instantiation} // \index{otb::ImageFileWriter!Instantiation} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Below we instantiate the RescaleIntensityImageFilter class that will // linearly scale the image intensities. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter< - InputImageType, - OutputImageType> FilterType; - // Software Guide : EndCodeSnippet + typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> FilterType; - // Software Guide : BeginLatex - // // A filter object is constructed and the minimum and maximum values of // the output are selected using the SetOutputMinimum() and // SetOutputMaximum() methods. // // \index{itk::RescaleIntensityImageFilter!SetOutputMinimum()} // \index{itk::RescaleIntensityImageFilter!SetOutputMaximum()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet FilterType::Pointer filter = FilterType::New(); filter->SetOutputMinimum(0); filter->SetOutputMaximum(255); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, we create the reader and writer and connect the pipeline. // // \index{otb::ImageFileReader!New()} // \index{otb::ImageFileWriter!New()} // \index{otb::ImageFileReader!SmartPointer} // \index{otb::ImageFileWriter!SmartPointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet // // Here we recover the file names from the command line arguments // - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; - // Software Guide : BeginLatex - // // The name of the files to be read and written are passed with the // SetFileName() method. // @@ -158,34 +117,24 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!SetFileName()} // \index{SetFileName()!otb::ImageFileReader} // \index{SetFileName()!otb::ImageFileWriter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally we trigger the execution of the pipeline with the Update() // method on the writer. The output image will then be the scaled and cast // version of the input image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } return EXIT_SUCCESS; } diff --git a/Examples/IO/ImageReadRegionOfInterestWrite.cxx b/Examples/IO/ImageReadRegionOfInterestWrite.cxx index 168a789deda4017cb72d5bc93d63635d2076c1af..b169c652aa8c0e1267e123372c73326bcbbaa877 100644 --- a/Examples/IO/ImageReadRegionOfInterestWrite.cxx +++ b/Examples/IO/ImageReadRegionOfInterestWrite.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // This example should arguably be placed in the filtering // chapter. However its usefulness for typical IO operations makes it // interesting to mention here. The purpose of this example is to read and @@ -31,67 +28,43 @@ // the region of interest of an image. // // As usual with OTB IO, we begin by including the appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // The \doxygen{otb}{ExtractROI} is the filter used to extract a // region from an image. Its header is included below. // // \index{otb::ExtractROI!header} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbExtractROI.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters in the command line if (argc < 7) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl; std::cerr << " startX startY sizeX sizeY" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Image types are defined below. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef unsigned char InputPixelType; - typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; + const unsigned int Dimension = 2; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The types for the \doxygen{otb}{ImageFileReader} and \doxygen{otb}{ImageFileWriter} // are instantiated using the image types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The ExtractROI type is instantiated using // the input and output pixel types. Using the pixel types as // template parameters instead of the image types allows @@ -100,35 +73,22 @@ int main(int argc, char * argv[]) // \ref{sec:ExtractROI} for the extraction of ROIs on // \doxygen{otb}{VectorImage}s. A filter object is created with the // New() method and assigned to a \doxygen{itk}{SmartPointer}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ExtractROI<InputImageType::PixelType, - OutputImageType::PixelType> FilterType; + typedef otb::ExtractROI<InputImageType::PixelType, OutputImageType::PixelType> FilterType; FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The ExtractROI requires a region to be // defined by the user. This is done by defining a rectangle with // the following methods (the filter assumes that a 2D image is // being processed, for N-D region extraction, you can use the // \doxygen{itk}{RegionOfInterestImageFilter} class). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetStartX(atoi(argv[3])); filter->SetStartY(atoi(argv[4])); filter->SetSizeX(atoi(argv[5])); filter->SetSizeY(atoi(argv[6])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Below, we create the reader and writer using the New() method and // assigning the result to a SmartPointer. // @@ -136,22 +96,16 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!New()} // \index{otb::ImageFileReader!SmartPointer} // \index{otb::ImageFileWriter!SmartPointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet // // Here we recover the file names from the command line arguments // - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; - // Software Guide : BeginLatex - // // The name of the file to be read or written is passed with the // SetFileName() method. // @@ -159,46 +113,30 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!SetFileName()} // \index{SetFileName()!otb::ImageFileReader} // \index{SetFileName()!otb::ImageFileWriter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Below we connect the reader, filter and writer to form the data // processing pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally we execute the pipeline by invoking Update() on the writer. The // call is placed in a \code{try/catch} block in case exceptions are // thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } return EXIT_SUCCESS; } diff --git a/Examples/IO/ImageReadWrite.cxx b/Examples/IO/ImageReadWrite.cxx index 26b42122657c8ca37d317b2c66ba53518854321a..1e01ad77cf2bd654b44553fb0095b5c310a5e2d8 100644 --- a/Examples/IO/ImageReadWrite.cxx +++ b/Examples/IO/ImageReadWrite.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // The classes responsible for reading and writing images are located at the // beginning and end of the data processing pipeline. These classes are // known as data sources (readers) and data sinks (writers). @@ -46,28 +43,22 @@ // // \index{otb::ImageFileWriter} // \index{otb::ImageFileWriter!header} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters in the command line if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then, as usual, a decision must be made about the type of pixel used to // represent the image processed by the pipeline. Note that when reading // and writing images, the pixel type of the image \textbf{is not @@ -86,17 +77,11 @@ int main(int argc, char * argv[]) // // A typical selection for remote sensing images is illustrated in // the following lines. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef unsigned short PixelType; - const unsigned int Dimension = 2; + typedef unsigned short PixelType; + const unsigned int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Note that the dimension of the image in memory should match the one of // the image in file. There are a couple of special cases in which this // condition may be relaxed, but in general it is better to ensure that both @@ -108,16 +93,10 @@ int main(int argc, char * argv[]) // // \index{otb::ImageFileReader!Instantiation} // \index{otb::ImageFileWriter!Instantiation} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, we create one object of each type using the New() method and // assigning the result to a \doxygen{itk}{SmartPointer}. // @@ -125,21 +104,15 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!New()} // \index{otb::ImageFileReader!SmartPointer} // \index{otb::ImageFileWriter!SmartPointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet // Here we recover the file names from the command line arguments // - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; - // Software Guide : BeginLatex - // // The name of the file to be read or written is passed with the // SetFileName() method. // @@ -147,28 +120,16 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!SetFileName()} // \index{SetFileName()!otb::ImageFileReader} // \index{SetFileName()!otb::ImageFileWriter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now connect these readers and writers to filters to create a // pipeline. For example, we can create a short pipeline by passing // the output of the reader directly to the input of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // At first view, this may seem as a quite useless program, but it is // actually implementing a powerful file format conversion tool! The // execution of the pipeline is triggered by the invocation of the @@ -176,24 +137,18 @@ int main(int argc, char * argv[]) // data pipeline object is the writer. It is a wise practice of defensive // programming to insert any \code{Update()} call inside a \code{try/catch} block // in case exceptions are thrown during the execution of the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // Note that exceptions should only be caught by pieces of code that know // what to do with them. In a typical application this \code{catch} block // should probably reside on the GUI code. The action on the \code{catch} @@ -211,8 +166,6 @@ int main(int argc, char * argv[]) // user can specify the data file format by explicit instantiation and // assignment the appropriate \doxygen{itk}{ImageIO} subclass. // - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/IO/ImageSeriesIOExample.cxx b/Examples/IO/ImageSeriesIOExample.cxx index 3e11df1a9a449afaf7c3a995d5f7263f937e0b9c..bd5f6fda12a6cd7d7d01226a36c96f52100ac20e 100644 --- a/Examples/IO/ImageSeriesIOExample.cxx +++ b/Examples/IO/ImageSeriesIOExample.cxx @@ -20,11 +20,8 @@ */ - #include <iostream> -// Software Guide : BeginLatex -// // This example shows how to read a list of images and concatenate // them into a vector image. We will write a program which is able to // perform this operation taking advantage of the streaming @@ -32,88 +29,59 @@ // all the input images have the same size and a single band. // // The following header files will be needed: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageList.h" #include "otbImageListToVectorImageFilter.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet int main(int argc, char** argv) { if (argc < 4) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << "outputImage image1 image2 ... " << std::endl; - } + } const unsigned int NbImages = argc - 2; - std::cout << "Concat of " << NbImages << - " images into a multi-band image " << - std::endl; + std::cout << "Concat of " << NbImages << " images into a multi-band image " << std::endl; -// Software Guide : BeginLatex -// -// We will start by defining the types for the input images and the -// associated readers. -// -// Software Guide : EndLatex + // We will start by defining the types for the input images and the + // associated readers. -// Software Guide : BeginCodeSnippet typedef unsigned short int PixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::Image<PixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ImageReaderType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We will use a list of image file readers in order to open all the -// input images at once. For this, we use the -// \doxygen{otb}{ObjectList} object and we template it over the type -// of the readers. -// -// Software Guide : EndLatex + // We will use a list of image file readers in order to open all the + // input images at once. For this, we use the + // \doxygen{otb}{ObjectList} object and we template it over the type + // of the readers. -// Software Guide : BeginCodeSnippet typedef otb::ObjectList<ImageReaderType> ReaderListType; ReaderListType::Pointer readerList = ReaderListType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We will also build a list of input images in order to store the -// smart pointers obtained at the output of each reader. This allows -// us to build a pipeline without really reading the images and using -// lots of RAM. The \doxygen{otb}{ImageList} object will be used. -// -// Software Guide : EndLatex + // We will also build a list of input images in order to store the + // smart pointers obtained at the output of each reader. This allows + // us to build a pipeline without really reading the images and using + // lots of RAM. The \doxygen{otb}{ImageList} object will be used. -// Software Guide : BeginCodeSnippet typedef otb::ImageList<InputImageType> ImageListType; ImageListType::Pointer imageList = ImageListType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now loop over the input image list in order to populate the -// reader list and the input image list. -// -// Software Guide : EndLatex + // We can now loop over the input image list in order to populate the + // reader list and the input image list. -// Software Guide : BeginCodeSnippet for (unsigned int i = 0; i < NbImages; ++i) - { + { ImageReaderType::Pointer imageReader = ImageReaderType::New(); @@ -126,39 +94,24 @@ int main(int argc, char** argv) imageList->PushBack(imageReader->GetOutput()); readerList->PushBack(imageReader); + } - } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// All the input images will be concatenated into a single output -// vector image. For this matter, we will use the -// \doxygen{otb}{ImageListToVectorImageFilter} which is templated -// over the input image list type and the output vector image type. -// -// Software Guide : EndLatex + // All the input images will be concatenated into a single output + // vector image. For this matter, we will use the + // \doxygen{otb}{ImageListToVectorImageFilter} which is templated + // over the input image list type and the output vector image type. -// Software Guide : BeginCodeSnippet typedef otb::VectorImage<PixelType, Dimension> VectorImageType; - typedef otb::ImageListToVectorImageFilter<ImageListType, VectorImageType> - ImageListToVectorImageFilterType; + typedef otb::ImageListToVectorImageFilter<ImageListType, VectorImageType> ImageListToVectorImageFilterType; - ImageListToVectorImageFilterType::Pointer iL2VI = - ImageListToVectorImageFilterType::New(); -// Software Guide : EndCodeSnippet + ImageListToVectorImageFilterType::Pointer iL2VI = ImageListToVectorImageFilterType::New(); -// Software Guide : BeginLatex -// -// We plug the image list as input of the filter and use a -// \doxygen{otb}{ImageFileWriter} to write the result image -// to a file, so that the streaming capabilities of all the readers -// and the filter are used. -// -// Software Guide : EndLatex + // We plug the image list as input of the filter and use a + // \doxygen{otb}{ImageFileWriter} to write the result image + // to a file, so that the streaming capabilities of all the readers + // and the filter are used. -// Software Guide : BeginCodeSnippet iL2VI->SetInput(imageList); typedef otb::ImageFileWriter<VectorImageType> ImageWriterType; @@ -166,17 +119,11 @@ int main(int argc, char** argv) ImageWriterType::Pointer imageWriter = ImageWriterType::New(); imageWriter->SetFileName(argv[1]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can tune the size of the image tiles, so that the -// total memory footprint of the pipeline is constant -// for any execution of the program. -// -// Software Guide : EndLatex + // We can tune the size of the image tiles, so that the + // total memory footprint of the pipeline is constant + // for any execution of the program. -// Software Guide : BeginCodeSnippet unsigned long memoryConsumptionInMB = 10; std::cout << "Memory consumption: " << memoryConsumptionInMB << std::endl; @@ -186,7 +133,6 @@ int main(int argc, char** argv) imageWriter->SetInput(iL2VI->GetOutput()); imageWriter->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/IO/MetadataExample.cxx b/Examples/IO/MetadataExample.cxx index 190c52570ff07a6caf73489085aeb8aed570fd42..e2875c34df3994e0be11926e81c2f2e7c594d84e 100644 --- a/Examples/IO/MetadataExample.cxx +++ b/Examples/IO/MetadataExample.cxx @@ -19,9 +19,6 @@ */ - -// SoftwareGuide: BeginLatex -// // This example illustrates the access to metadata image information // with OTB. By metadata, we mean data which is typically stored with // remote sensing images, like geographical coordinates of pixels, @@ -35,8 +32,6 @@ // is accessible through the \doxygen{otb}{Image} and // \doxygen{otb}{VectorImage} classes. You should avoid using the // \doxygen{itk}{Image} class if you want to have metadata support. -// -// SoftwareGuide: EndLatex #include "itkMacro.h" #include <iostream> @@ -50,72 +45,49 @@ int main(int itkNotUsed(argc), char* argv[]) { // Verify the number of parameters in the command line - const char * inputFilename = argv[1]; - const char * outputAsciiFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputAsciiFilename = argv[2]; -// SoftwareGuide: BeginLatex -// -// This simple example will consist on reading an image from a file -// and writing the metadata to an output ASCII file. As usual we -// start by defining the types needed for the image to be read. -// -// SoftwareGuide: EndLatex + // This simple example will consist on reading an image from a file + // and writing the metadata to an output ASCII file. As usual we + // start by defining the types needed for the image to be read. -// SoftwareGuide : BeginCodeSnippet typedef unsigned char InputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; -// SoftwareGuide : EndCodeSnippet -// SoftwareGuide: BeginLatex -// -// We can now instantiate the reader and get a pointer to the input image. -// -// SoftwareGuide: EndLatex + // We can now instantiate the reader and get a pointer to the input image. -// SoftwareGuide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); - InputImageType::Pointer image = InputImageType::New(); + InputImageType::Pointer image = InputImageType::New(); reader->SetFileName(inputFilename); reader->Update(); image = reader->GetOutput(); -// SoftwareGuide : EndCodeSnippet -// SoftwareGuide: BeginLatex -// -// Once the image has been read, we can access the metadata -// information. We will copy this information to an ASCII file, so we -// create an output file stream for this purpose. -// -// SoftwareGuide: EndLatex + // Once the image has been read, we can access the metadata + // information. We will copy this information to an ASCII file, so we + // create an output file stream for this purpose. -// SoftwareGuide : BeginCodeSnippet std::ofstream file; file.open(outputAsciiFilename); -// SoftwareGuide : EndCodeSnippet -// SoftwareGuide: BeginLatex -// -// We can now call the different available methods for accessing the -// metadata. Useful methods are : -// \begin{itemize} -// \item \code{GetSpacing}: the sampling step; -// \item \code{GetOrigin}: the coordinates of the origin of the image; -// \item \code{GetProjectionRef}: the image projection reference; -// \item \code{GetGCPProjection}: the projection for the eventual -// ground control points; -// \item \code{GetGCPCount}: the number of GCPs available; -// \end{itemize} -// -// SoftwareGuide: EndLatex + // We can now call the different available methods for accessing the + // metadata. Useful methods are : + // \begin{itemize} + // \item \code{GetSpacing}: the sampling step; + // \item \code{GetOrigin}: the coordinates of the origin of the image; + // \item \code{GetProjectionRef}: the image projection reference; + // \item \code{GetGCPProjection}: the projection for the eventual + // ground control points; + // \item \code{GetGCPCount}: the number of GCPs available; + // \end{itemize} -// SoftwareGuide : BeginCodeSnippet file << "Spacing " << image->GetSignedSpacing() << std::endl; file << "Origin " << image->GetOrigin() << std::endl; @@ -125,80 +97,64 @@ int main(int itkNotUsed(argc), char* argv[]) unsigned int GCPCount = image->GetGCPCount(); file << "GCP Count " << image->GetGCPCount() << std::endl; -// SoftwareGuide : EndCodeSnippet -// SoftwareGuide: BeginLatex -// -// One can also get the GCPs by number, as well as their coordinates -// in image and geographical space. -// -// SoftwareGuide: EndLatex + // One can also get the GCPs by number, as well as their coordinates + // in image and geographical space. -// SoftwareGuide : BeginCodeSnippet for (unsigned int GCPnum = 0; GCPnum < GCPCount; GCPnum++) - { + { file << "GCP[" << GCPnum << "] Id " << image->GetGCPId(GCPnum) << std::endl; - file << "GCP[" << GCPnum << "] Info " << image->GetGCPInfo(GCPnum) << - std::endl; - file << "GCP[" << GCPnum << "] Row " << image->GetGCPRow(GCPnum) << - std::endl; - file << "GCP[" << GCPnum << "] Col " << image->GetGCPCol(GCPnum) << - std::endl; + file << "GCP[" << GCPnum << "] Info " << image->GetGCPInfo(GCPnum) << std::endl; + file << "GCP[" << GCPnum << "] Row " << image->GetGCPRow(GCPnum) << std::endl; + file << "GCP[" << GCPnum << "] Col " << image->GetGCPCol(GCPnum) << std::endl; file << "GCP[" << GCPnum << "] X " << image->GetGCPX(GCPnum) << std::endl; file << "GCP[" << GCPnum << "] Y " << image->GetGCPY(GCPnum) << std::endl; file << "GCP[" << GCPnum << "] Z " << image->GetGCPZ(GCPnum) << std::endl; file << "----------------" << std::endl; - } -// SoftwareGuide : EndCodeSnippet + } -// SoftwareGuide: BeginLatex -// -// If a geographical transformation is available, it can be recovered -// as follows. -// -// SoftwareGuide: EndLatex + // If a geographical transformation is available, it can be recovered + // as follows. -// SoftwareGuide : BeginCodeSnippet InputImageType::VectorType tab = image->GetGeoTransform(); file << "Geo Transform " << std::endl; for (unsigned int i = 0; i < tab.size(); ++i) - { + { file << " " << i << " -> " << tab[i] << std::endl; - } + } tab.clear(); tab = image->GetUpperLeftCorner(); file << "Corners " << std::endl; for (unsigned int i = 0; i < tab.size(); ++i) - { + { file << " UL[" << i << "] -> " << tab[i] << std::endl; - } + } tab.clear(); tab = image->GetUpperRightCorner(); for (unsigned int i = 0; i < tab.size(); ++i) - { + { file << " UR[" << i << "] -> " << tab[i] << std::endl; - } + } tab.clear(); tab = image->GetLowerLeftCorner(); for (unsigned int i = 0; i < tab.size(); ++i) - { + { file << " LL[" << i << "] -> " << tab[i] << std::endl; - } + } tab.clear(); tab = image->GetLowerRightCorner(); for (unsigned int i = 0; i < tab.size(); ++i) - { + { file << " LR[" << i << "] -> " << tab[i] << std::endl; - } + } tab.clear(); file.close(); - // SoftwareGuide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/IO/MultibandImageReadWrite.cxx b/Examples/IO/MultibandImageReadWrite.cxx index 44d2152c8861b4976bb31bc5d875dc5e9e58739a..59853d649cec9ca40b013c843ba70172ceb822e4 100644 --- a/Examples/IO/MultibandImageReadWrite.cxx +++ b/Examples/IO/MultibandImageReadWrite.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // The \doxygen{otb}{Image} class with a vector pixel type could be // used for representing multispectral images, with one band per // vector component, however, this is not a practical way, since the @@ -42,61 +39,43 @@ // // \index{otb::ImageFileWriter} // \index{otb::ImageFileWriter!header} -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbVectorImage.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters in the command line if (argc < 3) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Then, as usual, a decision must be made about the type of pixel used to // represent the image processed by the pipeline. The pixel type // corresponds to the scalar type stored in the vector // components. Therefore, for a multiband Pl\'eiades image we will // do: // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef unsigned short PixelType; - const unsigned int Dimension = 2; + typedef unsigned short PixelType; + const unsigned int Dimension = 2; typedef otb::VectorImage<PixelType, Dimension> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now instantiate the types of the reader and writer. These two // classes are parameterized over the image type. // // \index{otb::ImageFileReader!Instantiation} // \index{otb::ImageFileWriter!Instantiation} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, we create one object of each type using the New() method and // assigning the result to a \doxygen{itk}{SmartPointer}. // @@ -104,21 +83,15 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!New()} // \index{otb::ImageFileReader!SmartPointer} // \index{otb::ImageFileWriter!SmartPointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet // Here we recover the file names from the command line arguments // - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; - // Software Guide : BeginLatex - // // The name of the file to be read or written is passed with the // SetFileName() method. // @@ -126,39 +99,27 @@ int main(int argc, char * argv[]) // \index{otb::ImageFileWriter!SetFileName()} // \index{SetFileName()!otb::ImageFileReader} // \index{SetFileName()!otb::ImageFileWriter} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We can now connect these readers and writers to filters to create a // pipeline. The only thig to take care of is, when executing the // program, choosing an output image file format which supports // multiband images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } return EXIT_SUCCESS; } diff --git a/Examples/IO/VectorDataIOExample.cxx b/Examples/IO/VectorDataIOExample.cxx index c96080fa8cf9e31af7b25a13fe2e0a7a48dfa421..0eef2e3ccabeb993aff5a58a336e08fc33d54365 100644 --- a/Examples/IO/VectorDataIOExample.cxx +++ b/Examples/IO/VectorDataIOExample.cxx @@ -19,8 +19,6 @@ */ -// Software Guide : BeginLatex -// // Unfortunately, many vector data formats do not // share the models for the data they represent. However, in some // cases, when simple data is stored, it can be decomposed in simple @@ -44,145 +42,87 @@ // // We will start by including the header files for the classes // describing the vector data and the corresponding reader and writer. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVectorData.h" #include "otbVectorDataFileReader.h" #include "otbVectorDataFileWriter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // We will also need to include the header files for the classes // which model the individual objects that we get from the vector // data structure. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkPreOrderTreeIterator.h" #include "otbObjectList.h" #include "otbPolygon.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << "inputFile outputFile" << std::endl; return EXIT_FAILURE; - } + } typedef unsigned short int PixelType; -// Software Guide : BeginLatex -// -// We define the types for the vector data structure and the -// corresponding file reader. -// -// Software Guide : EndLatex + // We define the types for the vector data structure and the + // corresponding file reader. -// Software Guide : BeginCodeSnippet typedef otb::VectorData<PixelType, 2> VectorDataType; - typedef otb::VectorDataFileReader<VectorDataType> - VectorDataFileReaderType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now instantiate the reader and read the data. -// -// Software Guide : EndLatex + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + // We can now instantiate the reader and read the data. -// Software Guide : BeginCodeSnippet VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); reader->SetFileName(argv[1]); reader->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The vector data obtained from the reader will provide a tree of -// nodes containing the actual objects of the scene. This tree will -// be accessed using an \doxygen{itk}{PreOrderTreeIterator}. -// -// Software Guide : EndLatex + // The vector data obtained from the reader will provide a tree of + // nodes containing the actual objects of the scene. This tree will + // be accessed using an \doxygen{itk}{PreOrderTreeIterator}. -// Software Guide : BeginCodeSnippet typedef VectorDataType::DataTreeType DataTreeType; typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// In this example we will only read polygon objects from the input -// file before writing them to the output file. We define the type -// for the polygon object as well as an iterator to the vertices. The -// polygons obtained will be stored in an \doxygen{otb}{ObjectList}. -// -// Software Guide : EndLatex + // In this example we will only read polygon objects from the input + // file before writing them to the output file. We define the type + // for the polygon object as well as an iterator to the vertices. The + // polygons obtained will be stored in an \doxygen{otb}{ObjectList}. -// Software Guide : BeginCodeSnippet - typedef otb::Polygon<double> PolygonType; - typedef otb::ObjectList<PolygonType> PolygonListType; + typedef otb::Polygon<double> PolygonType; + typedef otb::ObjectList<PolygonType> PolygonListType; PolygonListType::Pointer polygonList = PolygonListType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We get the data tree and instantiate an iterator to walk through it. -// -// Software Guide : EndLatex + // We get the data tree and instantiate an iterator to walk through it. -// Software Guide : BeginCodeSnippet TreeIteratorType it(reader->GetOutput()->GetDataTree()); it.GoToBegin(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We check that the current object is a polygon using the -// \code{IsPolygonFeature()} method and get its exterior ring in -// order to store it into the list. -// -// Software Guide : EndLatex + // We check that the current object is a polygon using the + // \code{IsPolygonFeature()} method and get its exterior ring in + // order to store it into the list. -// Software Guide : BeginCodeSnippet while (!it.IsAtEnd()) - { + { if (it.Get()->IsPolygonFeature()) - { + { polygonList->PushBack(it.Get()->GetPolygonExteriorRing()); - } - ++it; } -// Software Guide : EndCodeSnippet + ++it; + } polygonList->PushBack(PolygonType::New()); -// Software Guide : BeginLatex -// -// Before writing the polygons to the output file, we have to build -// the vector data structure. This structure will be built up of -// nodes. We define the types needed for that. -// -// Software Guide : EndLatex + // Before writing the polygons to the output file, we have to build + // the vector data structure. This structure will be built up of + // nodes. We define the types needed for that. -// Software Guide : BeginCodeSnippet VectorDataType::Pointer outVectorData = VectorDataType::New(); typedef VectorDataType::DataNodeType DataNodeType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We fill the data structure with the nodes. The root node is a -// document which is composed of folders. A list of polygons can be -// seen as a multi polygon object. -// -// Software Guide : EndLatex + // We fill the data structure with the nodes. The root node is a + // document which is composed of folders. A list of polygons can be + // seen as a multi polygon object. -// Software Guide : BeginCodeSnippet DataNodeType::Pointer document = DataNodeType::New(); document->SetNodeType(otb::DOCUMENT); document->SetNodeId("polygon"); @@ -190,64 +130,39 @@ int main(int argc, char * argv[]) folder->SetNodeType(otb::FOLDER); DataNodeType::Pointer multiPolygon = DataNodeType::New(); multiPolygon->SetNodeType(otb::FEATURE_MULTIPOLYGON); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We assign these objects to the data tree stored by the vector data object. -// -// Software Guide : EndLatex + // We assign these objects to the data tree stored by the vector data object. -// Software Guide : BeginCodeSnippet DataTreeType::Pointer tree = outVectorData->GetDataTree(); DataNodeType::Pointer root = tree->GetRoot()->Get(); tree->Add(document, root); tree->Add(folder, document); tree->Add(multiPolygon, folder); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now iterate through the polygon list and fill the vector -// data structure. -// -// Software Guide : EndLatex + // We can now iterate through the polygon list and fill the vector + // data structure. -// Software Guide : BeginCodeSnippet - for (PolygonListType::Iterator pit = polygonList->Begin(); - pit != polygonList->End(); ++pit) - { + for (PolygonListType::Iterator pit = polygonList->Begin(); pit != polygonList->End(); ++pit) + { DataNodeType::Pointer newPolygon = DataNodeType::New(); newPolygon->SetPolygonExteriorRing(pit.Get()); tree->Add(newPolygon, multiPolygon); - } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// And finally we write the vector data to a file using a generic -// \doxygen{otb}{VectorDataFileWriter}. -// -// Software Guide : EndLatex + } + // And finally we write the vector data to a file using a generic + // \doxygen{otb}{VectorDataFileWriter}. -// Software Guide : BeginCodeSnippet typedef otb::VectorDataFileWriter<VectorDataType> WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput(outVectorData); writer->SetFileName(argv[2]); writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; -// Software Guide : BeginLatex -// -// This example can convert an ESRI Shapefile to -// a MapInfo File but you can also access with the same OTB source code -// to a PostgreSQL datasource, using a connection string as : -// PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" -// Starting with GDAL 1.6.0, the set of tables to be scanned can be overridden -// by specifying tables=schema.table. - -// Software Guide : EndLatex - + // This example can convert an ESRI Shapefile to + // a MapInfo File but you can also access with the same OTB source code + // to a PostgreSQL datasource, using a connection string as : + // PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" + // Starting with GDAL 1.6.0, the set of tables to be scanned can be overridden + // by specifying tables=schema.table. } diff --git a/Examples/Image/Image1.cxx b/Examples/Image/Image1.cxx index f57654cfef0365190b76c45ef324c3b4d5eaddc2..b6818eff52faa6030501a8f3aee44ce187d80220 100644 --- a/Examples/Image/Image1.cxx +++ b/Examples/Image/Image1.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates how to manually construct an \doxygen{otb}{Image} // class. The following is the minimal code needed to instantiate, declare // and create the image class. @@ -31,31 +28,19 @@ // \index{Image!Header} // // First, the header file of the Image class must be included. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" -// Software Guide : EndCodeSnippet -int main(int, char *[]) +int main(int, char* []) { - // Software Guide : BeginLatex - // // Then we must decide with what type to represent the pixels // and what the dimension of the image will be. With these two // parameters we can instantiate the image class. Here we create // a 2D image, which is what we often use in remote sensing // applications, anyway, with \code{unsigned short} pixel data. // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet typedef otb::Image<unsigned short, 2> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image can then be created by invoking the \code{New()} operator // from the corresponding image type and assigning the result // to a \doxygen{itk}{SmartPointer}. @@ -63,14 +48,8 @@ int main(int, char *[]) // \index{Image!Pointer} // \index{Image!New()} // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet ImageType::Pointer image = ImageType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // In OTB, images exist in combination with one or more // \emph{regions}. A region is a subset of the image and indicates a // portion of the image that may be processed by other classes in @@ -104,17 +83,11 @@ int main(int, char *[]) // \index{Image!Size} // \index{Image!SizeType} // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet ImageType::IndexType start; - start[0] = 0; // first index on X - start[1] = 0; // first index on Y - // Software Guide : EndCodeSnippet + start[0] = 0; // first index on X + start[1] = 0; // first index on Y - // Software Guide : BeginLatex - // // The region size is represented by an array of the same dimension of the // image (using the Size class). The components of the array are // unsigned integers indicating the extent in pixels of the image along @@ -123,17 +96,11 @@ int main(int, char *[]) // \index{Image!Index} // \index{Image!IndexType} // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet ImageType::SizeType size; - size[0] = 200; // size along X - size[1] = 200; // size along Y - // Software Guide : EndCodeSnippet + size[0] = 200; // size along X + size[1] = 200; // size along Y - // Software Guide : BeginLatex - // // Having defined the starting index and the image size, these two // parameters are used to create an ImageRegion object which basically // encapsulates both concepts. The region is initialized with the @@ -141,18 +108,12 @@ int main(int, char *[]) // // \index{Image!itk::ImageRegion} // \index{Image!RegionType} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::RegionType region; region.SetSize(size); region.SetIndex(start); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally, the region is passed to the \code{Image} object in // order to define its extent and origin. The \code{SetRegions} // method sets the LargestPossibleRegion, BufferedRegion, and @@ -165,13 +126,9 @@ int main(int, char *[]) // // \index{Image!Allocate()} // \index{Image!SetRegions()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet image->SetRegions(region); image->Allocate(); - // Software Guide : EndCodeSnippet return EXIT_SUCCESS; } diff --git a/Examples/Image/Image2.cxx b/Examples/Image/Image2.cxx index 39105c83a5b5fb696f260dcc66c41d5e90b12910..797cc357f35fb24537633719f0ac472564867a84 100644 --- a/Examples/Image/Image2.cxx +++ b/Examples/Image/Image2.cxx @@ -20,38 +20,23 @@ */ - #include "otbImage.h" -// Software Guide : BeginLatex -// // The first thing required to read an image from a file is to include // the header file of the \doxygen{otb}{ImageFileReader} class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" -// Software Guide : EndCodeSnippet -int main(int, char * argv[]) +int main(int, char* argv[]) { - // Software Guide : BeginLatex - // // Then, the image type should be defined by specifying the // type used to represent pixels and the dimensions of the image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned char PixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Using the image type, it is now possible to instantiate the image reader // class. The image type is used as a template parameter to define how the // data will be represented once it is loaded into memory. This type does @@ -65,15 +50,9 @@ int main(int, char * argv[]) // // \index{otb::ImageFileReader!Instantiation} // \index{otb::Image!read} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The reader type can now be used to create one reader object. A // \doxygen{itk}{SmartPointer} (defined by the \code{::Pointer} // notation) is used to receive the reference to the newly created @@ -82,15 +61,9 @@ int main(int, char * argv[]) // // \index{otb::ImageFileReader!New()} // \index{otb::ImageFileReader!Pointer} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The minimum information required by the reader is the filename // of the image to be loaded in memory. This is provided through // the \code{SetFileName()} method. The file format here is inferred @@ -100,16 +73,10 @@ int main(int, char * argv[]) // information): // // \index{otb::ImageFileReader!SetFileName()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const char * filename = argv[1]; + const char* filename = argv[1]; reader->SetFileName(filename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Reader objects are referred to as pipeline source objects; they // respond to pipeline update requests and initiate the data flow in the // pipeline. The pipeline update mechanism ensures that the reader only @@ -122,15 +89,9 @@ int main(int, char * argv[]) // explicit update is invoked on the reader. // // \index{otb::ImageFileReader!Update()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Access to the newly read image can be gained by calling the // \code{GetOutput()} method on the reader. This method can also be called // before the update request is sent to the reader. The reference to the @@ -138,20 +99,12 @@ int main(int, char * argv[]) // actually executes. // // \index{otb::ImageFileReader!GetOutput()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::Pointer image = reader->GetOutput(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Any attempt to access image data before the reader executes will yield // an image with no pixel data. It is likely that a program crash will // result since the image will not have been properly initialized. - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Image/Image3.cxx b/Examples/Image/Image3.cxx index 6f4d2452a42f79d1062ed35f9e10e16dc4108107..b00873ccad1c7a3d87edff3bbb7409ccc52f0d69 100644 --- a/Examples/Image/Image3.cxx +++ b/Examples/Image/Image3.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates the use of the \code{SetPixel()} and // \code{GetPixel()} methods. These two methods provide direct access to the // pixel data contained in the image. Note that these two methods are @@ -32,12 +29,10 @@ // %Chapter~\ref{sec:ImageIteratorsChapter} on page // %\pageref{sec:ImageIteratorsChapter} for information about image // %iterators.) -// -// Software Guide : EndLatex #include "otbImage.h" -int main(int, char *[]) +int main(int, char* []) { // First the image type should be declared typedef otb::Image<unsigned short, 2> ImageType; @@ -49,11 +44,11 @@ int main(int, char *[]) ImageType::IndexType start; ImageType::SizeType size; - size[0] = 200; // size along X - size[1] = 200; // size along Y + size[0] = 200; // size along X + size[1] = 200; // size along Y - start[0] = 0; // first index on X - start[1] = 0; // first index on Y + start[0] = 0; // first index on X + start[1] = 0; // first index on Y ImageType::RegionType region; region.SetSize(size); @@ -67,8 +62,6 @@ int main(int, char *[]) ImageType::PixelType initialValue = 0; image->FillBuffer(initialValue); - // Software Guide : BeginLatex - // // The individual position of a pixel inside the image is identified by a // unique index. An index is an array of integers that defines the position // of the pixel along each coordinate dimension of the image. The IndexType @@ -86,44 +79,26 @@ int main(int, char *[]) // // The following lines declare an instance of the index type and initialize // its content in order to associate it with a pixel position in the image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::IndexType pixelIndex; - pixelIndex[0] = 27; // x position - pixelIndex[1] = 29; // y position - // Software Guide : EndCodeSnippet + pixelIndex[0] = 27; // x position + pixelIndex[1] = 29; // y position - // Software Guide : BeginLatex - // // Having defined a pixel position with an index, it is then possible to // access the content of the pixel in the image. The \code{GetPixel()} // method allows us to get the value of the pixels. // // \index{otb::Image!GetPixel()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::PixelType pixelValue = image->GetPixel(pixelIndex); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \code{SetPixel()} method allows us to set the value of the pixel. // // \index{otb::Image!SetPixel()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - image->SetPixel(pixelIndex, pixelValue + 1); - // Software Guide : EndCodeSnippet + image->SetPixel(pixelIndex, pixelValue + 1); - // Software Guide : BeginLatex - // // Please note that \code{GetPixel()} returns the pixel value using copy // and not reference semantics. Hence, the method cannot be used to // modify image data values. @@ -131,9 +106,6 @@ int main(int, char *[]) // Remember that both \code{SetPixel()} and \code{GetPixel()} are inefficient // and should only be used for debugging or for supporting interactions like // querying pixel values by clicking with the mouse. - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Image/Image4.cxx b/Examples/Image/Image4.cxx index 13ba6fce065b4737dc613a4b4264bb5fd539cdd1..d3393191318407b2697067d983a8b90c47d7515b 100644 --- a/Examples/Image/Image4.cxx +++ b/Examples/Image/Image4.cxx @@ -20,8 +20,6 @@ */ -// Software Guide : BeginLatex -// // Even though OTB can be used to perform // general image processing tasks, the primary purpose of the toolkit is the // processing of remote sensing image data. In that respect, additional @@ -59,13 +57,11 @@ // illustrated in the right side of the figure. Linear interpolation of // image values is performed inside the Delaunay region whose corners // are pixel centers. -// -// Software Guide : EndLatex #include "otbImage.h" #include "itkPoint.h" -int main(int, char *[]) +int main(int, char* []) { typedef otb::Image<unsigned short, 2> ImageType; @@ -74,11 +70,11 @@ int main(int, char *[]) ImageType::IndexType start; ImageType::SizeType size; - size[0] = 200; // size along X - size[1] = 200; // size along Y + size[0] = 200; // size along X + size[1] = 200; // size along Y - start[0] = 0; // first index on X - start[1] = 0; // first index on Y + start[0] = 0; // first index on X + start[1] = 0; // first index on Y ImageType::RegionType region; region.SetSize(size); @@ -89,8 +85,6 @@ int main(int, char *[]) image->FillBuffer(0); - // Software Guide : BeginLatex - // // Image spacing is represented in a \code{FixedArray} // whose size matches the dimension of the image. In order to manually set // the spacing of the image, an array of the corresponding type must be @@ -100,49 +94,31 @@ int main(int, char *[]) // spacing and origin. // // \index{otb::Image!Spacing} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::SpacingType spacing; // Note: measurement units (e.g., meters, feet, etc.) are defined by the application. spacing[0] = 0.70; // spacing along X spacing[1] = 0.70; // spacing along Y - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The array can be assigned to the image using // the \code{SetSignedSpacing()} method. // // \index{otb::Image!SetSignedSpacing()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet image->SetSignedSpacing(spacing); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The spacing information can be retrieved from an image by using the // \code{GetSignedSpacing()} method. This method returns a reference to a // \code{FixedArray}. The returned object can then be used to read the // contents of the array. Note the use of the \code{const} keyword to indicate // that the array will not be modified. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const ImageType::SpacingType& sp = image->GetSignedSpacing(); std::cout << "Spacing = "; std::cout << sp[0] << ", " << sp[1] << std::endl; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The image origin is managed in a similar way to the spacing. A // \code{Point} of the appropriate dimension must first be // allocated. The coordinates of the origin can then be assigned to @@ -158,37 +134,25 @@ int main(int, char *[]) // // \index{otb::Image!origin} // \index{otb::Image!SetOrigin()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::PointType origin; - origin[0] = 0.0; // coordinates of the - origin[1] = 0.0; // first pixel in 2-D + origin[0] = 0.0; // coordinates of the + origin[1] = 0.0; // first pixel in 2-D image->SetOrigin(origin); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The origin can also be retrieved from an image by using the // \code{GetOrigin()} method. This will return a reference to a // \code{Point}. The reference can be used to read the contents of // the array. Note again the use of the \code{const} keyword to indicate // that the array contents will not be modified. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const ImageType::PointType& orgn = image->GetOrigin(); std::cout << "Origin = "; std::cout << orgn[0] << ", " << orgn[1] << std::endl; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Once the spacing and origin of the image have been initialized, the image // will correctly map pixel indices to and from physical space // coordinates. The following code illustrates how a point in physical @@ -199,15 +163,9 @@ int main(int, char *[]) // templated over the type used to represent coordinates and over the // dimension of the space. In this particular case, the dimension of the // point must match the dimension of the image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef itk::Point<double, ImageType::ImageDimension> PointType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The Point class, like an \doxygen{itk}{Index}, is a relatively small and // simple object. For this reason, it is not reference-counted like the // large data objects in OTB. Consequently, it is also not manipulated @@ -218,32 +176,20 @@ int main(int, char *[]) // no bounds checking is performed on the index used to access a particular // point component. It is the user's responsibility to make sure that the // index is in the range $\{0, Dimension-1\}$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet PointType point; - point[0] = 1.45; // x coordinate - point[1] = 7.21; // y coordinate - // Software Guide : EndCodeSnippet + point[0] = 1.45; // x coordinate + point[1] = 7.21; // y coordinate - // Software Guide : BeginLatex - // // The image will map the point to an index using the values of the // current spacing and origin. An index object must be provided to // receive the results of the mapping. The index object can be // instantiated by using the \code{IndexType} defined in the Image // type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::IndexType pixelIndex; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \code{TransformPhysicalPointToIndex()} method of the image class // will compute the pixel index closest to the point provided. The method // checks for this index to be contained inside the current buffered pixel @@ -256,29 +202,21 @@ int main(int, char *[]) // image. // // \index{otb::Image!TransformPhysicalPointToIndex()} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet bool isInside = image->TransformPhysicalPointToIndex(point, pixelIndex); if (isInside) - { + { ImageType::PixelType pixelValue = image->GetPixel(pixelIndex); pixelValue += 5; image->SetPixel(pixelIndex, pixelValue); - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // Remember that \code{GetPixel()} and \code{SetPixel()} are very // inefficient methods for accessing pixel data. Image iterators should be // used when massive access to pixel data is required. - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Image/Image5.cxx b/Examples/Image/Image5.cxx index ab759a2d75375690f80379a41b8f19aaa3ea9c2b..45eb939ab0998cfdbc593deec39edd3adead74c9 100644 --- a/Examples/Image/Image5.cxx +++ b/Examples/Image/Image5.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // This example illustrates how to import data into the \doxygen{otb}{Image} // class. This is particularly useful for interfacing with other software // systems. Many systems use a contiguous block of memory as a buffer @@ -41,69 +38,45 @@ // // First, the header file of the ImportImageFilter class must be // included. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbImportImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileWriter.h" #include "itkRGBPixel.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 2) - { + { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " outputImageFile" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // Next, we select the data type to use to represent the image pixels. We // assume that the external block of memory uses the same data type to // represent the pixels. // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet - typedef unsigned char PixelType; - const unsigned int Dimension = 2; + typedef unsigned char PixelType; + const unsigned int Dimension = 2; typedef otb::Image<PixelType, Dimension> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The type of the ImportImageFilter is instantiated in the // following line. // // \index{otb::ImportImageFilter!Instantiation} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImportImageFilter<ImageType> ImportFilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // A filter object created using the \code{New()} method is then // assigned to a \code{SmartPointer}. // // \index{otb::ImportImageFilter!Pointer} // \index{otb::ImportImageFilter!New()} // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet ImportFilterType::Pointer importFilter = ImportFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // This filter requires the user to specify the size of the image to be // produced as output. The \code{SetRegion()} method is used to this end. // The image size should exactly match the number of pixels available in the @@ -113,13 +86,10 @@ int main(int argc, char * argv[]) // \index{otb::ImportImageFilter!New()} // \index{otb::ImportImageFilter!New()} // - // Software Guide : EndLatex - // - // Software Guide : BeginCodeSnippet ImportFilterType::SizeType size; - size[0] = 200; // size along X - size[1] = 200; // size along Y + size[0] = 200; // size along X + size[1] = 200; // size along Y ImportFilterType::IndexType start; start.Fill(0); @@ -129,57 +99,36 @@ int main(int argc, char * argv[]) region.SetSize(size); importFilter->SetRegion(region); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The origin of the output image is specified with the \code{SetOrigin()} // method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet double origin[Dimension]; - origin[0] = 0.0; // X coordinate - origin[1] = 0.0; // Y coordinate + origin[0] = 0.0; // X coordinate + origin[1] = 0.0; // Y coordinate importFilter->SetOrigin(origin); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The spacing of the image is passed with the \code{SetSpacing()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet double spacing[Dimension]; - spacing[0] = 1.0; // along X direction - spacing[1] = 1.0; // along Y direction + spacing[0] = 1.0; // along X direction + spacing[1] = 1.0; // along Y direction importFilter->SetSpacing(spacing); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Next we allocate the memory block containing the pixel data to be // passed to the ImportImageFilter. Note that we use exactly the // same size that was specified with the \code{SetRegion()} method. In a // practical application, you may get this buffer from some other library // using a different data structure to represent the images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet // MODIFIED - const unsigned int numberOfPixels = size[0] * size[1]; - PixelType * localBuffer = new PixelType[numberOfPixels]; - // Software Guide : EndCodeSnippet + const unsigned int numberOfPixels = size[0] * size[1]; + PixelType* localBuffer = new PixelType[numberOfPixels]; const double radius = 80.0; - // Software Guide : BeginLatex - // // Here we fill up the buffer with a binary sphere. We use simple // \code{for()} loops here similar to those found in the C or FORTRAN // programming languages. Note that otb @@ -187,29 +136,21 @@ int main(int argc, char * argv[]) // pixels. All pixel access tasks are instead performed using // \doxygen{otb}{ImageIterator}s that support the management of // n-dimensional images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const double radius2 = radius * radius; - PixelType * it = localBuffer; + PixelType* it = localBuffer; for (unsigned int y = 0; y < size[1]; y++) - { - const double dy = static_cast<double>(y) - static_cast<double>(size[1]) / - 2.0; + { + const double dy = static_cast<double>(y) - static_cast<double>(size[1]) / 2.0; for (unsigned int x = 0; x < size[0]; x++) - { - const double dx = static_cast<double>(x) - static_cast<double>(size[0]) / - 2.0; + { + const double dx = static_cast<double>(x) - static_cast<double>(size[0]) / 2.0; const double d2 = dx * dx + dy * dy; - *it++ = (d2 < radius2) ? 255 : 0; - } + *it++ = (d2 < radius2) ? 255 : 0; } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // The buffer is passed to the ImportImageFilter with the // \code{SetImportPointer()}. Note that the last argument of this method // specifies who will be responsible for deleting the memory block once it @@ -226,48 +167,34 @@ int main(int argc, char * argv[]) // other words, it is the application programmer's responsibility // to ensure that ImportImageFilter is only given // permission to delete the C++ \code{new} operator-allocated memory. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const bool importImageFilterWillOwnTheBuffer = true; - importFilter->SetImportPointer(localBuffer, numberOfPixels, - importImageFilterWillOwnTheBuffer); - // Software Guide : EndCodeSnippet + importFilter->SetImportPointer(localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer); - // Software Guide : BeginLatex - // // Finally, we can connect the output of this filter to a pipeline. // For simplicity we just use a writer here, but it could be any other filter. - // - // Software Guide : EndLatex typedef otb::ImageFileWriter<ImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[1]); - // Software Guide : BeginCodeSnippet writer->SetInput(dynamic_cast<ImageType*>(importFilter->GetOutput())); - // Software Guide : EndCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& exp) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << exp << std::endl; return -1; - } + } - // Software Guide : BeginLatex - // // Note that we do not call \code{delete} on the buffer since we pass // \code{true} as the last argument of \code{SetImportPointer()}. Now the // buffer is owned by the ImportImageFilter. - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Image/ImageListExample.cxx b/Examples/Image/ImageListExample.cxx index 744076a4552225c1a3410cf87d6b7ceef7f89e36..2f1a7da5ca7132ff29376b66deb2cab71d38e78e 100644 --- a/Examples/Image/ImageListExample.cxx +++ b/Examples/Image/ImageListExample.cxx @@ -19,8 +19,6 @@ */ -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{ImageList} // class. This class provides the functionnalities needed in order to // integrate image lists as data objects into the OTB @@ -33,12 +31,8 @@ // // The first thing required to read an image from a file is to include // the header file of the \doxygen{otb}{ImageFileReader} class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageList.h" -// Software Guide : EndCodeSnippet #include "itkMacro.h" @@ -46,109 +40,70 @@ #include "otbImageFileWriter.h" #include "otbImage.h" -int main(int itkNotUsed(argc), char * argv[]) +int main(int itkNotUsed(argc), char* argv[]) { - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; -// Software Guide : BeginLatex -// -// As usual, we start by defining the types for the pixel and image -// types, as well as those for the readers and writers. -// -// Software Guide : EndLatex + // As usual, we start by defining the types for the pixel and image + // types, as well as those for the readers and writers. -// Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef unsigned char InputPixelType; typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<InputImageType> WriterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now define the type for the image list. The -// \doxygen{otb}{ImageList} class is templated over the type of image -// contained in it. This means that all images in a list must have the -// same type. -// -// Software Guide : EndLatex + // We can now define the type for the image list. The + // \doxygen{otb}{ImageList} class is templated over the type of image + // contained in it. This means that all images in a list must have the + // same type. -// Software Guide : BeginCodeSnippet typedef otb::ImageList<InputImageType> ImageListType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Let us assume now that we want to read an image from a file and -// store it in a list. The first thing to do is to instantiate the -// reader and set the image file name. We effectively read the image -// by calling the \code{Update()}. -// -// Software Guide : EndLatex + // Let us assume now that we want to read an image from a file and + // store it in a list. The first thing to do is to instantiate the + // reader and set the image file name. We effectively read the image + // by calling the \code{Update()}. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFilename); reader->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We create an image list by using the \code{New()} method. -// -// Software Guide : EndLatex + // We create an image list by using the \code{New()} method. -// Software Guide : BeginCodeSnippet ImageListType::Pointer imageList = ImageListType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// In order to store the image in the list, the \code{PushBack()} -// method is used. -// -// Software Guide : EndLatex + // In order to store the image in the list, the \code{PushBack()} + // method is used. -// Software Guide : BeginCodeSnippet imageList->PushBack(reader->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We could repeat this operation for other readers or the outputs of -// filters. We will now write an image of the list to a file. We -// therefore instantiate a writer, set the image file name and set the -// input image for it. This is done by calling the \code{Back()} -// method of the list, which allows us to get the last element. -// -// Software Guide : EndLatex + // We could repeat this operation for other readers or the outputs of + // filters. We will now write an image of the list to a file. We + // therefore instantiate a writer, set the image file name and set the + // input image for it. This is done by calling the \code{Back()} + // method of the list, which allows us to get the last element. -// Software Guide : BeginCodeSnippet -// Getting the image from the list and writing it to file + // Getting the image from the list and writing it to file WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); writer->SetInput(imageList->Back()); writer->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Other useful methods are: -// \begin{itemize} -// \item \code{SetNthElement()} and \code{GetNthElement()} allow -// randomly accessing any element of the list. -// \item \code{Front()} to access to the first element of the list. -// \item \code{Erase()} to remove an element. -// \end{itemize} -// -// Also, iterator classes are defined in order to have an efficient -// mean of moving through the list. Finally, the -// \doxygen{otb}{ImageListToImageListFilter} is provided in order -// to implement filter which operate on image lists and produce image lists. -// Software Guide : EndLatex + // Other useful methods are: + // \begin{itemize} + // \item \code{SetNthElement()} and \code{GetNthElement()} allow + // randomly accessing any element of the list. + // \item \code{Front()} to access to the first element of the list. + // \item \code{Erase()} to remove an element. + // \end{itemize} + // + // Also, iterator classes are defined in order to have an efficient + // mean of moving through the list. Finally, the + // \doxygen{otb}{ImageListToImageListFilter} is provided in order + // to implement filter which operate on image lists and produce image lists. return EXIT_SUCCESS; } diff --git a/Examples/Image/VectorImage.cxx b/Examples/Image/VectorImage.cxx index 04e2a2ab3702522a5f3c8109e26cb02bc45e1b0f..b6cfce05f4dad7b86a2429b4a2bff8ab1c97e8da 100644 --- a/Examples/Image/VectorImage.cxx +++ b/Examples/Image/VectorImage.cxx @@ -20,9 +20,6 @@ */ - -// Software Guide : BeginLatex -// // Many image processing tasks require images of non-scalar pixel type. A // typical example is a multispectral image. The following code illustrates // how to instantiate and use an image whose pixels are of vector type. @@ -46,30 +43,20 @@ // \doxygen{itk}{VariableLengthVector}. // // The first step is to include the header file of the VectorImage class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbVectorImage.h" -// Software Guide : EndCodeSnippet -int main(int, char *[]) +int main(int, char* []) { - // Software Guide : BeginLatex - // // The VectorImage class is templated over the type used to represent // the coordinate in space and over the dimension of the space. In // this example, // we want to represent Pl\'eiades images which have 4 bands. // // \index{otb::VectorImage!Instantiation} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned char PixelType; typedef otb::VectorImage<PixelType, 2> ImageType; - // Software Guide : EndCodeSnippet // Then the image object can be created ImageType::Pointer image = ImageType::New(); @@ -78,11 +65,11 @@ int main(int, char *[]) ImageType::IndexType start; ImageType::SizeType size; - size[0] = 200; // size along X - size[1] = 200; // size along Y + size[0] = 200; // size along X + size[1] = 200; // size along Y - start[0] = 0; // first index on X - start[1] = 0; // first index on Y + start[0] = 0; // first index on X + start[1] = 0; // first index on Y ImageType::RegionType region; region.SetSize(size); @@ -91,70 +78,46 @@ int main(int, char *[]) // Pixel data is allocated image->SetRegions(region); - // Software Guide : BeginLatex // Since the pixel dimensionality is chosen at runtime, one has to // pass this parameter to the image before memory allocation. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet image->SetNumberOfComponentsPerPixel(4); image->Allocate(); - // Software Guide : EndCodeSnippet ImageType::IndexType pixelIndex; - pixelIndex[0] = 27; // x position - pixelIndex[1] = 29; // y position + pixelIndex[0] = 27; // x position + pixelIndex[1] = 29; // y position - // Software Guide : BeginLatex - // // The VariableLengthVector class overloads the operator // \code{[]}. This makes it possible to access the // Vector's components using index notation. The user must not // forget to allocate the memory for each individual pixel by using // the \code{Reserve} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::PixelType pixelValue; pixelValue.Reserve(4); - pixelValue[0] = 1; // Blue component - pixelValue[1] = 6; // Green component - pixelValue[2] = 100; // Red component - pixelValue[3] = 100; // NIR component - // Software Guide : EndCodeSnippet + pixelValue[0] = 1; // Blue component + pixelValue[1] = 6; // Green component + pixelValue[2] = 100; // Red component + pixelValue[3] = 100; // NIR component - // Software Guide : BeginLatex - // // We can now store this vector in one of the image pixels by defining an // index and invoking the \code{SetPixel()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - image->SetPixel(pixelIndex, pixelValue); - // Software Guide : EndCodeSnippet + image->SetPixel(pixelIndex, pixelValue); - // Software Guide : BeginLatex // The GetPixel method can also be used to read Vectors // pixels from the image - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::PixelType value = image->GetPixel(pixelIndex); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are // inefficient and should only be used for debugging purposes or for // implementing interactions with a graphical user interface such as // querying pixel value by clicking with the mouse. - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Installation/HelloWorld.cxx b/Examples/Installation/HelloWorld.cxx index f620a77677c3bced4edd64b24554ae1280659b18..f0040c92a6cce97ffa626e5b3ef0dca239906be4 100644 --- a/Examples/Installation/HelloWorld.cxx +++ b/Examples/Installation/HelloWorld.cxx @@ -19,15 +19,10 @@ */ -// Software Guide : BeginLatex -// // The following code is an implementation of a small OTB // program. It tests including header files and linking with OTB // libraries. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include <iostream> @@ -41,10 +36,7 @@ int main() return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // This code instantiates an image whose pixels are represented with // type \code{unsigned short}. The image is then constructed and assigned to a // \doxygen{itk}{SmartPointer}. Although later in the text we will discuss @@ -52,5 +44,3 @@ int main() // instance of an object (see section \ref{sec:SmartPointers} for more // information). The \doxygen{itk}{Image} class will be described in // Section~\ref{sec:ImageSection}. -// -// Software Guide : EndLatex diff --git a/Examples/Iterators/ImageLinearIteratorWithIndex.cxx b/Examples/Iterators/ImageLinearIteratorWithIndex.cxx index 52007b2812411950f3dc0bba454287b02f799a2a..144eedb4cc8877a782b55da2a5710638fe5602c8 100644 --- a/Examples/Iterators/ImageLinearIteratorWithIndex.cxx +++ b/Examples/Iterators/ImageLinearIteratorWithIndex.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // The \doxygen{itk}{ImageLinearIteratorWithIndex} is designed for line-by-line // processing of an image. It walks a linear path along a selected image // direction parallel to one of the coordinate axes of the image. This @@ -92,47 +89,35 @@ // \index{itk::ImageLinearIteratorWithIndex!example of using|(} // // Headers for both the const and non-const versions are needed. -// -// Software Guide : EndLatex #include "otbImage.h" #include "itkRGBPixel.h" -// Software Guide : BeginCodeSnippet #include "itkImageLinearIteratorWithIndex.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 3) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// The RGB image and pixel types are defined as in the previous example. The -// ImageLinearIteratorWithIndex class and its const version each have -// single template parameters, the image type. -// -// Software Guide : EndLatex + // The RGB image and pixel types are defined as in the previous example. The + // ImageLinearIteratorWithIndex class and its const version each have + // single template parameters, the image type. const unsigned int Dimension = 2; typedef itk::RGBPixel<unsigned char> RGBPixelType; typedef otb::Image<RGBPixelType, Dimension> ImageType; -// Software Guide : BeginCodeSnippet typedef itk::ImageLinearIteratorWithIndex<ImageType> IteratorType; typedef itk::ImageLinearConstIteratorWithIndex<ImageType> ConstIteratorType; -// Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; @@ -141,93 +126,71 @@ int main(int argc, char *argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); inputImage = reader->GetOutput(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught a !" << std::endl; std::cout << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// After reading the input image, we allocate an output image that of the same -// size, spacing, and origin. -// -// Software Guide : EndLatex + // After reading the input image, we allocate an output image that of the same + // size, spacing, and origin. -// Software Guide : BeginCodeSnippet ImageType::Pointer outputImage = ImageType::New(); outputImage->SetRegions(inputImage->GetRequestedRegion()); outputImage->CopyInformation(inputImage); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Next we create the two iterators. The const iterator walks the input image, -// and the non-const iterator walks the output image. The iterators are -// initialized over the same region. The direction of iteration is set to 0, -// the $x$ dimension. -// -// Software Guide : EndLatex + // Next we create the two iterators. The const iterator walks the input image, + // and the non-const iterator walks the output image. The iterators are + // initialized over the same region. The direction of iteration is set to 0, + // the $x$ dimension. -// Software Guide : BeginCodeSnippet ConstIteratorType inputIt(inputImage, inputImage->GetRequestedRegion()); IteratorType outputIt(outputImage, inputImage->GetRequestedRegion()); inputIt.SetDirection(0); outputIt.SetDirection(0); -// Software Guide : EndCodeSnippet -// Software Guide: BeginLatex -// -// Each line in the input is copied to the output. The input iterator moves -// forward across columns while the output iterator moves backwards. -// -// Software Guide : EndLatex + // Each line in the input is copied to the output. The input iterator moves + // forward across columns while the output iterator moves backwards. -// Software Guide : BeginCodeSnippet - for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); - outputIt.NextLine(), inputIt.NextLine()) - { + for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); outputIt.NextLine(), inputIt.NextLine()) + { inputIt.GoToBeginOfLine(); outputIt.GoToEndOfLine(); --outputIt; while (!inputIt.IsAtEndOfLine()) - { + { outputIt.Set(inputIt.Get()); ++inputIt; --outputIt; - } } -// Software Guide : EndCodeSnippet + } WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(outputImage); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// Running this example on \code{ROI\_QB\_MUL\_1.tif} produces -// the same output image shown in -// Figure~\ref{fig:ImageRegionIteratorWithIndexExample}. -// -// \index{itk::ImageLinearIteratorWithIndex!example of using|)} -// Software Guide : EndLatex + // Running this example on \code{ROI\_QB\_MUL\_1.tif} produces + // the same output image shown in + // Figure~\ref{fig:ImageRegionIteratorWithIndexExample}. + // + // \index{itk::ImageLinearIteratorWithIndex!example of using|)} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ImageLinearIteratorWithIndex2.cxx b/Examples/Iterators/ImageLinearIteratorWithIndex2.cxx index 0d68dccadab656aae2cf0e16f1d6d3516c2fae41..56b7ce2f58759bee12db0797d063578b931b4e8e 100644 --- a/Examples/Iterators/ImageLinearIteratorWithIndex2.cxx +++ b/Examples/Iterators/ImageLinearIteratorWithIndex2.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // This example shows how to use the \doxygen{itk}{ImageLinearIteratorWithIndex} for // computing the mean across time of a 4D image where the first three // dimensions correspond to spatial coordinates and the fourth dimension @@ -30,36 +27,25 @@ // // \index{Iterators!and 4D images} // \index{ImageLinearIteratorWithIndex!4D images} -// -// Software Guide : EndLatex #include "otbImage.h" -// Software Guide : BeginCodeSnippet #include "itkImageLinearConstIteratorWithIndex.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 3) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " input4DImageFile output3DImageFile" - << std::endl; + std::cerr << argv[0] << " input4DImageFile output3DImageFile" << std::endl; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// First we declare the types of the images -// -// Software Guide : EndLatex + // First we declare the types of the images -// Software Guide : BeginCodeSnippet typedef unsigned char PixelType; typedef otb::Image<PixelType, 3> Image3DType; typedef otb::Image<PixelType, 4> Image4DType; @@ -71,19 +57,19 @@ int main(int argc, char *argv[]) reader4D->SetFileName(argv[1]); try - { + { reader4D->Update(); - } + } catch (itk::ExceptionObject& excp) - { + { std::cerr << "Error writing the image" << std::endl; std::cerr << excp << std::endl; return EXIT_FAILURE; - } + } Image4DType::ConstPointer image4D = reader4D->GetOutput(); - Image3DType::Pointer image3D = Image3DType::New(); + Image3DType::Pointer image3D = Image3DType::New(); typedef Image3DType::IndexType Index3DType; typedef Image3DType::SizeType Size3DType; typedef Image3DType::RegionType Region3DType; @@ -108,12 +94,12 @@ int main(int argc, char *argv[]) Origin4DType origin4D = image4D->GetOrigin(); for (unsigned int i = 0; i < 3; ++i) - { + { size3D[i] = size4D[i]; index3D[i] = index4D[i]; spacing3D[i] = spacing4D[i]; origin3D[i] = origin4D[i]; - } + } image3D->SetSignedSpacing(spacing3D); image3D->SetOrigin(origin3D); @@ -130,24 +116,22 @@ int main(int argc, char *argv[]) const unsigned int timeLength = region4D.GetSize()[3]; - typedef itk::ImageLinearConstIteratorWithIndex< - Image4DType> IteratorType; + typedef itk::ImageLinearConstIteratorWithIndex<Image4DType> IteratorType; IteratorType it(image4D, region4D); - it.SetDirection(3); // Walk along time dimension + it.SetDirection(3); // Walk along time dimension it.GoToBegin(); while (!it.IsAtEnd()) - { + { SumType sum = itk::NumericTraits<SumType>::Zero; it.GoToBeginOfLine(); index4D = it.GetIndex(); while (!it.IsAtEndOfLine()) - { + { sum += it.Get(); ++it; - } - MeanType mean = static_cast<MeanType>(sum) / - static_cast<MeanType>(timeLength); + } + MeanType mean = static_cast<MeanType>(sum) / static_cast<MeanType>(timeLength); index3D[0] = index4D[0]; index3D[1] = index4D[1]; @@ -155,41 +139,36 @@ int main(int argc, char *argv[]) image3D->SetPixel(index3D, static_cast<PixelType>(mean)); it.NextLine(); - } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// As you can see, we avoid to use a 3D iterator to walk -// over the mean image. The reason is that there is no -// guarantee that the 3D iterator will walk in the same -// order as the 4D. Iterators just adhere to their contract -// of visiting all the pixel, but do not enforce any particular -// order for the visits. The linear iterator guarantees to -// visit the pixels along a line of the image in the order -// in which they are placed in the line, but do not states -// in what order one line will be visited with respect to -// other lines. Here we simply take advantage of knowing -// the first three components of the 4D iterator index, -// and use them to place the resulting mean value in the -// output 3D image. -// -// Software Guide : EndLatex + } + + // As you can see, we avoid to use a 3D iterator to walk + // over the mean image. The reason is that there is no + // guarantee that the 3D iterator will walk in the same + // order as the 4D. Iterators just adhere to their contract + // of visiting all the pixel, but do not enforce any particular + // order for the visits. The linear iterator guarantees to + // visit the pixels along a line of the image in the order + // in which they are placed in the line, but do not states + // in what order one line will be visited with respect to + // other lines. Here we simply take advantage of knowing + // the first three components of the 4D iterator index, + // and use them to place the resulting mean value in the + // output 3D image. Writer3DType::Pointer writer3D = Writer3DType::New(); writer3D->SetFileName(argv[2]); writer3D->SetInput(image3D); try - { + { writer3D->Update(); - } + } catch (itk::ExceptionObject& excp) - { + { std::cerr << "Error writing the image" << std::endl; std::cerr << excp << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ImageRandomConstIteratorWithIndex.cxx b/Examples/Iterators/ImageRandomConstIteratorWithIndex.cxx index 095cdf7f048ffdea19c1ea56bbe5fd6987d01b03..4e24eb6405f07124303b88d4de4b34523f381583 100644 --- a/Examples/Iterators/ImageRandomConstIteratorWithIndex.cxx +++ b/Examples/Iterators/ImageRandomConstIteratorWithIndex.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // \doxygen{itk}{ImageRandomConstIteratorWithIndex} was developed to randomly // sample pixel values. When incremented or decremented, it jumps to a random // location in its image region. @@ -44,36 +41,28 @@ // example calculates an estimate of the arithmetic mean of pixel values. // // First, include the appropriate header and declare pixel and image types. -// -// Software Guide : EndLatex #include "otbImage.h" -// Software Guide : BeginCodeSnippet #include "itkImageRandomConstIteratorWithIndex.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 3) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile numberOfSamples" - << std::endl; + std::cerr << argv[0] << " inputImageFile numberOfSamples" << std::endl; return -1; - } + } -// Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef unsigned short PixelType; typedef otb::Image<PixelType, Dimension> ImageType; typedef itk::ImageRandomConstIteratorWithIndex<ImageType> ConstIteratorType; -// Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; @@ -81,75 +70,60 @@ int main(int argc, char *argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); inputImage = reader->GetOutput(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// The input image has been read as \code{inputImage}. We now create an -// iterator with a number of samples set by command line argument. The call to -// \code{ReinitializeSeed} seeds the random number generator. The iterator is -// initialized over the entire valid image region. -// -// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!SetNumberOfSamples()} -// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!ReinitializeSeed()} -// Software Guide : EndLatex + // The input image has been read as \code{inputImage}. We now create an + // iterator with a number of samples set by command line argument. The call to + // \code{ReinitializeSeed} seeds the random number generator. The iterator is + // initialized over the entire valid image region. + // + // \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!SetNumberOfSamples()} + // \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!ReinitializeSeed()} -// Software Guide : BeginCodeSnippet - ConstIteratorType inputIt(inputImage, inputImage->GetRequestedRegion()); + ConstIteratorType inputIt(inputImage, inputImage->GetRequestedRegion()); inputIt.SetNumberOfSamples(::atoi(argv[2])); inputIt.ReinitializeSeed(); -// Software Guide : EndCodeSnippet -// Software Guide: BeginLatex -// -// Now take the specified number of samples and calculate their average value. -// -// Software Guide : EndLatex + // Now take the specified number of samples and calculate their average value. -// Software Guide : BeginCodeSnippet float mean = 0.0f; for (inputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt) - { + { mean += static_cast<float>(inputIt.Get()); - } + } mean = mean / ::atof(argv[2]); -// Software Guide : EndCodeSnippet - std::cout << "Mean estimate with " << argv[2] << " samples is " << mean << - std::endl; + std::cout << "Mean estimate with " << argv[2] << " samples is " << mean << std::endl; -// Software Guide : BeginLatex -// -// Table~\ref{fig:ImageRandomConstIteratorWithIndexExample} shows the results -// of running this example on several of the data files from -// \code{Examples/Data} with a range of sample sizes. -// -// \begin{table} -// \begin{center} -// \begin{tabular}[]{rc|c|c|c} -// & \multicolumn{4}{c}{\emph{Sample Size}} \\ & \code{\textbf{10}} & \code{\textbf{100}} -// & \code{\textbf{1000}} -// & \code{\textbf{10000}} \\ \cline{2-5} -// \code{RatLungSlice1.mha} & 50.5 & 52.4 & 53.0 & 52.4 \\ \code{RatLungSlice2.mha} -// & 46.7 & 47.5 & 47.4 & 47.6 \\ \code{BrainT1Slice.png} -// & 47.2 & 64.1 & 68.0 & 67.8 \\ \end{tabular} -// \protect\label{fig:ImageRandomConstIteratorWithIndexExample} -// \itkcaption[ImageRandomConstIteratorWithIndex usage]{Estimates of mean image pixel -// value using the ImageRandomConstIteratorWithIndex at different sample -// sizes.} -// \end{center} -// \end{table} -// -// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!example of using|)} -// Software Guide : EndLatex + // Table~\ref{fig:ImageRandomConstIteratorWithIndexExample} shows the results + // of running this example on several of the data files from + // \code{Examples/Data} with a range of sample sizes. + // + // \begin{table} + // \begin{center} + // \begin{tabular}[]{rc|c|c|c} + // & \multicolumn{4}{c}{\emph{Sample Size}} \\ & \code{\textbf{10}} & \code{\textbf{100}} + // & \code{\textbf{1000}} + // & \code{\textbf{10000}} \\ \cline{2-5} + // \code{RatLungSlice1.mha} & 50.5 & 52.4 & 53.0 & 52.4 \\ \code{RatLungSlice2.mha} + // & 46.7 & 47.5 & 47.4 & 47.6 \\ \code{BrainT1Slice.png} + // & 47.2 & 64.1 & 68.0 & 67.8 \\ \end{tabular} + // \protect\label{fig:ImageRandomConstIteratorWithIndexExample} + // \itkcaption[ImageRandomConstIteratorWithIndex usage]{Estimates of mean image pixel + // value using the ImageRandomConstIteratorWithIndex at different sample + // sizes.} + // \end{center} + // \end{table} + // + // \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!example of using|)} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ImageRegionIterator.cxx b/Examples/Iterators/ImageRegionIterator.cxx index ac89632af9cecddcc4b640ca2e6045472772b370..bbb348844d011ac2d665c1bd34767dbc9732c059 100644 --- a/Examples/Iterators/ImageRegionIterator.cxx +++ b/Examples/Iterators/ImageRegionIterator.cxx @@ -19,14 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {ImageRegionIteratorOutput.png} -// 10 10 110 140 -// Software Guide : EndCommandLineArgs +/* Example usage: +./ImageRegionIterator Input/QB_Suburb.png Output/ImageRegionIteratorOutput.png 10 10 110 140 +*/ + -// Software Guide : BeginLatex -// // \index{Iterators!speed} // The \doxygen{itk}{ImageRegionIterator} is optimized for // iteration speed and is the first choice for iterative, pixel-wise operations @@ -44,36 +41,26 @@ // \index{Iterators!and image regions} // \index{itk::ImageRegionIterator!example of using|(} // We begin by including the appropriate header files. -// Software Guide : EndLatex #include "otbImage.h" -// Software Guide : BeginCodeSnippet #include "itkImageRegionIterator.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 7) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile startX startY sizeX sizeY" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile startX startY sizeX sizeY" << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// Next we define a pixel type and corresponding image type. ITK iterator -// classes expect the image type as their template parameter. -// -// Software Guide : EndLatex + // Next we define a pixel type and corresponding image type. ITK iterator + // classes expect the image type as their template parameter. - // Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef unsigned char PixelType; @@ -81,20 +68,14 @@ int main(int argc, char *argv[]) typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType; typedef itk::ImageRegionIterator<ImageType> IteratorType; - // Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; -// Software Guide : BeginLatex -// -// Information about the subregion to copy is read from the command line. The -// subregion is defined by an \doxygen{itk}{ImageRegion} object, with a starting -// grid index and a size (Section~\ref{sec:ImageSection}). -// -// Software Guide : EndLatex + // Information about the subregion to copy is read from the command line. The + // subregion is defined by an \doxygen{itk}{ImageRegion} object, with a starting + // grid index and a size (Section~\ref{sec:ImageSection}). -// Software Guide : BeginCodeSnippet ImageType::RegionType inputRegion; ImageType::RegionType::IndexType inputStart; @@ -103,22 +84,16 @@ int main(int argc, char *argv[]) inputStart[0] = ::atoi(argv[3]); inputStart[1] = ::atoi(argv[4]); - size[0] = ::atoi(argv[5]); - size[1] = ::atoi(argv[6]); + size[0] = ::atoi(argv[5]); + size[1] = ::atoi(argv[6]); inputRegion.SetSize(size); inputRegion.SetIndex(inputStart); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The destination region in the output image is defined using the input region -// size, but a different start index. The starting index for the destination -// region is the corner of the newly generated image. -// -// Software Guide : EndLatex + // The destination region in the output image is defined using the input region + // size, but a different start index. The starting index for the destination + // region is the corner of the newly generated image. -// Software Guide : BeginCodeSnippet ImageType::RegionType outputRegion; ImageType::RegionType::IndexType outputStart; @@ -128,140 +103,116 @@ int main(int argc, char *argv[]) outputRegion.SetSize(size); outputRegion.SetIndex(outputStart); -// Software Guide : EndCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return -1; - } + } // Check that the region is contained within the input image. if (!reader->GetOutput()->GetRequestedRegion().IsInside(inputRegion)) - { + { std::cerr << "Error" << std::endl; - std::cerr << "The region " << inputRegion << - "is not contained within the input image region " - << reader->GetOutput()->GetRequestedRegion() << std::endl; + std::cerr << "The region " << inputRegion << "is not contained within the input image region " << reader->GetOutput()->GetRequestedRegion() << std::endl; return -1; - } - -// Software Guide : BeginLatex -// -// After reading the input image and checking that the desired subregion is, -// in fact, contained in the input, we allocate an output image. It is -// fundamental to set valid values to some of the basic image information -// during the copying process. -// In particular, the starting index of the output region -// is now filled up with zero values and the coordinates of the physical -// origin are computed as a shift from the origin of the input image. This is -// quite important since it will allow us to later -// register the extracted region against the original image. -// -// Software Guide : EndLatex + } + + // After reading the input image and checking that the desired subregion is, + // in fact, contained in the input, we allocate an output image. It is + // fundamental to set valid values to some of the basic image information + // during the copying process. + // In particular, the starting index of the output region + // is now filled up with zero values and the coordinates of the physical + // origin are computed as a shift from the origin of the input image. This is + // quite important since it will allow us to later + // register the extracted region against the original image. -// Software Guide : BeginCodeSnippet ImageType::Pointer outputImage = ImageType::New(); outputImage->SetRegions(outputRegion); - const ImageType::SpacingType& spacing = reader->GetOutput()->GetSignedSpacing(); + const ImageType::SpacingType& spacing = reader->GetOutput()->GetSignedSpacing(); const ImageType::PointType& inputOrigin = reader->GetOutput()->GetOrigin(); double outputOrigin[Dimension]; for (unsigned int i = 0; i < Dimension; ++i) - { + { outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i]; - } + } outputImage->SetSignedSpacing(spacing); outputImage->SetOrigin(outputOrigin); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// \index{Iterators!construction of} \index{Iterators!and image regions} -// The necessary images and region definitions are now in place. All that is -// left to do is to create the iterators and perform the copy. Note that image -// iterators are not accessed via smart pointers so they are light-weight -// objects that are instantiated on the stack. Also notice how the input and -// output iterators are defined over the \emph{same corresponding region}. Though the -// images are different sizes, they both contain the same target subregion. -// -// Software Guide : EndLatex + // \index{Iterators!construction of} \index{Iterators!and image regions} + // The necessary images and region definitions are now in place. All that is + // left to do is to create the iterators and perform the copy. Note that image + // iterators are not accessed via smart pointers so they are light-weight + // objects that are instantiated on the stack. Also notice how the input and + // output iterators are defined over the \emph{same corresponding region}. Though the + // images are different sizes, they both contain the same target subregion. -// Software Guide : BeginCodeSnippet ConstIteratorType inputIt(reader->GetOutput(), inputRegion); - IteratorType outputIt(outputImage, outputRegion); + IteratorType outputIt(outputImage, outputRegion); - for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); - ++inputIt, ++outputIt) - { + for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt) + { outputIt.Set(inputIt.Get()); - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// \index{Iterators!image dimensionality} -// The \code{for} loop above is a common -// construct in ITK/OTB. The beauty of these four lines of code is that they are -// equally valid for one, two, three, or even ten dimensional data, and no -// knowledge of the size of the image is necessary. Consider the ugly -// alternative of ten nested \code{for} loops for traversing an image. -// -// Software Guide : EndLatex + // \index{Iterators!image dimensionality} + // The \code{for} loop above is a common + // construct in ITK/OTB. The beauty of these four lines of code is that they are + // equally valid for one, two, three, or even ten dimensional data, and no + // knowledge of the size of the image is necessary. Consider the ugly + // alternative of ten nested \code{for} loops for traversing an image. WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(outputImage); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return -1; - } - -// Software Guide : BeginLatex -// -// Let's run this example on the image \code{QB\_Suburb.png} found -// in \code{Examples/Data}. The command line arguments specify the -// input and output file names, then the $x$, $y$ origin and the $x$, $y$ size -// of the cropped subregion. -// -// \small -// \begin{verbatim} -// ImageRegionIterator QB_Suburb.png ImageRegionIteratorOutput.png 20 70 210 140 -// \end{verbatim} -// \normalsize -// -// The output is the cropped subregion shown in -// Figure~\ref{fig:ImageRegionIteratorOutput}. -// -// \begin{figure} -// \centering -// \includegraphics[width=0.4\textwidth]{QB_Suburb.eps} -// \includegraphics[width=0.3\textwidth]{ImageRegionIteratorOutput.eps} -// \itkcaption[Copying an image subregion using ImageRegionIterator]{Cropping a -// region from an image. The original image is shown at left. The image on -// the right is the result of applying the ImageRegionIterator example code.} -// \protect\label{fig:ImageRegionIteratorOutput} -// \end{figure} -// -// \index{itk::ImageRegionIterator!example of using|)} -// -// Software Guide : EndLatex + } + + // Let's run this example on the image \code{QB\_Suburb.png} found + // in \code{Examples/Data}. The command line arguments specify the + // input and output file names, then the $x$, $y$ origin and the $x$, $y$ size + // of the cropped subregion. + // + // \small + // \begin{verbatim} + // ImageRegionIterator QB_Suburb.png ImageRegionIteratorOutput.png 20 70 210 140 + // \end{verbatim} + // \normalsize + // + // The output is the cropped subregion shown in + // Figure~\ref{fig:ImageRegionIteratorOutput}. + // + // \begin{figure} + // \centering + // \includegraphics[width=0.4\textwidth]{QB_Suburb.eps} + // \includegraphics[width=0.3\textwidth]{ImageRegionIteratorOutput.eps} + // \itkcaption[Copying an image subregion using ImageRegionIterator]{Cropping a + // region from an image. The original image is shown at left. The image on + // the right is the result of applying the ImageRegionIterator example code.} + // \protect\label{fig:ImageRegionIteratorOutput} + // \end{figure} + // + // \index{itk::ImageRegionIterator!example of using|)} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ImageRegionIteratorWithIndex.cxx b/Examples/Iterators/ImageRegionIteratorWithIndex.cxx index ff58cba58818adaccacdef72e01b190f33192f7f..299585c7f25a719b907ed269c24688a7485da4d6 100644 --- a/Examples/Iterators/ImageRegionIteratorWithIndex.cxx +++ b/Examples/Iterators/ImageRegionIteratorWithIndex.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_2.tif} -// OUTPUTS: {ImageRegionIteratorWithIndexOutput.jpg} -// Software Guide : EndCommandLineArgs +/* Example usage: +./ImageRegionIteratorWithIndex Input/ROI_QB_MUL_2.tif Output/ImageRegionIteratorWithIndexOutput.jpg +*/ + -// Software Guide : BeginLatex -// // \index{Iterators!speed} // The ``WithIndex'' family of iterators was designed for algorithms that // use both the value and the location of image pixels in calculations. Unlike @@ -44,47 +42,35 @@ // method. // // We start by including the proper header file. -// -// Software Guide : EndLatex #include "otbImage.h" #include "itkRGBPixel.h" -// Software Guide : BeginCodeSnippet #include "itkImageRegionIteratorWithIndex.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 3) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// For this example, we will use an RGB pixel type so that we can process color -// images. Like most other ITK image iterator, -// ImageRegionIteratorWithIndex class expects the image type as its -// single template parameter. -// -// Software Guide : EndLatex + // For this example, we will use an RGB pixel type so that we can process color + // images. Like most other ITK image iterator, + // ImageRegionIteratorWithIndex class expects the image type as its + // single template parameter. -// Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef itk::RGBPixel<unsigned char> RGBPixelType; typedef otb::Image<RGBPixelType, Dimension> ImageType; typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType; -// Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; @@ -93,99 +79,75 @@ int main(int argc, char *argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); inputImage = reader->GetOutput(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// An \code{ImageType} smart pointer called \code{inputImage} points to the -// output of the image reader. After updating the image reader, we can -// allocate an output image of the same size, spacing, and origin as the -// input image. -// -// Software Guide : EndLatex + // An \code{ImageType} smart pointer called \code{inputImage} points to the + // output of the image reader. After updating the image reader, we can + // allocate an output image of the same size, spacing, and origin as the + // input image. -// Software Guide : BeginCodeSnippet ImageType::Pointer outputImage = ImageType::New(); outputImage->SetRegions(inputImage->GetRequestedRegion()); outputImage->CopyInformation(inputImage); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Next we create the iterator that walks the output image. This algorithm -// requires no iterator for the input image. -// -// Software Guide : EndLatex + // Next we create the iterator that walks the output image. This algorithm + // requires no iterator for the input image. -// Software Guide : BeginCodeSnippet IteratorType outputIt(outputImage, outputImage->GetRequestedRegion()); -// Software Guide : EndCodeSnippet -// Software Guide: BeginLatex -// -// This axis flipping algorithm works by iterating through the output image, -// querying the iterator for its index, and copying the value from the input -// at an index mirrored across the $x$-axis. -// -// Software Guide : EndLatex + // This axis flipping algorithm works by iterating through the output image, + // querying the iterator for its index, and copying the value from the input + // at an index mirrored across the $x$-axis. -// Software Guide : BeginCodeSnippet - ImageType::IndexType requestedIndex = - outputImage->GetRequestedRegion().GetIndex(); - ImageType::SizeType requestedSize = - outputImage->GetRequestedRegion().GetSize(); + ImageType::IndexType requestedIndex = outputImage->GetRequestedRegion().GetIndex(); + ImageType::SizeType requestedSize = outputImage->GetRequestedRegion().GetSize(); for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt) - { + { ImageType::IndexType idx = outputIt.GetIndex(); - idx[0] = requestedIndex[0] + requestedSize[0] - 1 - idx[0]; + idx[0] = requestedIndex[0] + requestedSize[0] - 1 - idx[0]; outputIt.Set(inputImage->GetPixel(idx)); - } -// Software Guide : EndCodeSnippet + } WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(outputImage); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } - -// Software Guide : BeginLatex -// -// Let's run this example on the image \code{ROI\_QB\_MUL\_2.tif} found in -// the \code{Examples/Data} directory. -// Figure~\ref{fig:ImageRegionIteratorWithIndexExample} shows how the original -// image has been mirrored across its $x$-axis in the output. -// -// \begin{figure} \center -// \includegraphics[width=0.44\textwidth]{ROI_QB_MUL_2.eps} -// \includegraphics[width=0.44\textwidth]{ImageRegionIteratorWithIndexOutput.eps} -// \itkcaption[Using the ImageRegionIteratorWithIndex]{Results of using -// ImageRegionIteratorWithIndex to mirror an image across an axis. The original -// image is shown at left. The mirrored output is shown at right.} -// \label{fig:ImageRegionIteratorWithIndexExample} -// \end{figure} -// -// \index{itk::ImageRegionIteratorWithIndex!example of using|)} -// -// Software Guide : EndLatex + } + + // Let's run this example on the image \code{ROI\_QB\_MUL\_2.tif} found in + // the \code{Examples/Data} directory. + // Figure~\ref{fig:ImageRegionIteratorWithIndexExample} shows how the original + // image has been mirrored across its $x$-axis in the output. + // + // \begin{figure} \center + // \includegraphics[width=0.44\textwidth]{ROI_QB_MUL_2.eps} + // \includegraphics[width=0.44\textwidth]{ImageRegionIteratorWithIndexOutput.eps} + // \itkcaption[Using the ImageRegionIteratorWithIndex]{Results of using + // ImageRegionIteratorWithIndex to mirror an image across an axis. The original + // image is shown at left. The mirrored output is shown at right.} + // \label{fig:ImageRegionIteratorWithIndexExample} + // \end{figure} + // + // \index{itk::ImageRegionIteratorWithIndex!example of using|)} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ImageSliceIteratorWithIndex.cxx b/Examples/Iterators/ImageSliceIteratorWithIndex.cxx index ffca93bb1e141472adb716f02e5453efdcb8f565..60292584963bc8466a360c83141d3c2076f712ed 100644 --- a/Examples/Iterators/ImageSliceIteratorWithIndex.cxx +++ b/Examples/Iterators/ImageSliceIteratorWithIndex.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // \index{Iterators!and image slices} // // The \doxygen{itk}{ImageSliceIteratorWithIndex} class is an extension of @@ -96,56 +93,38 @@ // previous section. The linear iterator is chosen because it can be set to // follow the same path in its underlying 2D image that the slice iterator // follows over each slice of the 3D image. -// -// Software Guide : EndLatex #include "otbImage.h" #include "vnl/vnl_math.h" -// Software Guide : BeginCodeSnippet #include "itkImageSliceConstIteratorWithIndex.h" #include "itkImageLinearIteratorWithIndex.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Verify the number of parameters on the command line. if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile projectionDirection" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile projectionDirection" << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// The pixel type is defined as \code{unsigned short}. For this application, -// we need two image types, a 3D image for the input, and a 2D image for the -// intensity projection. -// -// Software Guide : EndLatex + // The pixel type is defined as \code{unsigned short}. For this application, + // we need two image types, a 3D image for the input, and a 2D image for the + // intensity projection. -// Software Guide : BeginCodeSnippet typedef unsigned short PixelType; typedef otb::Image<PixelType, 2> ImageType2D; typedef otb::Image<PixelType, 3> ImageType3D; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// A slice iterator type is defined to walk the input image. -// -// Software Guide : EndLatex + // A slice iterator type is defined to walk the input image. -// Software Guide : BeginCodeSnippet typedef itk::ImageLinearIteratorWithIndex<ImageType2D> LinearIteratorType; typedef itk::ImageSliceConstIteratorWithIndex<ImageType3D> SliceIteratorType; -// Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType3D> ReaderType; typedef otb::ImageFileWriter<ImageType2D> WriterType; @@ -154,63 +133,51 @@ int main(int argc, char *argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); inputImage = reader->GetOutput(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// The projection direction is read from the command line. The projection image -// will be the size of the 2D plane orthogonal to the projection direction. -// Its spanning vectors are the two remaining coordinate axes in the volume. -// These axes are recorded in the \code{direction} array. -// -// Software Guide : EndLatex + // The projection direction is read from the command line. The projection image + // will be the size of the 2D plane orthogonal to the projection direction. + // Its spanning vectors are the two remaining coordinate axes in the volume. + // These axes are recorded in the \code{direction} array. -// Software Guide : BeginCodeSnippet - unsigned int projectionDirection = - static_cast<unsigned int>(::atoi(argv[3])); + unsigned int projectionDirection = static_cast<unsigned int>(::atoi(argv[3])); unsigned int i, j; unsigned int direction[2]; for (i = 0, j = 0; i < 3; ++i) - { + { if (i != projectionDirection) - { + { direction[j] = i; ++j; - } } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// The \code{direction} array is now used to define the projection image size -// based on the input image size. The output image is created so that its -// common dimension(s) with the input image are the same size. For example, -// if we project along the $x$ axis of the input, the size and origin of the -// $y$ axes of the input and output will match. This makes the code slightly -// more complicated, but prevents a counter-intuitive rotation of the output. -// -// Software Guide : EndLatex + // The \code{direction} array is now used to define the projection image size + // based on the input image size. The output image is created so that its + // common dimension(s) with the input image are the same size. For example, + // if we project along the $x$ axis of the input, the size and origin of the + // $y$ axes of the input and output will match. This makes the code slightly + // more complicated, but prevents a counter-intuitive rotation of the output. -// Software Guide : BeginCodeSnippet ImageType2D::RegionType region; ImageType2D::RegionType::SizeType size; ImageType2D::RegionType::IndexType index; ImageType3D::RegionType requestedRegion = inputImage->GetRequestedRegion(); - index[direction[0]] = requestedRegion.GetIndex()[direction[0]]; + index[direction[0]] = requestedRegion.GetIndex()[direction[0]]; index[1 - direction[0]] = requestedRegion.GetIndex()[direction[1]]; - size[direction[0]] = requestedRegion.GetSize()[direction[0]]; + size[direction[0]] = requestedRegion.GetSize()[direction[0]]; size[1 - direction[0]] = requestedRegion.GetSize()[direction[1]]; region.SetSize(size); @@ -220,107 +187,89 @@ int main(int argc, char *argv[]) outputImage->SetRegions(region); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Next we create the necessary iterators. The const slice iterator walks -// the 3D input image, and the non-const linear iterator walks the 2D output -// image. The iterators are initialized to walk the same linear path through -// a slice. Remember that the \emph{second} direction of the slice iterator -// defines the direction that linear iteration walks within a slice. -// -// Software Guide : EndLatex + // Next we create the necessary iterators. The const slice iterator walks + // the 3D input image, and the non-const linear iterator walks the 2D output + // image. The iterators are initialized to walk the same linear path through + // a slice. Remember that the \emph{second} direction of the slice iterator + // defines the direction that linear iteration walks within a slice. -// Software Guide : BeginCodeSnippet - SliceIteratorType inputIt(inputImage, inputImage->GetRequestedRegion()); + SliceIteratorType inputIt(inputImage, inputImage->GetRequestedRegion()); LinearIteratorType outputIt(outputImage, outputImage->GetRequestedRegion()); inputIt.SetFirstDirection(direction[1]); inputIt.SetSecondDirection(direction[0]); outputIt.SetDirection(1 - direction[0]); -// Software Guide : EndCodeSnippet -// Software Guide: BeginLatex -// -// Now we are ready to compute the projection. The first step is to initialize -// all of the projection values to their nonpositive minimum value. The -// projection values are then updated row by row from the first slice of the -// input. At the end of the first slice, the input iterator steps to the first -// row in the next slice, while the output iterator, whose underlying image -// consists of only one slice, rewinds to its first row. The process repeats -// until the last slice of the input is processed. -// -// Software Guide : EndLatex + // Now we are ready to compute the projection. The first step is to initialize + // all of the projection values to their nonpositive minimum value. The + // projection values are then updated row by row from the first slice of the + // input. At the end of the first slice, the input iterator steps to the first + // row in the next slice, while the output iterator, whose underlying image + // consists of only one slice, rewinds to its first row. The process repeats + // until the last slice of the input is processed. -// Software Guide : BeginCodeSnippet outputIt.GoToBegin(); while (!outputIt.IsAtEnd()) - { + { while (!outputIt.IsAtEndOfLine()) - { + { outputIt.Set(itk::NumericTraits<unsigned short>::NonpositiveMin()); ++outputIt; - } - outputIt.NextLine(); } + outputIt.NextLine(); + } inputIt.GoToBegin(); outputIt.GoToBegin(); while (!inputIt.IsAtEnd()) - { + { while (!inputIt.IsAtEndOfSlice()) - { + { while (!inputIt.IsAtEndOfLine()) - { + { outputIt.Set(vnl_math_max(outputIt.Get(), inputIt.Get())); ++inputIt; ++outputIt; - } + } outputIt.NextLine(); inputIt.NextLine(); - - } + } outputIt.GoToBegin(); inputIt.NextSlice(); - } - // Software Guide : EndCodeSnippet + } WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(outputImage); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } - -// Software Guide : BeginLatex -// -// Running this example code on the 3D image -// \code{Examples/Data/BrainProtonDensity3Slices.mha} using the $z$-axis as -// the axis of projection gives the image shown in -// Figure~\ref{fig:ImageSliceIteratorWithIndexOutput}. -// -// \begin{figure} -// \centering -// \includegraphics[width=0.4\textwidth]{ImageSliceIteratorWithIndexOutput.eps} -// \itkcaption[Maximum intensity projection using ImageSliceIteratorWithIndex]{The -// maximum intensity projection through three slices of a volume.} -// \protect\label{fig:ImageSliceIteratorWithIndexOutput} -// \end{figure} -// -// -// \index{itk::Image\-Slice\-Iterator\-With\-Index!example of using|)} -// -// Software Guide : EndLatex + } + + // Running this example code on the 3D image + // \code{Examples/Data/BrainProtonDensity3Slices.mha} using the $z$-axis as + // the axis of projection gives the image shown in + // Figure~\ref{fig:ImageSliceIteratorWithIndexOutput}. + // + // \begin{figure} + // \centering + // \includegraphics[width=0.4\textwidth]{ImageSliceIteratorWithIndexOutput.eps} + // \itkcaption[Maximum intensity projection using ImageSliceIteratorWithIndex]{The + // maximum intensity projection through three slices of a volume.} + // \protect\label{fig:ImageSliceIteratorWithIndexOutput} + // \end{figure} + // + // + // \index{itk::Image\-Slice\-Iterator\-With\-Index!example of using|)} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators1.cxx b/Examples/Iterators/NeighborhoodIterators1.cxx index ee27ff35285fb531950ffbcaa8887481b7a8abc4..a6b92d91c95ac44565436ea6e7086a3c9660fdd0 100644 --- a/Examples/Iterators/NeighborhoodIterators1.cxx +++ b/Examples/Iterators/NeighborhoodIterators1.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_PAN_1.tif} -// OUTPUTS: {NeighborhoodIterators1a.png} -// Software Guide : EndCommandLineArgs +/* Example usage: +./NeighborhoodIterators1 Input/ROI_QB_PAN_1.tif Output/NeighborhoodIterators1a.png +*/ + -// Software Guide : BeginLatex -// // This example uses the \doxygen{itk}{NeighborhoodIterator} to implement a simple // Sobel edge detection algorithm \cite{Gonzalez1993}. The algorithm uses the // neighborhood iterator to iterate through an input image and calculate a @@ -39,8 +37,6 @@ // \doxygen{itk}{ImageRegionIterator} will be used to write the results of // computations to the output image. A const version of the neighborhood // iterator is used because the input image is read-only. -// -// Software Guide : EndLatex #include "otbImage.h" #include "otbImageFileReader.h" @@ -48,168 +44,121 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCodeSnippet #include "itkConstNeighborhoodIterator.h" #include "itkImageRegionIterator.h" -// Software Guide : EndCodeSnippet -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 3) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl; return -1; - } - -// Software Guide : BeginLatex -// -// The finite difference calculations -// in this algorithm require floating point values. Hence, we define the image -// pixel type to be \code{float} and the file reader will -// automatically cast fixed-point data to \code{float}. -// -// We declare the iterator types using the image type as -// the template parameter. The second template parameter of the -// neighborhood iterator, which specifies -// the boundary condition, has been omitted because the default condition is -// appropriate for this algorithm. -// -// Software Guide : EndLatex + } + + // The finite difference calculations + // in this algorithm require floating point values. Hence, we define the image + // pixel type to be \code{float} and the file reader will + // automatically cast fixed-point data to \code{float}. + // + // We declare the iterator types using the image type as + // the template parameter. The second template parameter of the + // neighborhood iterator, which specifies + // the boundary condition, has been omitted because the default condition is + // appropriate for this algorithm. -// Software Guide : BeginCodeSnippet typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef itk::ConstNeighborhoodIterator<ImageType> NeighborhoodIteratorType; typedef itk::ImageRegionIterator<ImageType> IteratorType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The following code creates and executes the OTB image reader. -// The \code{Update} -// call on the reader object is surrounded by the standard \code{try/catch} -// blocks to handle any exceptions that may be thrown by the reader. -// -// Software Guide : EndLatex + // The following code creates and executes the OTB image reader. + // The \code{Update} + // call on the reader object is surrounded by the standard \code{try/catch} + // blocks to handle any exceptions that may be thrown by the reader. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// We can now create a neighborhood iterator to range over the output of the -// reader. For Sobel edge-detection in 2D, we need a square iterator that -// extends one pixel away from the neighborhood center in every dimension. -// -// Software Guide : EndLatex + // We can now create a neighborhood iterator to range over the output of the + // reader. For Sobel edge-detection in 2D, we need a square iterator that + // extends one pixel away from the neighborhood center in every dimension. -// Software Guide : BeginCodeSnippet NeighborhoodIteratorType::RadiusType radius; radius.Fill(1); - NeighborhoodIteratorType it(radius, reader->GetOutput(), - reader->GetOutput()->GetRequestedRegion()); -// Software Guide : EndCodeSnippet + NeighborhoodIteratorType it(radius, reader->GetOutput(), reader->GetOutput()->GetRequestedRegion()); -// Software Guide : BeginLatex -// -// The following code creates an output image and iterator. -// -// Software Guide : EndLatex + // The following code creates an output image and iterator. -// Software Guide : BeginCodeSnippet ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); output->Allocate(); IteratorType out(output, reader->GetOutput()->GetRequestedRegion()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Sobel edge detection uses weighted finite difference calculations to -// construct an edge magnitude image. Normally the edge magnitude is the -// root sum of squares of partial derivatives in all directions, but for -// simplicity this example only calculates the $x$ component. The result is a -// derivative image biased toward maximally vertical edges. -// -// The finite differences are computed from pixels at six locations in the -// neighborhood. In this example, we use the iterator \code{GetPixel()} -// method to query the values from their offsets in the neighborhood. -// The example in Section~\ref{sec:NeighborhoodExample2} uses convolution -// with a Sobel kernel instead. -// -// Six positions in the neighborhood are necessary for the finite difference -// calculations. These positions are recorded in \code{offset1} through -// \code{offset6}. -// -// Software Guide : EndLatex + // Sobel edge detection uses weighted finite difference calculations to + // construct an edge magnitude image. Normally the edge magnitude is the + // root sum of squares of partial derivatives in all directions, but for + // simplicity this example only calculates the $x$ component. The result is a + // derivative image biased toward maximally vertical edges. + // + // The finite differences are computed from pixels at six locations in the + // neighborhood. In this example, we use the iterator \code{GetPixel()} + // method to query the values from their offsets in the neighborhood. + // The example in Section~\ref{sec:NeighborhoodExample2} uses convolution + // with a Sobel kernel instead. + // + // Six positions in the neighborhood are necessary for the finite difference + // calculations. These positions are recorded in \code{offset1} through + // \code{offset6}. -// Software Guide : BeginCodeSnippet NeighborhoodIteratorType::OffsetType offset1 = {{-1, -1}}; NeighborhoodIteratorType::OffsetType offset2 = {{1, -1}}; - NeighborhoodIteratorType::OffsetType offset3 = {{-1, 0 }}; + NeighborhoodIteratorType::OffsetType offset3 = {{-1, 0}}; NeighborhoodIteratorType::OffsetType offset4 = {{1, 0}}; NeighborhoodIteratorType::OffsetType offset5 = {{-1, 1}}; NeighborhoodIteratorType::OffsetType offset6 = {{1, 1}}; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// It is equivalent to use the six corresponding integer array indices instead. -// For example, the offsets \code{(-1, -1)} and \code{(1, -1)} are -// equivalent to the integer indices \code{0} and \code{2}, respectively. -// -// The calculations are done in a \code{for} loop that moves the input and -// output iterators synchronously across their respective images. The -// \code{sum} variable is used to sum the results of the finite differences. -// -// Software Guide : EndLatex + // It is equivalent to use the six corresponding integer array indices instead. + // For example, the offsets \code{(-1, -1)} and \code{(1, -1)} are + // equivalent to the integer indices \code{0} and \code{2}, respectively. + // + // The calculations are done in a \code{for} loop that moves the input and + // output iterators synchronously across their respective images. The + // \code{sum} variable is used to sum the results of the finite differences. -// Software Guide : BeginCodeSnippet for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { float sum; sum = it.GetPixel(offset2) - it.GetPixel(offset1); sum += 2.0 * it.GetPixel(offset4) - 2.0 * it.GetPixel(offset3); sum += it.GetPixel(offset6) - it.GetPixel(offset5); out.Set(sum); - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// The last step is to write the output buffer to an image file. Writing is -// done inside a \code{try/catch} block to handle any exceptions. The output -// is rescaled to intensity range $[0, 255]$ and cast to unsigned char so that -// it can be saved and visualized as a PNG image. -// -// Software Guide : EndLatex + // The last step is to write the output buffer to an image file. Writing is + // done inside a \code{try/catch} block to handle any exceptions. The output + // is rescaled to intensity range $[0, 255]$ and cast to unsigned char so that + // it can be saved and visualized as a PNG image. -// Software Guide : BeginCodeSnippet typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter< - ImageType, WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -221,31 +170,26 @@ int main(int argc, char *argv[]) writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The center image of Figure~\ref{fig:NeighborhoodExamples1} shows the -// output of the Sobel algorithm applied to -// \code{Examples/Data/ROI\_QB\_PAN\_1.tif}. -// -// \begin{figure} \centering -// \includegraphics[width=0.45\textwidth]{ROI_QB_PAN_1.eps} -// \includegraphics[width=0.45\textwidth]{NeighborhoodIterators1a.eps} -// \itkcaption[Sobel edge detection results]{Applying the Sobel operator to an image (left) produces $x$ (right) derivative image.} -// \protect\label{fig:NeighborhoodExamples1} -// \end{figure} -// -// Software Guide : EndLatex + } + + // The center image of Figure~\ref{fig:NeighborhoodExamples1} shows the + // output of the Sobel algorithm applied to + // \code{Examples/Data/ROI\_QB\_PAN\_1.tif}. + // + // \begin{figure} \centering + // \includegraphics[width=0.45\textwidth]{ROI_QB_PAN_1.eps} + // \includegraphics[width=0.45\textwidth]{NeighborhoodIterators1a.eps} + // \itkcaption[Sobel edge detection results]{Applying the Sobel operator to an image (left) produces $x$ (right) derivative image.} + // \protect\label{fig:NeighborhoodExamples1} + // \end{figure} return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators2.cxx b/Examples/Iterators/NeighborhoodIterators2.cxx index 4558016e1fdcc7514af9a7f7aadab06c0e9f35ce..e7833381e52f02ade97d40adcccf957f9c7eec2e 100644 --- a/Examples/Iterators/NeighborhoodIterators2.cxx +++ b/Examples/Iterators/NeighborhoodIterators2.cxx @@ -27,8 +27,6 @@ #include "itkConstNeighborhoodIterator.h" #include "itkImageRegionIterator.h" -// Software Guide : BeginLatex -// // In this example, the Sobel edge-detection routine is rewritten using // convolution filtering. Convolution filtering is a standard image processing // technique that can be implemented numerically as the inner product of all @@ -51,25 +49,19 @@ // // We start writing this example by including the header files for the Sobel // kernel and the inner product function. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkSobelOperator.h" #include "itkNeighborhoodInnerProduct.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile direction" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile direction" << std::endl; return -1; - } + } typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; @@ -81,15 +73,15 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); @@ -97,77 +89,52 @@ int main(int argc, char * argv[]) IteratorType out(output, reader->GetOutput()->GetRequestedRegion()); -// Software Guide : BeginLatex -// -// \index{convolution!kernels} -// \index{convolution!operators} -// \index{iterators!neighborhood!and convolution} -// -// Refer to the previous example for a description of reading the input image and -// setting up the output image and iterator. -// -// The following code creates a Sobel operator. The Sobel operator requires -// a direction for its partial derivatives. This direction is read from the command line. -// Changing the direction of the derivatives changes the bias of the edge -// detection, i.e. maximally vertical or maximally horizontal. -// -// Software Guide : EndLatex + // \index{convolution!kernels} + // \index{convolution!operators} + // \index{iterators!neighborhood!and convolution} + // + // Refer to the previous example for a description of reading the input image and + // setting up the output image and iterator. + // + // The following code creates a Sobel operator. The Sobel operator requires + // a direction for its partial derivatives. This direction is read from the command line. + // Changing the direction of the derivatives changes the bias of the edge + // detection, i.e. maximally vertical or maximally horizontal. -// Software Guide : BeginCodeSnippet itk::SobelOperator<PixelType, 2> sobelOperator; sobelOperator.SetDirection(::atoi(argv[3])); sobelOperator.CreateDirectional(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The neighborhood iterator is initialized as before, except that now it takes -// its radius directly from the radius of the Sobel operator. The inner -// product function object is templated over image type and requires no -// initialization. -// -// Software Guide : EndLatex + // The neighborhood iterator is initialized as before, except that now it takes + // its radius directly from the radius of the Sobel operator. The inner + // product function object is templated over image type and requires no + // initialization. -// Software Guide : BeginCodeSnippet NeighborhoodIteratorType::RadiusType radius = sobelOperator.GetRadius(); - NeighborhoodIteratorType it(radius, reader->GetOutput(), - reader->GetOutput()-> - GetRequestedRegion()); + NeighborhoodIteratorType it(radius, reader->GetOutput(), reader->GetOutput()->GetRequestedRegion()); itk::NeighborhoodInnerProduct<ImageType> innerProduct; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Using the Sobel operator, inner product, and neighborhood iterator objects, -// we can now write a very simple \code{for} loop for performing convolution -// filtering. As before, out-of-bounds pixel values are supplied automatically -// by the iterator. -// -// Software Guide : EndLatex + // Using the Sobel operator, inner product, and neighborhood iterator objects, + // we can now write a very simple \code{for} loop for performing convolution + // filtering. As before, out-of-bounds pixel values are supplied automatically + // by the iterator. -// Software Guide : BeginCodeSnippet for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { out.Set(innerProduct(it, sobelOperator)); - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// The output is rescaled and written as in the previous example. Applying -// this example in the $x$ and $y$ directions produces the images at the center -// and right of Figure~\ref{fig:NeighborhoodExamples1}. Note that x-direction -// operator produces the same output image as in the previous example. -// -// Software Guide : EndLatex + // The output is rescaled and written as in the previous example. Applying + // this example in the $x$ and $y$ directions produces the images at the center + // and right of Figure~\ref{fig:NeighborhoodExamples1}. Note that x-direction + // operator produces the same output image as in the previous example. typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter< - ImageType, WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -179,15 +146,15 @@ int main(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators3.cxx b/Examples/Iterators/NeighborhoodIterators3.cxx index d34a300ce88b4efb69190679082b9782c679ec29..564097cfc64a47768991058b9f709fed476dd609 100644 --- a/Examples/Iterators/NeighborhoodIterators3.cxx +++ b/Examples/Iterators/NeighborhoodIterators3.cxx @@ -27,8 +27,6 @@ #include "itkConstNeighborhoodIterator.h" #include "itkImageRegionIterator.h" -// Software Guide : BeginLatex -// // This example illustrates a technique for improving the efficiency of // neighborhood calculations by eliminating unnecessary bounds checking. As // described in Section~\ref{sec:NeighborhoodIterators}, the neighborhood @@ -53,27 +51,21 @@ // // The face calculator object is defined in \code{itkNeighborhoodAlgorithm.h}. // We include this file in addition to those from the previous two examples. -// -// Software Guide : EndLatex #include "itkSobelOperator.h" #include "itkNeighborhoodInnerProduct.h" -// Software Guide : BeginCodeSnippet #include "itkNeighborhoodAlgorithm.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile direction" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile direction" << std::endl; return -1; - } + } typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; @@ -85,15 +77,15 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); @@ -105,107 +97,75 @@ int main(int argc, char * argv[]) itk::NeighborhoodInnerProduct<ImageType> innerProduct; -// Software Guide : BeginLatex -// -// First we load the input image and create the output image and inner product -// function as in the previous examples. The image iterators will be created -// in a later step. Next we create a face calculator object. An empty list is -// created to hold the regions that will later on be returned by the face -// calculator. -// -// Software Guide : EndLatex + // First we load the input image and create the output image and inner product + // function as in the previous examples. The image iterators will be created + // in a later step. Next we create a face calculator object. An empty list is + // created to hold the regions that will later on be returned by the face + // calculator. -// Software Guide : BeginCodeSnippet - typedef itk::NeighborhoodAlgorithm - ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; + typedef itk::NeighborhoodAlgorithm ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; FaceCalculatorType faceCalculator; FaceCalculatorType::FaceListType faceList; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The face calculator function is invoked by passing it an image pointer, an -// image region, and a neighborhood radius. The image pointer is the same -// image used to initialize the neighborhood iterator, and the image region is -// the region that the algorithm is going to process. The radius is the radius -// of the iterator. -// -// Notice that in this case the image region is given as the region of the -// \emph{output} image and the image pointer is given as that of the -// \emph{input} image. This is important if the input and output images differ -// in size, i.e. the input image is larger than the output image. ITK -// and OTB image -// filters, for example, operate on data from the input image but only generate -// results in the \code{RequestedRegion} of the output image, which may be -// smaller than the full extent of the input. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - faceList = faceCalculator(reader->GetOutput(), output->GetRequestedRegion(), - sobelOperator.GetRadius()); -// Software Guide : EndCodeSnippet + // The face calculator function is invoked by passing it an image pointer, an + // image region, and a neighborhood radius. The image pointer is the same + // image used to initialize the neighborhood iterator, and the image region is + // the region that the algorithm is going to process. The radius is the radius + // of the iterator. + // + // Notice that in this case the image region is given as the region of the + // \emph{output} image and the image pointer is given as that of the + // \emph{input} image. This is important if the input and output images differ + // in size, i.e. the input image is larger than the output image. ITK + // and OTB image + // filters, for example, operate on data from the input image but only generate + // results in the \code{RequestedRegion} of the output image, which may be + // smaller than the full extent of the input. + + faceList = faceCalculator(reader->GetOutput(), output->GetRequestedRegion(), sobelOperator.GetRadius()); + + // The face calculator has returned a list of $2N+1$ regions. The first element + // in the list is always the inner region, which may or may not be important + // depending on the application. For our purposes it does not matter because + // all regions are processed the same way. We use an iterator to traverse the + // list of faces. -// Software Guide : BeginLatex -// -// The face calculator has returned a list of $2N+1$ regions. The first element -// in the list is always the inner region, which may or may not be important -// depending on the application. For our purposes it does not matter because -// all regions are processed the same way. We use an iterator to traverse the -// list of faces. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet FaceCalculatorType::FaceListType::iterator fit; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We now rewrite the main loop of the previous example so that each region in the -// list is processed by a separate iterator. The iterators \code{it} and -// \code{out} are reinitialized over each region in turn. Bounds checking is -// automatically enabled for those regions that require it, and disabled for -// the region that does not. -// -// Software Guide : EndLatex + // We now rewrite the main loop of the previous example so that each region in the + // list is processed by a separate iterator. The iterators \code{it} and + // \code{out} are reinitialized over each region in turn. Bounds checking is + // automatically enabled for those regions that require it, and disabled for + // the region that does not. -// Software Guide : BeginCodeSnippet IteratorType out; NeighborhoodIteratorType it; for (fit = faceList.begin(); fit != faceList.end(); ++fit) - { - it = NeighborhoodIteratorType(sobelOperator.GetRadius(), - reader->GetOutput(), *fit); + { + it = NeighborhoodIteratorType(sobelOperator.GetRadius(), reader->GetOutput(), *fit); out = IteratorType(output, *fit); for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { out.Set(innerProduct(it, sobelOperator)); - } } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// The output is written as before. Results for this example are the same as -// the previous example. You may not notice the speedup except on larger -// images. When moving to 3D and higher dimensions, the effects are greater -// because the volume to surface area ratio is usually larger. In other -// words, as the number of interior pixels increases relative to the number of -// face pixels, there is a corresponding increase in efficiency from disabling -// bounds checking on interior pixels. -// -// Software Guide : EndLatex + // The output is written as before. Results for this example are the same as + // the previous example. You may not notice the speedup except on larger + // images. When moving to 3D and higher dimensions, the effects are greater + // because the volume to surface area ratio is usually larger. In other + // words, as the number of interior pixels increases relative to the number of + // face pixels, there is a corresponding increase in efficiency from disabling + // bounds checking on interior pixels. typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter< - ImageType, WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -217,15 +177,15 @@ int main(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators4.cxx b/Examples/Iterators/NeighborhoodIterators4.cxx index 64388fdc5c20f0b5792ae7fa1bec3c7b08b14062..828a96fc9ff129984accb30bdc86f4300b807243 100644 --- a/Examples/Iterators/NeighborhoodIterators4.cxx +++ b/Examples/Iterators/NeighborhoodIterators4.cxx @@ -19,26 +19,22 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {NeighborhoodIterators4a.png} -// 0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {NeighborhoodIterators4b.png} -// 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {NeighborhoodIterators4c.png} -// 2 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {NeighborhoodIterators4d.png} -// 5 -// Software Guide : EndCommandLineArgs +/* Example usage: +./NeighborhoodIterators4 Input/QB_Suburb.png Output/NeighborhoodIterators4a.png 0 +*/ + +/* Example usage: +./NeighborhoodIterators4 Input/QB_Suburb.png Output/NeighborhoodIterators4b.png 1 +*/ + +/* Example usage: +./NeighborhoodIterators4 Input/QB_Suburb.png Output/NeighborhoodIterators4c.png 2 +*/ + +/* Example usage: +./NeighborhoodIterators4 Input/QB_Suburb.png Output/NeighborhoodIterators4d.png 5 +*/ + #include "otbImage.h" #include "otbImageFileReader.h" @@ -50,8 +46,6 @@ #include "itkNeighborhoodAlgorithm.h" #include "itkNeighborhoodInnerProduct.h" -// Software Guide : BeginLatex -// // We now introduce a variation on convolution filtering that is useful when a // convolution kernel is separable. In this example, we create a different // neighborhood iterator for each axial direction of the image and then take @@ -62,23 +56,18 @@ // in calculations becomes large. // // The only new class necessary for this example is the Gaussian operator. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkGaussianOperator.h" -// Software Guide : EndCodeSnippet -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile sigma" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile sigma" << std::endl; return -1; - } + } typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; @@ -90,15 +79,15 @@ int main(int argc, char *argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); @@ -106,8 +95,7 @@ int main(int argc, char *argv[]) itk::NeighborhoodInnerProduct<ImageType> innerProduct; - typedef itk::NeighborhoodAlgorithm - ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; + typedef itk::NeighborhoodAlgorithm ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; FaceCalculatorType faceCalculator; FaceCalculatorType::FaceListType faceList; @@ -116,97 +104,80 @@ int main(int argc, char *argv[]) IteratorType out; NeighborhoodIteratorType it; -// Software Guide : BeginLatex -// The Gaussian operator, like the Sobel operator, is instantiated with a pixel -// type and a dimensionality. Additionally, we set the variance of the -// Gaussian, which has been read from the command line as standard deviation. -// Software Guide : EndLatex + // The Gaussian operator, like the Sobel operator, is instantiated with a pixel + // type and a dimensionality. Additionally, we set the variance of the + // Gaussian, which has been read from the command line as standard deviation. -// Software Guide : BeginCodeSnippet itk::GaussianOperator<PixelType, 2> gaussianOperator; gaussianOperator.SetVariance(::atof(argv[3]) * ::atof(argv[3])); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The only further changes from the previous example are in the main loop. -// Once again we use the results from face calculator to construct a loop that -// processes boundary and non-boundary image regions separately. Separable -// convolution, however, requires an additional, outer loop over all the image -// dimensions. The direction of the Gaussian operator is reset at each -// iteration of the outer loop using the new dimension. The iterators change -// direction to match because they are initialized with the radius of the -// Gaussian operator. -// -// Input and output buffers are swapped at each iteration so that the output of -// the previous iteration becomes the input for the current iteration. The swap -// is not performed on the last iteration. -// -// Software Guide : EndLatex + // The only further changes from the previous example are in the main loop. + // Once again we use the results from face calculator to construct a loop that + // processes boundary and non-boundary image regions separately. Separable + // convolution, however, requires an additional, outer loop over all the image + // dimensions. The direction of the Gaussian operator is reset at each + // iteration of the outer loop using the new dimension. The iterators change + // direction to match because they are initialized with the radius of the + // Gaussian operator. + // + // Input and output buffers are swapped at each iteration so that the output of + // the previous iteration becomes the input for the current iteration. The swap + // is not performed on the last iteration. -// Software Guide : BeginCodeSnippet ImageType::Pointer input = reader->GetOutput(); for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) - { + { gaussianOperator.SetDirection(i); gaussianOperator.CreateDirectional(); - faceList = faceCalculator(input, output->GetRequestedRegion(), - gaussianOperator.GetRadius()); + faceList = faceCalculator(input, output->GetRequestedRegion(), gaussianOperator.GetRadius()); for (fit = faceList.begin(); fit != faceList.end(); ++fit) - { - it = NeighborhoodIteratorType(gaussianOperator.GetRadius(), - input, *fit); + { + it = NeighborhoodIteratorType(gaussianOperator.GetRadius(), input, *fit); out = IteratorType(output, *fit); for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { out.Set(innerProduct(it, gaussianOperator)); - } } + } // Swap the input and output buffers if (i != ImageType::ImageDimension - 1) - { + { ImageType::Pointer tmp = input; - input = output; - output = tmp; - } + input = output; + output = tmp; } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The output is rescaled and written as in the previous examples. -// Figure~\ref{fig:NeighborhoodExample4} shows the results of Gaussian blurring -// the image \code{Examples/Data/QB\_Suburb.png} using increasing -// kernel widths. -// -// \begin{figure} -// \centering -// \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4a.eps} -// \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4b.eps} -// \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4c.eps} -// \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4d.eps} -// \itkcaption[Gaussian blurring by convolution filtering]{Results of -// convolution filtering with a Gaussian kernel of increasing standard -// deviation $\sigma$ (from left to right, $\sigma = 0$, $\sigma = 1$, $\sigma -// = 2$, $\sigma = 5$). Increased blurring reduces contrast and changes the -// average intensity value of the image, which causes the image to appear -// brighter when rescaled.} -// \protect\label{fig:NeighborhoodExample4} -// \end{figure} -// -// Software Guide : EndLatex + } + + // The output is rescaled and written as in the previous examples. + // Figure~\ref{fig:NeighborhoodExample4} shows the results of Gaussian blurring + // the image \code{Examples/Data/QB\_Suburb.png} using increasing + // kernel widths. + // + // \begin{figure} + // \centering + // \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4a.eps} + // \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4b.eps} + // \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4c.eps} + // \includegraphics[width=0.23\textwidth]{NeighborhoodIterators4d.eps} + // \itkcaption[Gaussian blurring by convolution filtering]{Results of + // convolution filtering with a Gaussian kernel of increasing standard + // deviation $\sigma$ (from left to right, $\sigma = 0$, $\sigma = 1$, $\sigma + // = 2$, $\sigma = 5$). Increased blurring reduces contrast and changes the + // average intensity value of the image, which causes the image to appear + // brighter when rescaled.} + // \protect\label{fig:NeighborhoodExample4} + // \end{figure} typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter< - ImageType, WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -218,15 +189,15 @@ int main(int argc, char *argv[]) writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators5.cxx b/Examples/Iterators/NeighborhoodIterators5.cxx index bee8f9b28010f3271bf8f9626d6122cd28abf5f4..33ea5516d22ef4f0779485da83bc5f6d6bf4af62 100644 --- a/Examples/Iterators/NeighborhoodIterators5.cxx +++ b/Examples/Iterators/NeighborhoodIterators5.cxx @@ -30,8 +30,6 @@ #include "itkGaussianOperator.h" #include "itkNeighborhoodInnerProduct.h" -// Software Guide : BeginLatex -// // This example introduces slice-based neighborhood processing. A slice, in // this context, is a 1D path through an ND neighborhood. Slices are defined // for generic arrays by the \code{std::slice} class as a start index, a step @@ -58,20 +56,16 @@ // Good examples of slice-based neighborhood processing can be found in any of // the ND anisotropic diffusion function objects, such as // \doxygen{itk}{CurvatureNDAnisotropicDiffusionFunction}. -// -// Software Guide : EndLatex -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile sigma" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile sigma" << std::endl; return -1; - } + } typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; @@ -83,15 +77,15 @@ int main(int argc, char * argv[]) ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); @@ -99,8 +93,7 @@ int main(int argc, char * argv[]) itk::NeighborhoodInnerProduct<ImageType> innerProduct; - typedef itk::NeighborhoodAlgorithm - ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; + typedef itk::NeighborhoodAlgorithm ::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; FaceCalculatorType faceCalculator; FaceCalculatorType::FaceListType faceList; @@ -109,91 +102,68 @@ int main(int argc, char * argv[]) IteratorType out; NeighborhoodIteratorType it; -// Software Guide: BeginLatex -// -// The first difference between this example and the previous example is that -// the Gaussian operator is only initialized once. Its direction is not -// important because it is only a 1D array of coefficients. -// -// Software Guide: EndLatex + // The first difference between this example and the previous example is that + // the Gaussian operator is only initialized once. Its direction is not + // important because it is only a 1D array of coefficients. -// Software Guide : BeginCodeSnippet itk::GaussianOperator<PixelType, 2> gaussianOperator; gaussianOperator.SetDirection(0); gaussianOperator.SetVariance(::atof(argv[3]) * ::atof(argv[3])); gaussianOperator.CreateDirectional(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Next we need to define a radius for the iterator. The radius in all -// directions matches that of the single extent of the Gaussian operator, -// defining a square neighborhood. -// -// Software Guide : EndLatex + // Next we need to define a radius for the iterator. The radius in all + // directions matches that of the single extent of the Gaussian operator, + // defining a square neighborhood. -// Software Guide : BeginCodeSnippet NeighborhoodIteratorType::RadiusType radius; radius.Fill(gaussianOperator.GetRadius()[0]); -// Software Guide EndCodeSnippet -// Software Guide : BeginLatex -// -// The inner product and face calculator are defined for the main processing -// loop as before, but now the iterator is reinitialized each iteration with -// the square \code{radius} instead of the radius of the operator. The -// inner product is taken using a slice along the axial direction corresponding -// to the current iteration. Note the use of \code{GetSlice()} to return the -// proper slice from the iterator itself. \code{GetSlice()} can only be used -// to return the slice along the complete extent of the axial direction of a -// neighborhood. -// -// Software Guide : EndLatex + // The inner product and face calculator are defined for the main processing + // loop as before, but now the iterator is reinitialized each iteration with + // the square \code{radius} instead of the radius of the operator. The + // inner product is taken using a slice along the axial direction corresponding + // to the current iteration. Note the use of \code{GetSlice()} to return the + // proper slice from the iterator itself. \code{GetSlice()} can only be used + // to return the slice along the complete extent of the axial direction of a + // neighborhood. -// Software Guide : BeginCodeSnippet ImageType::Pointer input = reader->GetOutput(); - faceList = faceCalculator(input, output->GetRequestedRegion(), radius); + faceList = faceCalculator(input, output->GetRequestedRegion(), radius); for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) - { + { for (fit = faceList.begin(); fit != faceList.end(); ++fit) - { - it = NeighborhoodIteratorType(radius, input, *fit); + { + it = NeighborhoodIteratorType(radius, input, *fit); out = IteratorType(output, *fit); for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { out.Set(innerProduct(it.GetSlice(i), it, gaussianOperator)); - } } + } // Swap the input and output buffers if (i != ImageType::ImageDimension - 1) - { + { ImageType::Pointer tmp = input; - input = output; - output = tmp; - } + input = output; + output = tmp; } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// This technique produces exactly the same results as the previous example. A -// little experimentation, however, will reveal that it is less efficient since -// the neighborhood iterator is keeping track of extra, unused pixel locations -// for each iteration, while the previous example only references those pixels -// that it needs. In cases, however, where an algorithm takes multiple -// derivatives or convolution products over the same neighborhood, slice-based -// processing can increase efficiency and simplify the implementation. -// -// Software Guide : EndLatex + // This technique produces exactly the same results as the previous example. A + // little experimentation, however, will reveal that it is less efficient since + // the neighborhood iterator is keeping track of extra, unused pixel locations + // for each iteration, while the previous example only references those pixels + // that it needs. In cases, however, where an algorithm takes multiple + // derivatives or convolution products over the same neighborhood, slice-based + // processing can increase efficiency and simplify the implementation. typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, - WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -205,15 +175,15 @@ int main(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/NeighborhoodIterators6.cxx b/Examples/Iterators/NeighborhoodIterators6.cxx index ba6a4d971dcdd729c9ff0124ec91c109541445e7..a2402077f75af9d4d4f3abda8f73893546eaa271 100644 --- a/Examples/Iterators/NeighborhoodIterators6.cxx +++ b/Examples/Iterators/NeighborhoodIterators6.cxx @@ -29,23 +29,21 @@ #include "itkFastMarchingImageFilter.h" #include "itkAddImageFilter.h" -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {NeighborhoodIterators6a.png} -// 100 100 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {NeighborhoodIterators6b.png} -// 50 150 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginCommandLineArgs -// OUTPUTS: {NeighborhoodIterators6c.png} -// 150 50 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// +/* Example usage: +./NeighborhoodIterators6 Output/NeighborhoodIterators6a.png 100 100 +*/ + + +/* Example usage: +./NeighborhoodIterators6 Output/NeighborhoodIterators6b.png 50 150 +*/ + + +/* Example usage: +./NeighborhoodIterators6 Output/NeighborhoodIterators6c.png 150 50 +*/ + + // Some image processing routines do not need to visit every pixel in an // image. Flood-fill and connected-component algorithms, for example, only // visit pixels that are locally connected to one another. Algorithms @@ -65,27 +63,22 @@ // neighborhood iterators, but can be found in the source code of this // example. Some noise has been added to the distance transform image for // additional interest. -// -// Software Guide : EndLatex -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " outputImageFile startX startY" - << std::endl; + std::cerr << argv[0] << " outputImageFile startX startY" << std::endl; return -1; - } + } typedef float PixelType; typedef otb::Image<PixelType, 2> ImageType; typedef itk::NeighborhoodIterator<ImageType> NeighborhoodIteratorType; - typedef itk::FastMarchingImageFilter<ImageType, - ImageType> FastMarchingFilterType; + typedef itk::FastMarchingImageFilter<ImageType, ImageType> FastMarchingFilterType; FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New(); @@ -96,8 +89,8 @@ int main(int argc, char *argv[]) ImageType::IndexType seedPosition; - seedPosition[0] = 128; - seedPosition[1] = 128; + seedPosition[0] = 128; + seedPosition[1] = 128; const double initialDistance = 1.0; NodeType node; @@ -114,11 +107,10 @@ int main(int argc, char *argv[]) fastMarching->SetTrialPoints(seeds); fastMarching->SetSpeedConstant(1.0); - itk::AddImageFilter<ImageType, ImageType, ImageType>::Pointer adder - = itk::AddImageFilter<ImageType, ImageType, ImageType>::New(); + itk::AddImageFilter<ImageType, ImageType, ImageType>::Pointer adder = itk::AddImageFilter<ImageType, ImageType, ImageType>::New(); // Allocate the noise image - ImageType::Pointer noise = ImageType::New(); + ImageType::Pointer noise = ImageType::New(); ImageType::RegionType noiseRegion; noiseRegion.SetSize(size); noise->SetRegions(noiseRegion); @@ -130,81 +122,66 @@ int main(int argc, char *argv[]) // Random number seed unsigned int sample_seed = 12345; - double u = 0.; - double rnd = 0.; - double dMin = -.7; - double dMax = .8; - - while(!itNoise.IsAtEnd()) - { - sample_seed = ( sample_seed * 16807 ) % 2147483647L; - u = static_cast< double >( sample_seed ) / 2147483711UL; - rnd = ( 1.0 - u ) * dMin + u * dMax; - - itNoise.Set( (PixelType)rnd ); + double u = 0.; + double rnd = 0.; + double dMin = -.7; + double dMax = .8; + + while (!itNoise.IsAtEnd()) + { + sample_seed = (sample_seed * 16807) % 2147483647L; + u = static_cast<double>(sample_seed) / 2147483711UL; + rnd = (1.0 - u) * dMin + u * dMax; + + itNoise.Set((PixelType)rnd); ++itNoise; - } + } adder->SetInput1(noise); adder->SetInput2(fastMarching->GetOutput()); try - { + { fastMarching->SetOutputSize(size); fastMarching->Update(); adder->Update(); - - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } ImageType::Pointer input = adder->GetOutput(); -// Software Guide : BeginLatex -// -// The variable \code{input} is the pointer to the distance transform image. -// The local minimum algorithm is initialized with a seed point read from the -// command line. -// Software Guide : EndLatex + // The variable \code{input} is the pointer to the distance transform image. + // The local minimum algorithm is initialized with a seed point read from the + // command line. -// Software Guide : BeginCodeSnippet ImageType::IndexType index; index[0] = ::atoi(argv[2]); index[1] = ::atoi(argv[3]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// Next we create the neighborhood iterator and position it at the seed point. -// Software Guide : EndLatex + // Next we create the neighborhood iterator and position it at the seed point. -// Software Guide : BeginCodeSnippet NeighborhoodIteratorType::RadiusType radius; radius.Fill(1); NeighborhoodIteratorType it(radius, input, input->GetRequestedRegion()); it.SetLocation(index); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Searching for the local minimum involves finding the minimum in the current -// neighborhood, then shifting the neighborhood in the direction of that -// minimum. The \code{for} loop below records the \doxygen{itk}{Offset} of the -// minimum neighborhood pixel. The neighborhood iterator is then moved using -// that offset. When a local minimum is detected, \code{flag} will remain -// false and the \code{while} loop will exit. Note that this code is -// valid for an image of any dimensionality. -// -// Software Guide : EndLatex + // Searching for the local minimum involves finding the minimum in the current + // neighborhood, then shifting the neighborhood in the direction of that + // minimum. The \code{for} loop below records the \doxygen{itk}{Offset} of the + // minimum neighborhood pixel. The neighborhood iterator is then moved using + // that offset. When a local minimum is detected, \code{flag} will remain + // false and the \code{while} loop will exit. Note that this code is + // valid for an image of any dimensionality. -// Software Guide : BeginCodeSnippet bool flag = true; while (flag == true) - { + { NeighborhoodIteratorType::OffsetType nextMove; nextMove.Fill(0); @@ -212,45 +189,39 @@ int main(int argc, char *argv[]) PixelType min = it.GetCenterPixel(); for (unsigned i = 0; i < it.Size(); ++i) - { + { if (it.GetPixel(i) < min) - { - min = it.GetPixel(i); + { + min = it.GetPixel(i); nextMove = it.GetOffset(i); - flag = true; - } + flag = true; } + } it.SetCenterPixel(255.0); it += nextMove; - } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// Figure~\ref{fig:NeighborhoodExample6} shows the results of the algorithm -// for several seed points. The white line is the path of the iterator from -// the seed point to the minimum in the center of the image. The effect of the -// additive noise is visible as the small perturbations in the paths. -// -// \begin{figure} \centering -// \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6a.eps} -// \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6b.eps} -// \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6c.eps} -// \itkcaption[Finding local minima]{Paths traversed by the neighborhood -// iterator from different seed points to the local minimum. -// The true minimum is at the center -// of the image. The path of the iterator is shown in white. The effect of -// noise in the image is seen as small perturbations in each path. } -// \protect\label{fig:NeighborhoodExample6} \end{figure} -// -// Software Guide : EndLatex + } + + // Figure~\ref{fig:NeighborhoodExample6} shows the results of the algorithm + // for several seed points. The white line is the path of the iterator from + // the seed point to the minimum in the center of the image. The effect of the + // additive noise is visible as the small perturbations in the paths. + // + // \begin{figure} \centering + // \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6a.eps} + // \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6b.eps} + // \includegraphics[width=0.3\textwidth]{NeighborhoodIterators6c.eps} + // \itkcaption[Finding local minima]{Paths traversed by the neighborhood + // iterator from different seed points to the local minimum. + // The true minimum is at the center + // of the image. The path of the iterator is shown in white. The effect of + // noise in the image is seen as small perturbations in each path. } + // \protect\label{fig:NeighborhoodExample6} \end{figure} typedef unsigned char WritePixelType; typedef otb::Image<WritePixelType, 2> WriteImageType; typedef otb::ImageFileWriter<WriteImageType> WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, - WriteImageType> RescaleFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, WriteImageType> RescaleFilterType; RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); @@ -262,14 +233,14 @@ int main(int argc, char *argv[]) writer->SetFileName(argv[1]); writer->SetInput(rescaler->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ShapedNeighborhoodIterators1.cxx b/Examples/Iterators/ShapedNeighborhoodIterators1.cxx index 96c2fa1f16b457165712b2d189cf498af7e34c36..cfc75e48ed4e9b4011133444782b6783e78065be 100644 --- a/Examples/Iterators/ShapedNeighborhoodIterators1.cxx +++ b/Examples/Iterators/ShapedNeighborhoodIterators1.cxx @@ -25,8 +25,6 @@ #include "itkNeighborhoodAlgorithm.h" #include <math.h> -// Software Guide : BeginLatex -// // This example uses \doxygen{itk}{ShapedNeighborhoodIterator} to implement a binary // erosion algorithm. If we think of an image $I$ as a set of pixel indices, // then erosion of $I$ by a smaller set $E$, called the \emph{structuring @@ -41,136 +39,96 @@ // // We need two iterators, a shaped iterator for the input image and a regular // image iterator for writing results to the output image. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "itkConstShapedNeighborhoodIterator.h" #include "itkImageRegionIterator.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile element_radius" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile element_radius" << std::endl; return -1; - } + } - // Software Guide : BeginLatex - // // Since we are working with binary images in this example, an \code{unsigned // char} pixel type will do. The image and iterator types are defined using // the pixel type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned char PixelType; typedef otb::Image<PixelType, 2> ImageType; - typedef itk::ConstShapedNeighborhoodIterator< - ImageType - > ShapedNeighborhoodIteratorType; + typedef itk::ConstShapedNeighborhoodIterator<ImageType> ShapedNeighborhoodIteratorType; typedef itk::ImageRegionIterator<ImageType> IteratorType; - // Software Guide : EndCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); output->Allocate(); -// Software Guide : BeginLatex -// -// Refer to the examples in Section~\ref{sec:itkNeighborhoodIterator} or the -// source code of this example for a description of how to read the input image -// and allocate a matching output image. -// -// The size of the structuring element is read from the command line and used -// to define a radius for the shaped neighborhood iterator. Using the method -// developed in section~\ref{sec:itkNeighborhoodIterator} to minimize bounds -// checking, the iterator itself is not initialized until entering the -// main processing loop. -// -// Software Guide : EndLatex + // Refer to the examples in Section~\ref{sec:itkNeighborhoodIterator} or the + // source code of this example for a description of how to read the input image + // and allocate a matching output image. + // + // The size of the structuring element is read from the command line and used + // to define a radius for the shaped neighborhood iterator. Using the method + // developed in section~\ref{sec:itkNeighborhoodIterator} to minimize bounds + // checking, the iterator itself is not initialized until entering the + // main processing loop. -// Software Guide : BeginCodeSnippet unsigned int element_radius = ::atoi(argv[3]); ShapedNeighborhoodIteratorType::RadiusType radius; radius.Fill(element_radius); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The face calculator object introduced in -// Section~\ref{sec:NeighborhoodExample3} is created and used as before. -// -// Software Guide : EndLatex + // The face calculator object introduced in + // Section~\ref{sec:NeighborhoodExample3} is created and used as before. -// Software Guide : BeginCodeSnippet - typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< - ImageType> FaceCalculatorType; + typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; FaceCalculatorType faceCalculator; FaceCalculatorType::FaceListType faceList; FaceCalculatorType::FaceListType::iterator fit; - faceList = faceCalculator(reader->GetOutput(), - output->GetRequestedRegion(), - radius); -// Software Guide : EndCodeSnippet + faceList = faceCalculator(reader->GetOutput(), output->GetRequestedRegion(), radius); -// Software Guide : BeginLatex -// -// Now we initialize some variables and constants. -// -// Software Guide : EndLatex + // Now we initialize some variables and constants. -// Software Guide : BeginCodeSnippet IteratorType out; const PixelType background_value = 0; const PixelType foreground_value = 255; - const float rad = static_cast<float>(element_radius); -// Software Guide : EndCodeSnippet + const float rad = static_cast<float>(element_radius); -// Software Guide : BeginLatex -// -// The outer loop of the algorithm is structured as in previous neighborhood -// iterator examples. Each region in the face list is processed in turn. As each new -// region is processed, the input and output iterators are initialized on that -// region. -// -// The shaped iterator that ranges over the input is our structuring element -// and its active stencil must be created accordingly. For this example, the -// structuring element is shaped like a circle of radius -// \code{element\_radius}. Each of the appropriate neighborhood offsets is -// activated in the double \code{for} loop. -// -// Software Guide : EndLatex + // The outer loop of the algorithm is structured as in previous neighborhood + // iterator examples. Each region in the face list is processed in turn. As each new + // region is processed, the input and output iterators are initialized on that + // region. + // + // The shaped iterator that ranges over the input is our structuring element + // and its active stencil must be created accordingly. For this example, the + // structuring element is shaped like a circle of radius + // \code{element\_radius}. Each of the appropriate neighborhood offsets is + // activated in the double \code{for} loop. -// Software Guide : BeginCodeSnippet for (fit = faceList.begin(); fit != faceList.end(); ++fit) - { + { ShapedNeighborhoodIteratorType it(radius, reader->GetOutput(), *fit); out = IteratorType(output, *fit); @@ -178,59 +136,52 @@ int main(int argc, char * argv[]) // than radius distance from the center of the neighborhood. for (float y = -rad; y <= rad; y++) - { + { for (float x = -rad; x <= rad; x++) - { + { ShapedNeighborhoodIteratorType::OffsetType off; float dis = ::sqrt(x * x + y * y); if (dis <= rad) - { + { off[0] = static_cast<int>(x); off[1] = static_cast<int>(y); it.ActivateOffset(off); - } } } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// The inner loop, which implements the erosion algorithm, is fairly simple. -// The \code{for} loop steps the input and output iterators through their -// respective images. At each step, the active stencil of the shaped iterator -// is traversed to determine whether all pixels underneath the stencil contain -// the foreground value, i.e. are contained within the set $I$. Note the use -// of the stencil iterator, \code{ci}, in performing this check. -// -// Software Guide : EndLatex + // The inner loop, which implements the erosion algorithm, is fairly simple. + // The \code{for} loop steps the input and output iterators through their + // respective images. At each step, the active stencil of the shaped iterator + // is traversed to determine whether all pixels underneath the stencil contain + // the foreground value, i.e. are contained within the set $I$. Note the use + // of the stencil iterator, \code{ci}, in performing this check. -// Software Guide : BeginCodeSnippet // Implements erosion for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { ShapedNeighborhoodIteratorType::ConstIterator ci; bool flag = true; for (ci = it.Begin(); ci != it.End(); ci++) - { + { if (ci.Get() == background_value) - { + { flag = false; break; - } } + } if (flag == true) - { + { out.Set(foreground_value); - } + } else - { + { out.Set(background_value); - } } } -// Software Guide : EndCodeSnippet + } typedef otb::ImageFileWriter<ImageType> WriterType; @@ -238,15 +189,15 @@ int main(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->SetInput(output); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Iterators/ShapedNeighborhoodIterators2.cxx b/Examples/Iterators/ShapedNeighborhoodIterators2.cxx index 03283fbb60381978d4d282d8dc02025b070a8403..ba78734d54349106db389b52fc5bae6b90510349 100644 --- a/Examples/Iterators/ShapedNeighborhoodIterators2.cxx +++ b/Examples/Iterators/ShapedNeighborhoodIterators2.cxx @@ -19,11 +19,11 @@ */ -// SoftwareGuide : BeginCommandLineArgs -// INPUTS: {BinaryImage.png} -// OUTPUTS: {ShapedNeighborhoodIterators1b.png} -// 4 -// SoftwareGuide : EndCommandLineArgs +/* Example usage: +./ShapedNeighborhoodIterators2 Input/BinaryImage.png \ + Output/ShapedNeighborhoodIterators1b.png \ + 4 +*/ #include "otbImage.h" #include "otbImageFileReader.h" @@ -33,25 +33,22 @@ #include "itkNeighborhoodAlgorithm.h" #include <math.h> -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 4) - { + { std::cerr << "Missing parameters. " << std::endl; std::cerr << "Usage: " << std::endl; - std::cerr << argv[0] - << " inputImageFile outputImageFile element_radius" - << std::endl; + std::cerr << argv[0] << " inputImageFile outputImageFile element_radius" << std::endl; return -1; - } + } typedef unsigned char PixelType; typedef otb::Image<PixelType, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; - typedef itk::ConstShapedNeighborhoodIterator<ImageType> - ShapedNeighborhoodIteratorType; - typedef itk::ImageRegionIterator<ImageType> IteratorType; + typedef itk::ConstShapedNeighborhoodIterator<ImageType> ShapedNeighborhoodIteratorType; + typedef itk::ImageRegionIterator<ImageType> IteratorType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); @@ -59,22 +56,21 @@ int main(int argc, char *argv[]) unsigned int element_radius = ::atoi(argv[3]); try - { + { reader->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } ImageType::Pointer output = ImageType::New(); output->SetRegions(reader->GetOutput()->GetRequestedRegion()); output->Allocate(); - typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<ImageType> - FaceCalculatorType; + typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<ImageType> FaceCalculatorType; FaceCalculatorType faceCalculator; FaceCalculatorType::FaceListType faceList; @@ -83,8 +79,7 @@ int main(int argc, char *argv[]) ShapedNeighborhoodIteratorType::RadiusType radius; radius.Fill(element_radius); - faceList = faceCalculator(reader->GetOutput(), - output->GetRequestedRegion(), radius); + faceList = faceCalculator(reader->GetOutput(), output->GetRequestedRegion(), radius); IteratorType out; const float rad = static_cast<float>(element_radius); @@ -93,84 +88,74 @@ int main(int argc, char *argv[]) const PixelType foreground_value = 255; for (fit = faceList.begin(); fit != faceList.end(); ++fit) - { + { ShapedNeighborhoodIteratorType it(radius, reader->GetOutput(), *fit); out = IteratorType(output, *fit); // Creates a circular structuring element by activating all the pixels less // than radius distance from the center of the neighborhood. for (float y = -rad; y <= rad; y++) - { + { for (float x = -rad; x <= rad; x++) - { + { ShapedNeighborhoodIteratorType::OffsetType off; float dis = ::sqrt(x * x + y * y); if (dis <= rad) - { + { off[0] = static_cast<int>(x); off[1] = static_cast<int>(y); it.ActivateOffset(off); - } } } + } -// Software Guide : BeginLatex -// -// The logic of the inner loop can be rewritten to perform -// dilation. Dilation of the set $I$ by $E$ is the set of all $x$ such that -// $E$ positioned at $x$ contains at least one element in $I$. -// -// Software Guide : EndLatex + // The logic of the inner loop can be rewritten to perform + // dilation. Dilation of the set $I$ by $E$ is the set of all $x$ such that + // $E$ positioned at $x$ contains at least one element in $I$. -// Software Guide : BeginCodeSnippet // Implements dilation for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out) - { + { ShapedNeighborhoodIteratorType::ConstIterator ci; bool flag = false; for (ci = it.Begin(); ci != it.End(); ci++) - { + { if (ci.Get() != background_value) - { + { flag = true; break; - } } + } if (flag == true) - { + { out.Set(foreground_value); - } + } else - { + { out.Set(background_value); - } } } -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The output image is written and visualized directly as a binary image of -// \code{unsigned chars}. Figure~\ref{fig:ShapedNeighborhoodExample2} -// illustrates the results of dilation on the image -// \code{Examples/Data/BinaryImage.png}. Applying erosion and dilation -// in sequence effects the morphological operations of opening and closing. -// -// \begin{figure} \centering -// \includegraphics[width=0.18\textwidth]{BinaryImage.eps} -// %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1a.eps} -// \includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1b.eps} -// %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1c.eps} -// %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1d.eps} -// \itkcaption[Binary image morphology]{The effects of morphological operations -// on a binary image using a circular structuring element of size 4. -// Left: original image. Right: dilation.} -// \protect\label{fig:ShapedNeighborhoodExample2} -// \end{figure} -// -// Software Guide : EndLatex + } + + // The output image is written and visualized directly as a binary image of + // \code{unsigned chars}. Figure~\ref{fig:ShapedNeighborhoodExample2} + // illustrates the results of dilation on the image + // \code{Examples/Data/BinaryImage.png}. Applying erosion and dilation + // in sequence effects the morphological operations of opening and closing. + // + // \begin{figure} \centering + // \includegraphics[width=0.18\textwidth]{BinaryImage.eps} + // %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1a.eps} + // \includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1b.eps} + // %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1c.eps} + // %\includegraphics[width=0.18\textwidth]{ShapedNeighborhoodIterators1d.eps} + // \itkcaption[Binary image morphology]{The effects of morphological operations + // on a binary image using a circular structuring element of size 4. + // Left: original image. Right: dilation.} + // \protect\label{fig:ShapedNeighborhoodExample2} + // \end{figure} typedef otb::ImageFileWriter<ImageType> WriterType; @@ -178,15 +163,15 @@ int main(int argc, char *argv[]) writer->SetFileName(argv[2]); writer->SetInput(output); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; return -1; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Learning/GenerateTrainingImageExample.cxx b/Examples/Learning/GenerateTrainingImageExample.cxx index 60e0355d9dee0d9011996ac3c177dcbbbc81b315..c195330765eafa017e470f68e6b6e954668b0778 100644 --- a/Examples/Learning/GenerateTrainingImageExample.cxx +++ b/Examples/Learning/GenerateTrainingImageExample.cxx @@ -19,18 +19,13 @@ */ +/* Example usage: +./GenerateTrainingImageExample Input/ROI_QB_MUL_4.tif Input/LearningROIs.txt Output/ROI_QB_MUL_4_training.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_4.tif}, {LearningROIs.txt} -// OUTPUTS: {ROI_QB_MUL_4_training.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates how to generate a training image for an // image supervised classification. -// -// Software Guide : EndLatex #include "itkNumericTraits.h" #include "otbImage.h" @@ -42,27 +37,25 @@ #include <iostream> #include <fstream> -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { - std::cout << "Usage : " << argv[0] << - " inputImage roiFile outputTrainingImage" << std::endl; + std::cout << "Usage : " << argv[0] << " inputImage roiFile outputTrainingImage" << std::endl; return EXIT_FAILURE; + } - } - - const char * imageFilename = argv[1]; - const char * roiFilename = argv[2]; - const char * outputFilename = argv[3]; + const char* imageFilename = argv[1]; + const char* roiFilename = argv[2]; + const char* outputFilename = argv[3]; typedef unsigned char InputPixelType; typedef unsigned char OutputPixelType; const unsigned int Dimension = 2; - typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; @@ -123,7 +116,7 @@ int main(int argc, char *argv[]) std::cout << "Nb of ROIS " << int(nbRois) << std::endl; while (!roisFile.fail() && (nbRois > 0)) - { + { --nbRois; OutputPixelType label = 0; @@ -146,31 +139,29 @@ int main(int argc, char *argv[]) start[0] = xUL; start[1] = yUL; - size[0] = xBR - xUL; - size[1] = yBR - yUL; + size[0] = xBR - xUL; + size[1] = yBR - yUL; region.SetSize(size); region.SetIndex(start); // Iterator creation typedef itk::ImageRegionIterator<OutputImageType> IteratorType; - IteratorType it(trainingImage, region); + IteratorType it(trainingImage, region); it.GoToBegin(); // Iteration and pixel value assignment while (!it.IsAtEnd()) - { + { it.Set(static_cast<OutputPixelType>(label)); - //std::cout << (int)static_cast<OutputPixelType>(label) << " -- "; - //std::cout << (int)it.Get() << std::endl; + // std::cout << (int)static_cast<OutputPixelType>(label) << " -- "; + // std::cout << (int)it.Get() << std::endl; ++it; - - } - } + } writer->SetInput(trainingImage); diff --git a/Examples/Learning/SEMModelEstimatorExample.cxx b/Examples/Learning/SEMModelEstimatorExample.cxx index 8953cd0a7dc2cbbea3ad681f6762038051b655a6..d6113347484b00ccc0e3c093221e8eb08d159090 100644 --- a/Examples/Learning/SEMModelEstimatorExample.cxx +++ b/Examples/Learning/SEMModelEstimatorExample.cxx @@ -20,13 +20,10 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_4.tif} -// OUTPUTS: {SEMClassif.png} -// 4 40 5 -// Software Guide : EndCommandLineArgs -// -// Software Guide : BeginLatex +/* Example usage: +./SEMModelEstimatorExample Input/ROI_QB_MUL_4.tif Output/SEMClassif.png 4 40 5 +*/ + // // In this example, we present OTB's implementation of SEM, through the class // \doxygen{otb}{SEMClassifier}. This class performs a stochastic version @@ -37,8 +34,6 @@ // // The program begins with \doxygen{otb}{VectorImage} and outputs // \doxygen{otb}{Image}. Then appropriate header files have to be included: -// -// Software Guide : EndLatex #include <iostream> @@ -47,51 +42,38 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // \doxygen{otb}{SEMClassifier} performs estimation of mixture to fit the // initial histogram. Actually, mixture of Gaussian pdf can be performed. // Those generic pdf are treated in // \subdoxygen{otb}{Statistics}{ModelComponentBase}. The Gaussian model // is taken in charge with the class // \subdoxygen{otb}{Statistics}{GaussianModelComponent}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSEMClassifier.h" -// Software Guide : EndCodeSnippet -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { try - { + { if (argc != 6) - { + { std::cerr << "Unsupervised Image Segmentation with SEM approach\n"; std::cerr << argv[0] << " imageIn imgClassif num_of_class "; std::cerr << "nbIteration size_of_the_neighborhood\n"; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// Input/Output images type are define in a classical way. -// In fact, a \doxygen{itk}{VariableLengthVector} is to be -// considered for the templated \code{MeasurementVectorType}, which -// will be used in the \code{ListSample} interface. -// -// Software Guide : EndLatex + // Input/Output images type are define in a classical way. + // In fact, a \doxygen{itk}{VariableLengthVector} is to be + // considered for the templated \code{MeasurementVectorType}, which + // will be used in the \code{ListSample} interface. -// Software Guide : BeginCodeSnippet typedef double PixelType; typedef otb::VectorImage<PixelType, 2> ImageType; @@ -99,126 +81,91 @@ int main(int argc, char * argv[]) typedef otb::Image<unsigned char, 2> OutputImageType; typedef otb::ImageFileWriter<OutputImageType> WriterType; -// Software Guide : EndCodeSnippet - - char * fileNameIn = argv[1]; - char * fileNameImgInit = nullptr; - char * fileNameOut = argv[2]; - int numberOfClasses = atoi(argv[3]); - int numberOfIteration = atoi(argv[4]); - int neighborhood = atoi(argv[5]); + + char* fileNameIn = argv[1]; + char* fileNameImgInit = nullptr; + char* fileNameOut = argv[2]; + int numberOfClasses = atoi(argv[3]); + int numberOfIteration = atoi(argv[4]); + int neighborhood = atoi(argv[5]); double terminationThreshold = 1e-5; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(fileNameIn); reader->Update(); -// Software Guide : BeginLatex -// -// Once the input image is opened, the classifier may be initialised by -// \code{SmartPointer}. -// -// Software Guide : EndLatex + // Once the input image is opened, the classifier may be initialised by + // \code{SmartPointer}. -// Software Guide : BeginCodeSnippet typedef otb::SEMClassifier<ImageType, OutputImageType> ClassifType; - ClassifType::Pointer classifier = ClassifType::New(); -// Software Guide : EndCodeSnippet + ClassifType::Pointer classifier = ClassifType::New(); -// Software Guide : BeginLatex -// -// Then, it follows, classical initializations of the pipeline. -// -// Software Guide : EndLatex + // Then, it follows, classical initializations of the pipeline. -// Software Guide : BeginCodeSnippet classifier->SetNumberOfClasses(numberOfClasses); classifier->SetMaximumIteration(numberOfIteration); classifier->SetNeighborhood(neighborhood); classifier->SetTerminationThreshold(terminationThreshold); classifier->SetSample(reader->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// When an initial segmentation is available, the classifier may use it -// as image (of type \code{OutputImageType}) or as a -// \doxygen{itk}{SampleClassifier} result (of type -// \subdoxygen{itk}{Statistics}{MembershipSample}). -// Software Guide : EndLatex + // When an initial segmentation is available, the classifier may use it + // as image (of type \code{OutputImageType}) or as a + // \doxygen{itk}{SampleClassifier} result (of type + // \subdoxygen{itk}{Statistics}{MembershipSample}). -// Software Guide : BeginCodeSnippet if (fileNameImgInit != nullptr) - { + { typedef otb::ImageFileReader<OutputImageType> ImgInitReaderType; - ImgInitReaderType::Pointer segReader = ImgInitReaderType::New(); + ImgInitReaderType::Pointer segReader = ImgInitReaderType::New(); segReader->SetFileName(fileNameImgInit); segReader->Update(); classifier->SetClassLabels(segReader->GetOutput()); - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// By default, \doxygen{otb}{SEMClassifier} performs initialization of -// \code{ModelComponentBase} by as many instantiation of -// \subdoxygen{otb}{Statistics}{GaussianModelComponent} as the number of -// classes to estimate in the mixture. Nevertheless, the user may add specific -// distribution into the mixture estimation. It is permitted by the use of -// \code{AddComponent} for the given class number and the specific distribution. -// Software Guide : EndLatex + // By default, \doxygen{otb}{SEMClassifier} performs initialization of + // \code{ModelComponentBase} by as many instantiation of + // \subdoxygen{otb}{Statistics}{GaussianModelComponent} as the number of + // classes to estimate in the mixture. Nevertheless, the user may add specific + // distribution into the mixture estimation. It is permitted by the use of + // \code{AddComponent} for the given class number and the specific distribution. std::cerr << "Explicit component initialization\n"; -// Software Guide : BeginCodeSnippet - typedef ClassifType::ClassSampleType ClassSampleType; - typedef otb::Statistics::GaussianModelComponent<ClassSampleType> - GaussianType; + typedef ClassifType::ClassSampleType ClassSampleType; + typedef otb::Statistics::GaussianModelComponent<ClassSampleType> GaussianType; for (int i = 0; i < numberOfClasses; ++i) - { + { GaussianType::Pointer model = GaussianType::New(); classifier->AddComponent(i, model); - } -// Software Guide : EndCodeSnippet + } -// Software Guide : BeginLatex -// -// Once the pipeline is instantiated. The segmentation by itself may be -// launched by using the \code{Update} function. -// Software Guide : EndLatex + // Once the pipeline is instantiated. The segmentation by itself may be + // launched by using the \code{Update} function. -// Software Guide : BeginCodeSnippet try - { + { classifier->Update(); - } -// Software Guide : EndCodeSnippet + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught in " << argv[0] << "!\n"; std::cerr << err << std::endl; return -1; - } + } -// Software Guide : BeginLatex -// -// The segmentation may outputs a result of type -// \subdoxygen{itk}{Statistics}{MembershipSample} as it is the -// case for the \doxygen{otb}{SVMClassifier}. But when using -// \code{GetOutputImage} the output is directly an Image. -// -// Only for visualization purposes, we choose to rescale the image of -// classes before saving it to a file. We will use the -// \doxygen{itk}{RescaleIntensityImageFilter} for this purpose. -// -// Software Guide : EndLatex + // The segmentation may outputs a result of type + // \subdoxygen{itk}{Statistics}{MembershipSample} as it is the + // case for the \doxygen{otb}{SVMClassifier}. But when using + // \code{GetOutputImage} the output is directly an Image. + // + // Only for visualization purposes, we choose to rescale the image of + // classes before saving it to a file. We will use the + // \doxygen{itk}{RescaleIntensityImageFilter} for this purpose. -// Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter<OutputImageType, - OutputImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputImageType> RescalerType; + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetOutputMinimum(itk::NumericTraits<unsigned char>::min()); rescaler->SetOutputMaximum(itk::NumericTraits<unsigned char>::max()); @@ -229,55 +176,43 @@ int main(int argc, char * argv[]) writer->SetFileName(fileNameOut); writer->SetInput(rescaler->GetOutput()); writer->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Figure \ref{fig:RESSEMCLASSIF} shows the result of the SEM segmentation -// with 4 different classes and a contextual neighborhood of 3 pixels. -// \begin{figure} -// \center -// \includegraphics[width=0.6\textwidth]{SEMClassif.eps} -// \itkcaption[SEM Classification results]{SEM Classification results.} -// \label{fig:RESSEMCLASSIF} -// \end{figure} -// -// As soon as the segmentation is performed by an iterative stochastic -// process, it is worth verifying the output status: does the segmentation -// ends when it has converged or just at the limit of the iteration numbers. -// -// Software Guide : EndLatex + // Figure \ref{fig:RESSEMCLASSIF} shows the result of the SEM segmentation + // with 4 different classes and a contextual neighborhood of 3 pixels. + // \begin{figure} + // \center + // \includegraphics[width=0.6\textwidth]{SEMClassif.eps} + // \itkcaption[SEM Classification results]{SEM Classification results.} + // \label{fig:RESSEMCLASSIF} + // \end{figure} + // + // As soon as the segmentation is performed by an iterative stochastic + // process, it is worth verifying the output status: does the segmentation + // ends when it has converged or just at the limit of the iteration numbers. -// Software Guide : BeginCodeSnippet std::cerr << "Program terminated with a "; - if (classifier->GetTerminationCode() == - ClassifType::CONVERGED) std::cerr << "converged "; - else std::cerr << "not-converged "; + if (classifier->GetTerminationCode() == ClassifType::CONVERGED) + std::cerr << "converged "; + else + std::cerr << "not-converged "; std::cerr << "code...\n"; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The text output gives for each class the parameters of the pdf (e.g. mean -// of each component of the class and there covariance matrix, in the case of a -// Gaussian mixture model). -// -// Software Guide : EndLatex + // The text output gives for each class the parameters of the pdf (e.g. mean + // of each component of the class and there covariance matrix, in the case of a + // Gaussian mixture model). -// Software Guide : BeginCodeSnippet classifier->Print(std::cerr); -// Software Guide : EndCodeSnippet - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "Exception itk::ExceptionObject thrown !\n"; std::cerr << err << std::endl; return EXIT_FAILURE; - } + } catch (...) - { + { std::cerr << "Unknown exception thrown !\n"; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Learning/SOMClassifierExample.cxx b/Examples/Learning/SOMClassifierExample.cxx index e9b6e68b591a8ed3e985546fe64340d463e331be..de113b80b0a0cff1968d4bf7c7a67923c9ded4c0 100644 --- a/Examples/Learning/SOMClassifierExample.cxx +++ b/Examples/Learning/SOMClassifierExample.cxx @@ -19,7 +19,6 @@ */ - #include <fstream> #include "otbImage.h" #include "otbSOMMap.h" @@ -28,12 +27,11 @@ #include "itkImageRegionIterator.h" #include "itkListSample.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1.png}, {ROI_QB_MUL_SOM.png} -// OUTPUTS: {ROI_QB_MUL_SOMCLASS.png} -// Software Guide : EndCommandLineArgs +/* Example usage: +./SOMClassifierExample Input/ROI_QB_MUL_1.png Input/ROI_QB_MUL_SOM.png Output/ROI_QB_MUL_SOMCLASS.png +*/ + -// Software Guide : BeginLatex // This example illustrates the use of the // \doxygen{otb}{SOMClassifier} class for performing a classification // using an existing Kohonen's Self Organizing. Actually, the SOM @@ -45,92 +43,63 @@ // // The first thing to do is include the header file for the // class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSOMClassifier.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 4) - { - std::cout << "Usage : " << argv[0] << " inputImage modelFile outputImage" - << std::endl; + { + std::cout << "Usage : " << argv[0] << " inputImage modelFile outputImage" << std::endl; return EXIT_FAILURE; - } + } - const char * imageFilename = argv[1]; - const char * mapFilename = argv[2]; - const char * outputFilename = argv[3]; + const char* imageFilename = argv[1]; + const char* mapFilename = argv[2]; + const char* outputFilename = argv[3]; typedef double InputPixelType; typedef unsigned char LabelPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef itk::VariableLengthVector<InputPixelType> PixelType; -// Software Guide : BeginLatex -// -// As for the SOM learning step, we must define the types for the -// \code{otb::SOMMap}, and therefore, also for the distance to be -// used. We will also define the type for the SOM reader, which is -// actually an \doxygen{otb}{ImageFileReader} which the appropriate -// image type. -// -// Software Guide : EndLatex + // As for the SOM learning step, we must define the types for the + // \code{otb::SOMMap}, and therefore, also for the distance to be + // used. We will also define the type for the SOM reader, which is + // actually an \doxygen{otb}{ImageFileReader} which the appropriate + // image type. -// Software Guide : BeginCodeSnippet - typedef itk::Statistics::EuclideanDistanceMetric<PixelType> DistanceType; - typedef otb::SOMMap<PixelType, DistanceType, Dimension> SOMMapType; - typedef otb::ImageFileReader<SOMMapType> SOMReaderType; -// Software Guide : EndCodeSnippet + typedef itk::Statistics::EuclideanDistanceMetric<PixelType> DistanceType; + typedef otb::SOMMap<PixelType, DistanceType, Dimension> SOMMapType; + typedef otb::ImageFileReader<SOMMapType> SOMReaderType; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; -// Software Guide : BeginLatex -// -// The classification will be performed by the -// \doxygen{otb}{SOMClassifier}, which, as most of the -// classifiers, works on -// \subdoxygen{itk}{Statistics}{ListSample}s. In order to be able -// to perform an image classification, we will need to use the -// \subdoxygen{itk}{Statistics}{ImageToListAdaptor} which is -// templated over the type of image to be adapted. The -// \code{SOMClassifier} is templated over the sample type, the SOMMap -// type and the pixel type for the labels. -// -// Software Guide : EndLatex + // The classification will be performed by the + // \doxygen{otb}{SOMClassifier}, which, as most of the + // classifiers, works on + // \subdoxygen{itk}{Statistics}{ListSample}s. In order to be able + // to perform an image classification, we will need to use the + // \subdoxygen{itk}{Statistics}{ImageToListAdaptor} which is + // templated over the type of image to be adapted. The + // \code{SOMClassifier} is templated over the sample type, the SOMMap + // type and the pixel type for the labels. + + typedef itk::Statistics::ListSample<PixelType> SampleType; + typedef otb::SOMClassifier<SampleType, SOMMapType, LabelPixelType> ClassifierType; + // + // The result of the classification will be stored on an image and + // saved to a file. Therefore, we define the types needed for this step. -// Software Guide : BeginCodeSnippet - typedef itk::Statistics::ListSample<PixelType> SampleType; - typedef otb::SOMClassifier<SampleType, SOMMapType, LabelPixelType> - ClassifierType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// The result of the classification will be stored on an image and -// saved to a file. Therefore, we define the types needed for this step. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet typedef otb::Image<LabelPixelType, Dimension> OutputImageType; typedef otb::ImageFileWriter<OutputImageType> WriterType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We can now start reading the input image and the SOM given as -// inputs to the program. We instantiate the readers as usual. -// -// Software Guide : EndLatex + // + // We can now start reading the input image and the SOM given as + // inputs to the program. We instantiate the readers as usual. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(imageFilename); reader->Update(); @@ -138,139 +107,86 @@ int main(int argc, char* argv[]) SOMReaderType::Pointer somreader = SOMReaderType::New(); somreader->SetFileName(mapFilename); somreader->Update(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// The conversion of the input data from image to list sample is -// easily done using the adaptor. -// -// Software Guide : EndLatex + // + // The conversion of the input data from image to list sample is + // easily done using the adaptor. -// Software Guide : BeginCodeSnippet SampleType::Pointer sample = SampleType::New(); - itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(), - reader->GetOutput()-> - GetLargestPossibleRegion()); + itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion()); sample->SetMeasurementVectorSize(reader->GetOutput()->GetNumberOfComponentsPerPixel()); it.GoToBegin(); while (!it.IsAtEnd()) - { + { sample->PushBack(it.Get()); ++it; - } -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// The classifier can now be instantiated. The input data is set by -// using the \code{SetSample()} method and the SOM si set using the -// \code{SetMap()} method. The classification is triggered by using -// the \code{Update()} method. -// -// Software Guide : EndLatex + } + // + // The classifier can now be instantiated. The input data is set by + // using the \code{SetSample()} method and the SOM si set using the + // \code{SetMap()} method. The classification is triggered by using + // the \code{Update()} method. -// Software Guide : BeginCodeSnippet ClassifierType::Pointer classifier = ClassifierType::New(); classifier->SetSample(sample.GetPointer()); classifier->SetMap(somreader->GetOutput()); classifier->Update(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// Once the classification has been performed, the sample list -// obtained at the output of the classifier must be converted into an -// image. We create the image as follows : -// -// Software Guide : EndLatex + // + // Once the classification has been performed, the sample list + // obtained at the output of the classifier must be converted into an + // image. We create the image as follows : -// Software Guide : BeginCodeSnippet OutputImageType::Pointer outputImage = OutputImageType::New(); outputImage->SetRegions(reader->GetOutput()->GetLargestPossibleRegion()); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We can now get a pointer to the classification result. -// -// Software Guide : EndLatex + // + // We can now get a pointer to the classification result. -// Software Guide : BeginCodeSnippet ClassifierType::OutputType* membershipSample = classifier->GetOutput(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// And we can declare the iterators pointing to the front and the -// back of the sample list. -// -// Software Guide : EndLatex + // + // And we can declare the iterators pointing to the front and the + // back of the sample list. -// Software Guide : BeginCodeSnippet - ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin(); - ClassifierType::OutputType::ConstIterator m_last = membershipSample->End(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We also declare an \doxygen{itk}{ImageRegionIterator} in order -// to fill the output image with the class labels. -// -// Software Guide : EndLatex + ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin(); + ClassifierType::OutputType::ConstIterator m_last = membershipSample->End(); + // + // We also declare an \doxygen{itk}{ImageRegionIterator} in order + // to fill the output image with the class labels. -// Software Guide : BeginCodeSnippet typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType; OutputIteratorType outIt(outputImage, outputImage->GetLargestPossibleRegion()); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We iterate through the sample list and the output image and assign -// the label values to the image pixels. -// -// Software Guide : EndLatex + // + // We iterate through the sample list and the output image and assign + // the label values to the image pixels. -// Software Guide : BeginCodeSnippet outIt.GoToBegin(); while (m_iter != m_last && !outIt.IsAtEnd()) - { + { outIt.Set(m_iter.GetClassLabel()); ++m_iter; ++outIt; - } -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// Finally, we write the classified image to a file. -// -// Software Guide : EndLatex + } + // + // Finally, we write the classified image to a file. -// Software Guide : BeginCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename); writer->SetInput(outputImage); writer->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// Figure \ref{fig:SOMMAPCLASS} shows the result of the SOM classification. -// \begin{figure} -// \center -// \includegraphics[width=0.35\textwidth]{ROI_QB_MUL_1.eps} -// \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOM.eps} -// \includegraphics[width=0.35\textwidth]{ROI_QB_MUL_SOMCLASS.eps} -// \itkcaption[SOM Image Classification]{Result of the SOM -// learning. Left: RGB image. Center: SOM. Right: Classified Image} -// \label{fig:SOMMAPCLASS} -// \end{figure} -// Software Guide : EndLatex + // Figure \ref{fig:SOMMAPCLASS} shows the result of the SOM classification. + // \begin{figure} + // \center + // \includegraphics[width=0.35\textwidth]{ROI_QB_MUL_1.eps} + // \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOM.eps} + // \includegraphics[width=0.35\textwidth]{ROI_QB_MUL_SOMCLASS.eps} + // \itkcaption[SOM Image Classification]{Result of the SOM + // learning. Left: RGB image. Center: SOM. Right: Classified Image} + // \label{fig:SOMMAPCLASS} + // \end{figure} return EXIT_SUCCESS; } diff --git a/Examples/Learning/SOMExample.cxx b/Examples/Learning/SOMExample.cxx index 8e4f23ceb07490a5661a85ea60a1aade58cc8e40..5b1b90bcadcfaa8bbc5217b2a7acd8a80a449104 100644 --- a/Examples/Learning/SOMExample.cxx +++ b/Examples/Learning/SOMExample.cxx @@ -20,13 +20,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1.png} -// OUTPUTS: {ROI_QB_MUL_SOM.png}, {ROI_QB_MUL_SOMACT.png} -// 4 4 4 4 20 1.0 0.1 128 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SOMExample Input/ROI_QB_MUL_1.png Output/ROI_QB_MUL_SOM.png Output/ROI_QB_MUL_SOMACT.png 4 4 4 4 20 1.0 0.1 128 +*/ + -// Software Guide : BeginLatex // This example illustrates the use of the // \doxygen{otb}{SOM} class for building Kohonen's Self Organizing // Maps. @@ -43,14 +41,10 @@ // the activation map builder whose utility will be explained at the // end of the example. // -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSOMMap.h" #include "otbSOM.h" #include "otbSOMActivationBuilder.h" -// Software Guide : EndCodeSnippet #include "itkMacro.h" @@ -62,132 +56,82 @@ #include "otbPerBandVectorImageFilter.h" #include "otbPrintableImageFilter.h" -// Software Guide : BeginLatex // Since the \doxygen{otb}{SOM} class uses a distance, we will need to // include the header file for the one we want to use // -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "itkListSample.h" int main(int itkNotUsed(argc), char* argv[]) { - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - const char * actMapFileName = argv[3]; - unsigned int sizeX = atoi(argv[4]); - unsigned int sizeY = atoi(argv[5]); - unsigned int neighInitX = atoi(argv[6]); - unsigned int neighInitY = atoi(argv[7]); - unsigned int nbIterations = atoi(argv[8]); - double betaInit = atof(argv[9]); - double betaEnd = atof(argv[10]); - double initValue = atof(argv[11]); - -// Software Guide : BeginLatex -// -// The Self Organizing Map itself is actually an N-dimensional image -// where each pixel contains a neuron. In our case, we decide to build -// a 2-dimensional SOM, where the neurons store RGB values with -// floating point precision. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const char* inputFileName = argv[1]; + const char* outputFileName = argv[2]; + const char* actMapFileName = argv[3]; + unsigned int sizeX = atoi(argv[4]); + unsigned int sizeY = atoi(argv[5]); + unsigned int neighInitX = atoi(argv[6]); + unsigned int neighInitY = atoi(argv[7]); + unsigned int nbIterations = atoi(argv[8]); + double betaInit = atof(argv[9]); + double betaEnd = atof(argv[10]); + double initValue = atof(argv[11]); + + // The Self Organizing Map itself is actually an N-dimensional image + // where each pixel contains a neuron. In our case, we decide to build + // a 2-dimensional SOM, where the neurons store RGB values with + // floating point precision. + + const unsigned int Dimension = 2; typedef double PixelType; typedef otb::VectorImage<PixelType, Dimension> ImageType; typedef ImageType::PixelType VectorType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The distance that we want to apply between the RGB values is the -// Euclidean one. Of course we could choose to use other type of -// distance, as for instance, a distance defined in any other color space. -// -// Software Guide : EndLatex + // The distance that we want to apply between the RGB values is the + // Euclidean one. Of course we could choose to use other type of + // distance, as for instance, a distance defined in any other color space. -// Software Guide : BeginCodeSnippet typedef itk::Statistics::EuclideanDistanceMetric<VectorType> DistanceType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We can now define the type for the map. The \doxygen{otb}{SOMMap} -// class is templated over the neuron type -- \code{PixelType} here -// --, the distance type and the number of dimensions. Note that the -// number of dimensions of the map could be different from the one of -// the images to be processed. -// -// Software Guide : EndLatex + // + // We can now define the type for the map. The \doxygen{otb}{SOMMap} + // class is templated over the neuron type -- \code{PixelType} here + // --, the distance type and the number of dimensions. Note that the + // number of dimensions of the map could be different from the one of + // the images to be processed. -// Software Guide : BeginCodeSnippet typedef otb::SOMMap<VectorType, DistanceType, Dimension> MapType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We are going to perform the learning directly on the pixels of the -// input image. Therefore, the image type is defined using the same -// pixel type as we used for the map. We also define the type for the -// imge file reader. -// -// Software Guide : EndLatex + // + // We are going to perform the learning directly on the pixels of the + // input image. Therefore, the image type is defined using the same + // pixel type as we used for the map. We also define the type for the + // imge file reader. -// Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// Since the \doxygen{otb}{SOM} class works on lists of samples, it -// will need to access the input image through an adaptor. Its type is -// defined as follows: -// -// Software Guide : EndLatex + // + // Since the \doxygen{otb}{SOM} class works on lists of samples, it + // will need to access the input image through an adaptor. Its type is + // defined as follows: -// Software Guide : BeginCodeSnippet typedef itk::Statistics::ListSample<VectorType> SampleListType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We can now define the type for the SOM, which is templated over the -// input sample list and the type of the map to be produced and the two -// functors that hold the training behavior. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef otb::Functor::CzihoSOMLearningBehaviorFunctor - LearningBehaviorFunctorType; - typedef otb::Functor::CzihoSOMNeighborhoodBehaviorFunctor - NeighborhoodBehaviorFunctorType; - typedef otb::SOM<SampleListType, MapType, - LearningBehaviorFunctorType, NeighborhoodBehaviorFunctorType> - SOMType; -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// As an alternative to standard \code{SOMType}, one can decide to use -// an \doxygen{otb}{PeriodicSOM}, which behaves like \doxygen{otb}{SOM} but -// is to be considered to as a torus instead of a simple map. Hence, the -// neighborhood behavior of the winning neuron does not depend on its location -// on the map... -// \doxygen{otb}{PeriodicSOM} is defined in otbPeriodicSOM.h. -// -// We can now start building the pipeline. The first step is to -// instantiate the reader and pass its output to the adaptor. -// -// Software Guide : EndLatex + // + // We can now define the type for the SOM, which is templated over the + // input sample list and the type of the map to be produced and the two + // functors that hold the training behavior. + + typedef otb::Functor::CzihoSOMLearningBehaviorFunctor LearningBehaviorFunctorType; + typedef otb::Functor::CzihoSOMNeighborhoodBehaviorFunctor NeighborhoodBehaviorFunctorType; + typedef otb::SOM<SampleListType, MapType, LearningBehaviorFunctorType, NeighborhoodBehaviorFunctorType> SOMType; + // + // As an alternative to standard \code{SOMType}, one can decide to use + // an \doxygen{otb}{PeriodicSOM}, which behaves like \doxygen{otb}{SOM} but + // is to be considered to as a torus instead of a simple map. Hence, the + // neighborhood behavior of the winning neuron does not depend on its location + // on the map... + // \doxygen{otb}{PeriodicSOM} is defined in otbPeriodicSOM.h. + // + // We can now start building the pipeline. The first step is to + // instantiate the reader and pass its output to the adaptor. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(inputFileName); reader->Update(); @@ -195,86 +139,51 @@ int main(int itkNotUsed(argc), char* argv[]) SampleListType::Pointer sampleList = SampleListType::New(); sampleList->SetMeasurementVectorSize(reader->GetOutput()->GetVectorLength()); - itk::ImageRegionIterator<ImageType> imgIter (reader->GetOutput(), - reader->GetOutput()-> - GetBufferedRegion()); + itk::ImageRegionIterator<ImageType> imgIter(reader->GetOutput(), reader->GetOutput()->GetBufferedRegion()); imgIter.GoToBegin(); - itk::ImageRegionIterator<ImageType> imgIterEnd (reader->GetOutput(), - reader->GetOutput()-> - GetBufferedRegion()); + itk::ImageRegionIterator<ImageType> imgIterEnd(reader->GetOutput(), reader->GetOutput()->GetBufferedRegion()); imgIterEnd.GoToEnd(); do - { + { sampleList->PushBack(imgIter.Get()); ++imgIter; - } - while (imgIter != imgIterEnd); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We can now instantiate the SOM algorithm and set the sample list as input. -// -// Software Guide : EndLatex + } while (imgIter != imgIterEnd); + // + // We can now instantiate the SOM algorithm and set the sample list as input. -// Software Guide : BeginCodeSnippet SOMType::Pointer som = SOMType::New(); som->SetListSample(sampleList); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// We use a \code{SOMType::SizeType} array in order to set the sizes -// of the map. -// -// Software Guide : EndLatex + // + // We use a \code{SOMType::SizeType} array in order to set the sizes + // of the map. -// Software Guide : BeginCodeSnippet SOMType::SizeType size; size[0] = sizeX; size[1] = sizeY; som->SetMapSize(size); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// The initial size of the neighborhood of each neuron is set in the -// same way. -// -// Software Guide : EndLatex + // + // The initial size of the neighborhood of each neuron is set in the + // same way. -// Software Guide : BeginCodeSnippet SOMType::SizeType radius; radius[0] = neighInitX; radius[1] = neighInitY; som->SetNeighborhoodSizeInit(radius); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// The other parameters are the number of iterations, the initial and -// the final values for the learning rate -- $\beta$ -- and the -// maximum initial value for the neurons (the map will be randomly -// initialized). -// -// Software Guide : EndLatex + // + // The other parameters are the number of iterations, the initial and + // the final values for the learning rate -- $\beta$ -- and the + // maximum initial value for the neurons (the map will be randomly + // initialized). -// Software Guide : BeginCodeSnippet som->SetNumberOfIterations(nbIterations); som->SetBetaInit(betaInit); som->SetBetaEnd(betaEnd); som->SetMaxWeight(static_cast<PixelType>(initValue)); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// Now comes the initialization of the functors. -// -// Software Guide : EndLatex + // + // Now comes the initialization of the functors. -// Software Guide : BeginCodeSnippet LearningBehaviorFunctorType learningFunctor; learningFunctor.SetIterationThreshold(radius, nbIterations); som->SetBetaFunctor(learningFunctor); @@ -282,32 +191,20 @@ int main(int itkNotUsed(argc), char* argv[]) NeighborhoodBehaviorFunctorType neighborFunctor; som->SetNeighborhoodSizeFunctor(neighborFunctor); som->Update(); -// Software Guide : EndCodeSnippet -// -// Software Guide : BeginLatex -// -// Finally, we set up the las part of the pipeline where the plug the -// output of the SOM into the writer. The learning procedure is -// triggered by calling the \code{Update()} method on the writer. -// Since the map is itself an image, we can write it to disk with an -// \doxygen{otb}{ImageFileWriter}. -// -// Software Guide : EndLatex - - //Just for visualization purposes, we zoom the image, and pass it to the printable image filter - typedef otb::Image<PixelType, - 2> SingleImageType; - typedef itk::ExpandImageFilter<SingleImageType, - SingleImageType> ExpandType; - typedef otb::PerBandVectorImageFilter<MapType, MapType, - ExpandType> VectorExpandType; - typedef itk::NearestNeighborInterpolateImageFunction<SingleImageType, - double> - InterpolatorType; - typedef otb::PrintableImageFilter<MapType> - PrintableFilterType; - typedef otb::ImageFileWriter<PrintableFilterType::OutputImageType> - PrintableWriterType; + // + // Finally, we set up the las part of the pipeline where the plug the + // output of the SOM into the writer. The learning procedure is + // triggered by calling the \code{Update()} method on the writer. + // Since the map is itself an image, we can write it to disk with an + // \doxygen{otb}{ImageFileWriter}. + + // Just for visualization purposes, we zoom the image, and pass it to the printable image filter + typedef otb::Image<PixelType, 2> SingleImageType; + typedef itk::ExpandImageFilter<SingleImageType, SingleImageType> ExpandType; + typedef otb::PerBandVectorImageFilter<MapType, MapType, ExpandType> VectorExpandType; + typedef itk::NearestNeighborInterpolateImageFunction<SingleImageType, double> InterpolatorType; + typedef otb::PrintableImageFilter<MapType> PrintableFilterType; + typedef otb::ImageFileWriter<PrintableFilterType::OutputImageType> PrintableWriterType; InterpolatorType::Pointer interpolator = InterpolatorType::New(); VectorExpandType::Pointer expand = VectorExpandType::New(); @@ -315,7 +212,7 @@ int main(int itkNotUsed(argc), char* argv[]) scalarExpand->SetExpandFactors(40); scalarExpand->SetInterpolator(interpolator); - //scalarExpand->SetEdgePaddingValue(255); + // scalarExpand->SetEdgePaddingValue(255); expand->SetFilter(scalarExpand); @@ -337,113 +234,78 @@ int main(int itkNotUsed(argc), char* argv[]) printWriter->Update(); -// Software Guide : BeginLatex -// Figure \ref{fig:SOMMAP} shows the result of the SOM learning. Since -// we have performed a learning on RGB pixel values, the produced SOM -// can be interpreted as an optimal color table for the input -// image. It can be observed that the obtained colors are -// topologically organised, so similar colors are also close in the -// map. This topological organisation can be exploited to further -// reduce the number of coding levels of the pixels without -// performing a new learning: we can subsample the map to get a new -// color table. Also, a bilinear interpolation between the neurons can -// be used to increase the number of coding levels. -// \begin{figure} -// \center -// \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1.eps} -// \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOM.eps} -// \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOMACT.eps} -// \itkcaption[SOM Image Classification]{Result of the SOM -// learning. Left: RGB image. Center: SOM. Right: Activation map} -// \label{fig:SOMMAP} -// \end{figure} -// Software Guide : EndLatex - -// Software Guide : BeginLatex -// -// We can now compute the activation map for the input image. The -// activation map tells us how many times a given neuron is activated -// for the set of examples given to the map. The activation map is -// stored as a scalar image and an integer pixel type is usually enough. -// -// Software Guide : EndLatex + // Figure \ref{fig:SOMMAP} shows the result of the SOM learning. Since + // we have performed a learning on RGB pixel values, the produced SOM + // can be interpreted as an optimal color table for the input + // image. It can be observed that the obtained colors are + // topologically organised, so similar colors are also close in the + // map. This topological organisation can be exploited to further + // reduce the number of coding levels of the pixels without + // performing a new learning: we can subsample the map to get a new + // color table. Also, a bilinear interpolation between the neurons can + // be used to increase the number of coding levels. + // \begin{figure} + // \center + // \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1.eps} + // \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOM.eps} + // \includegraphics[width=0.2\textwidth]{ROI_QB_MUL_SOMACT.eps} + // \itkcaption[SOM Image Classification]{Result of the SOM + // learning. Left: RGB image. Center: SOM. Right: Activation map} + // \label{fig:SOMMAP} + // \end{figure} + + // We can now compute the activation map for the input image. The + // activation map tells us how many times a given neuron is activated + // for the set of examples given to the map. The activation map is + // stored as a scalar image and an integer pixel type is usually enough. -// Software Guide : BeginCodeSnippet typedef unsigned char OutputPixelType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; typedef otb::ImageFileWriter<OutputImageType> ActivationWriterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// In a similar way to the \doxygen{otb}{SOM} class the -// \doxygen{otb}{SOMActivationBuilder} is templated over the sample -// list given as input, the SOM map type and the activation map to be -// built as output. -// -// Software Guide : EndLatex + // In a similar way to the \doxygen{otb}{SOM} class the + // \doxygen{otb}{SOMActivationBuilder} is templated over the sample + // list given as input, the SOM map type and the activation map to be + // built as output. -// Software Guide : BeginCodeSnippet - typedef otb::SOMActivationBuilder<SampleListType, MapType, - OutputImageType> SOMActivationBuilderType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the activation map builder and set as input the SOM -// map build before and the image (using the adaptor). -// -// Software Guide : EndLatex + typedef otb::SOMActivationBuilder<SampleListType, MapType, OutputImageType> SOMActivationBuilderType; + // We instantiate the activation map builder and set as input the SOM + // map build before and the image (using the adaptor). -// Software Guide : BeginCodeSnippet - SOMActivationBuilderType::Pointer somAct - = SOMActivationBuilderType::New(); + SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New(); somAct->SetInput(som->GetOutput()); somAct->SetListSample(sampleList); somAct->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The final step is to write the activation map to a file. -// -// Software Guide : EndLatex + // The final step is to write the activation map to a file. -// Software Guide : BeginCodeSnippet if (actMapFileName != nullptr) - { + { ActivationWriterType::Pointer actWriter = ActivationWriterType::New(); actWriter->SetFileName(actMapFileName); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// The righthand side of figure \ref{fig:SOMMAP} shows the activation -// map obtained. -// -// Software Guide : EndLatex + // The righthand side of figure \ref{fig:SOMMAP} shows the activation + // map obtained. - //Just for visualization purposes, we zoom the image. - typedef itk::ExpandImageFilter<OutputImageType, - OutputImageType> ExpandType2; - typedef itk::NearestNeighborInterpolateImageFunction<OutputImageType, - double> - InterpolatorType2; + // Just for visualization purposes, we zoom the image. + typedef itk::ExpandImageFilter<OutputImageType, OutputImageType> ExpandType2; + typedef itk::NearestNeighborInterpolateImageFunction<OutputImageType, double> InterpolatorType2; InterpolatorType2::Pointer interpolator2 = InterpolatorType2::New(); - ExpandType2::Pointer expand2 = ExpandType2::New(); + ExpandType2::Pointer expand2 = ExpandType2::New(); expand2->SetInput(somAct->GetOutput()); expand2->SetExpandFactors(20); expand2->SetInterpolator(interpolator2); - //expand2->SetEdgePaddingValue(255); + // expand2->SetEdgePaddingValue(255); expand2->UpdateOutputInformation(); actWriter->SetInput(expand2->GetOutput()); actWriter->Update(); - } + } else - { + { std::cerr << "The activation map file name is null" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; - } diff --git a/Examples/Learning/SVMImageEstimatorClassificationMultiExample.cxx b/Examples/Learning/SVMImageEstimatorClassificationMultiExample.cxx index 10117f5e65ca9ee8c83bfbaa13e4e8535be02cd9..e79af559e1b34c690a1921bc1ddf1f5ba8eb5176 100644 --- a/Examples/Learning/SVMImageEstimatorClassificationMultiExample.cxx +++ b/Examples/Learning/SVMImageEstimatorClassificationMultiExample.cxx @@ -19,14 +19,15 @@ */ +/* Example usage: +./SVMImageEstimatorClassificationMultiExample Input/ROI_QB_MUL_1.png \ + Input/ROI_mask_multi.png \ + Output/ROI_QB_MUL_1_SVN_CLASS_MULTI.png \ + Output/ROI_QB_MUL_1_SVN_CLASS_MULTI_Rescaled.jpg \ + Output/ROI_mask_multi.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1.png}, {ROI_mask_multi.png} -// OUTPUTS: {ROI_QB_MUL_1_SVN_CLASS_MULTI.png}, {ROI_QB_MUL_1_SVN_CLASS_MULTI_Rescaled.jpg} -// NORMALIZE_EPS_OUTPUT_OF: {ROI_mask_multi.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex // This example illustrates the OTB's multi-class SVM // capabilities. The theory behind this kind of classification is out // of the scope of this guide. In OTB, the multi-class SVM @@ -44,18 +45,15 @@ // The following header files are needed for the program: -// Software Guide : EndLatex #include "itkMacro.h" #include "otbImage.h" #include "otbVectorImage.h" #include <iostream> -// Software Guide : BeginCodeSnippet #include "otbLibSVMMachineLearningModel.h" #include "itkImageToListSampleFilter.h" #include "otbImageClassificationFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileWriter.h" @@ -65,94 +63,64 @@ #include "otbImageFileReader.h" -int main(int itkNotUsed(argc), char *argv[]) +int main(int itkNotUsed(argc), char* argv[]) { - const char* inputImageFileName = argv[1]; - const char* trainingImageFileName = argv[2]; - const char* outputImageFileName = argv[3]; + const char* inputImageFileName = argv[1]; + const char* trainingImageFileName = argv[2]; + const char* outputImageFileName = argv[3]; const char* outputRescaledImageFileName = argv[4]; -// const char* outputModelFileName = argv[4]; - -// Software Guide : BeginLatex -// -// We define the types for the input and training images. Even if the -// input image will be an RGB image, we can read it as a 3 component -// vector image. This simplifies the interfacing with OTB's SVM -// framework. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // const char* outputModelFileName = argv[4]; + + // We define the types for the input and training images. Even if the + // input image will be an RGB image, we can read it as a 3 component + // vector image. This simplifies the interfacing with OTB's SVM + // framework. typedef unsigned short InputPixelType; - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; - typedef otb::Image<InputPixelType, Dimension> TrainingImageType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// The \doxygen{otb}{LibSVMMachineLearningModel} class is templated over -// the input (features) and the training (labels) values. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef otb::LibSVMMachineLearningModel<InputPixelType, - InputPixelType> ModelType; - -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// As usual, we define the readers for the images. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + typedef otb::Image<InputPixelType, Dimension> TrainingImageType; + + // The \doxygen{otb}{LibSVMMachineLearningModel} class is templated over + // the input (features) and the training (labels) values. + typedef otb::LibSVMMachineLearningModel<InputPixelType, InputPixelType> ModelType; + + + // As usual, we define the readers for the images. typedef otb::ImageFileReader<InputImageType> InputReaderType; typedef otb::ImageFileReader<TrainingImageType> TrainingReaderType; - InputReaderType::Pointer inputReader = InputReaderType::New(); + InputReaderType::Pointer inputReader = InputReaderType::New(); TrainingReaderType::Pointer trainingReader = TrainingReaderType::New(); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// We read the images. It is worth to note that, in order to ensure -// the pipeline coherence, the output of the objects which precede the -// model estimator in the pipeline, must be up to date, so we call -// the corresponding \code{Update} methods. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + + // We read the images. It is worth to note that, in order to ensure + // the pipeline coherence, the output of the objects which precede the + // model estimator in the pipeline, must be up to date, so we call + // the corresponding \code{Update} methods. inputReader->SetFileName(inputImageFileName); trainingReader->SetFileName(trainingImageFileName); //~ inputReader->Update(); //~ trainingReader->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The input data is contained in images. Only label values greater than 0 -// shall be used, so we create two iterators to fill the input and target -// ListSamples. -// -// Software Guide : EndLatex + // The input data is contained in images. Only label values greater than 0 + // shall be used, so we create two iterators to fill the input and target + // ListSamples. -// Software Guide : BeginCodeSnippet - typedef itk::BinaryThresholdImageFilter<TrainingImageType,TrainingImageType> ThresholdFilterType; - ThresholdFilterType::Pointer thresholder = ThresholdFilterType::New(); + typedef itk::BinaryThresholdImageFilter<TrainingImageType, TrainingImageType> ThresholdFilterType; + ThresholdFilterType::Pointer thresholder = ThresholdFilterType::New(); thresholder->SetInput(trainingReader->GetOutput()); thresholder->SetLowerThreshold(1); thresholder->SetOutsideValue(0); thresholder->SetInsideValue(1); - typedef itk::Statistics::ImageToListSampleFilter<InputImageType,TrainingImageType> ImageToListSample; - typedef itk::Statistics::ImageToListSampleFilter<TrainingImageType,TrainingImageType> ImageToTargetListSample; + typedef itk::Statistics::ImageToListSampleFilter<InputImageType, TrainingImageType> ImageToListSample; + typedef itk::Statistics::ImageToListSampleFilter<TrainingImageType, TrainingImageType> ImageToTargetListSample; ImageToListSample::Pointer imToList = ImageToListSample::New(); imToList->SetInput(inputReader->GetOutput()); @@ -166,105 +134,52 @@ int main(int itkNotUsed(argc), char *argv[]) imToTargetList->SetMaskValue(1); imToTargetList->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now instantiate the model and set its parameters. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // We can now instantiate the model and set its parameters. ModelType::Pointer svmModel = ModelType::New(); svmModel->SetInputListSample(const_cast<ModelType::InputListSampleType*>(imToList->GetOutput())); svmModel->SetTargetListSample(const_cast<ModelType::TargetListSampleType*>(imToTargetList->GetOutput())); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The model training procedure is triggered by calling the -// model's \code{Train} method. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // The model training procedure is triggered by calling the + // model's \code{Train} method. svmModel->Train(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We have now all the elements to create a classifier. The classifier -// is templated over the sample type (the type of the data to be -// classified) and the label type (the type of the output of the classifier). -// -// Software Guide : EndLatex + // We have now all the elements to create a classifier. The classifier + // is templated over the sample type (the type of the data to be + // classified) and the label type (the type of the output of the classifier). -// Software Guide : BeginCodeSnippet typedef otb::ImageClassificationFilter<InputImageType, TrainingImageType> ClassifierType; ClassifierType::Pointer classifier = ClassifierType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We set the classifier parameters : number of classes, SVM model, -// the sample data. And we trigger the classification process by -// calling the \code{Update} method. -// -// Software Guide : EndLatex + // We set the classifier parameters : number of classes, SVM model, + // the sample data. And we trigger the classification process by + // calling the \code{Update} method. -// Software Guide : BeginCodeSnippet classifier->SetModel(svmModel); classifier->SetInput(inputReader->GetOutput()); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// -// After the classification step, we usually want to get the -// results. The classifier gives an output under the form of a sample -// list. This list supports the classical STL iterators. Therefore, we -// will create an output image and fill it up with the results of the -// classification. The pixel type of the output image is the same as -// the one used for the labels. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet + // After the classification step, we usually want to get the + // results. The classifier gives an output under the form of a sample + // list. This list supports the classical STL iterators. Therefore, we + // will create an output image and fill it up with the results of the + // classification. The pixel type of the output image is the same as + // the one used for the labels. -// Software Guide : BeginLatex -// -// We allocate the memory for the output image using the information -// from the input image. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // We allocate the memory for the output image using the information + // from the input image. -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now declare the iterators on the list that we get at the -// output of the classifier as well as the iterator to fill the output image. -// -// Software Guide : EndLatex + // We can now declare the iterators on the list that we get at the + // output of the classifier as well as the iterator to fill the output image. -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet + // We will iterate through the list, get the labels and assign pixel + // values to the output image. -// Software Guide : BeginLatex -// -// We will iterate through the list, get the labels and assign pixel -// values to the output image. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - -// Software Guide : EndCodeSnippet typedef otb::ImageFileWriter<TrainingImageType> WriterType; @@ -275,38 +190,24 @@ int main(int itkNotUsed(argc), char *argv[]) writer->Update(); -// Software Guide : BeginLatex -// -// Only for visualization purposes, we choose a color mapping to the image of -// classes before saving it to a file. The -// \subdoxygen{itk}{Functor}{ScalarToRGBPixelFunctor} class is a special -// function object designed to hash a scalar value into an -// \doxygen{itk}{RGBPixel}. Plugging this functor into the -// \doxygen{itk}{UnaryFunctorImageFilter} creates an image filter for that -// converts scalar images to RGB images. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef itk::RGBPixel<unsigned char> RGBPixelType; - typedef otb::Image<RGBPixelType, 2> RGBImageType; - typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> - ColorMapFunctorType; - typedef itk::UnaryFunctorImageFilter<TrainingImageType, - RGBImageType, - ColorMapFunctorType> ColorMapFilterType; - ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); + // Only for visualization purposes, we choose a color mapping to the image of + // classes before saving it to a file. The + // \subdoxygen{itk}{Functor}{ScalarToRGBPixelFunctor} class is a special + // function object designed to hash a scalar value into an + // \doxygen{itk}{RGBPixel}. Plugging this functor into the + // \doxygen{itk}{UnaryFunctorImageFilter} creates an image filter for that + // converts scalar images to RGB images. + + typedef itk::RGBPixel<unsigned char> RGBPixelType; + typedef otb::Image<RGBPixelType, 2> RGBImageType; + typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType; + typedef itk::UnaryFunctorImageFilter<TrainingImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType; + ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); colormapper->SetInput(classifier->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now create an image file writer and save the image. -// -// Software Guide : EndLatex + // We can now create an image file writer and save the image. -// Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<RGBImageType> WriterRescaledType; WriterRescaledType::Pointer writerRescaled = WriterRescaledType::New(); @@ -315,19 +216,16 @@ int main(int itkNotUsed(argc), char *argv[]) writerRescaled->SetInput(colormapper->GetOutput()); writerRescaled->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// Figure \ref{fig:SVMCLASSMULTI} shows the result of the SVM classification. -// \begin{figure} -// \center -// \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1.eps} -// \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1_SVN_CLASS_MULTI_Rescaled.eps} -// \itkcaption[SVM Image Classification]{Result of the SVM -// classification . Left: RGB image. Right: image of classes.} -// \label{fig:SVMCLASSMULTI} -// \end{figure} -// Software Guide : EndLatex + // Figure \ref{fig:SVMCLASSMULTI} shows the result of the SVM classification. + // \begin{figure} + // \center + // \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1.eps} + // \includegraphics[width=0.45\textwidth]{ROI_QB_MUL_1_SVN_CLASS_MULTI_Rescaled.eps} + // \itkcaption[SVM Image Classification]{Result of the SVM + // classification . Left: RGB image. Right: image of classes.} + // \label{fig:SVMCLASSMULTI} + // \end{figure} return EXIT_SUCCESS; } diff --git a/Examples/Learning/TrainMachineLearningModelFromImagesExample.cxx b/Examples/Learning/TrainMachineLearningModelFromImagesExample.cxx index 1ca5213aca1dd9c6fe8e7287b2d8dcf7770be005..227776c73f5a5ee347b2249d9ad3d5085876c99e 100644 --- a/Examples/Learning/TrainMachineLearningModelFromImagesExample.cxx +++ b/Examples/Learning/TrainMachineLearningModelFromImagesExample.cxx @@ -19,19 +19,15 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_1_ortho.tif}, {VectorData_QB1.shp} -// OUTPUTS: {clLIBSVMModelQB1.libsvm} -// Software Guide : EndCommandLineArgs +/* Example usage: +./TrainMachineLearningModelFromImagesExample Input/QB_1_ortho.tif Input/VectorData_QB1.shp Output/clLIBSVMModelQB1.libsvm +*/ + -// Software Guide : BeginLatex // This example illustrates the use of the // \doxygen{otb}{MachineLearningModel} class. This class allows the // estimation of a classification model (supervised learning) from images. In this example, we will train an SVM // with 4 classes. We start by including the appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet // List sample generator #include "otbListSampleGenerator.h" @@ -40,7 +36,6 @@ // SVM model Estimator #include "otbSVMMachineLearningModel.h" -// Software Guide : EndCodeSnippet // Image @@ -57,35 +52,29 @@ int main(int itkNotUsed(argc), char* argv[]) { - const char* inputImageFileName = argv[1]; + const char* inputImageFileName = argv[1]; const char* trainingShpFileName = argv[2]; const char* outputModelFileName = argv[3]; - typedef unsigned int InputPixelType; - const unsigned int Dimension = 2; - typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; - typedef otb::VectorData<double, 2> VectorDataType; - typedef otb::ImageFileReader<InputImageType> InputReaderType; - typedef otb::VectorDataFileReader<VectorDataType> VectorDataReaderType; - -// Software Guide : BeginLatex -// -// In this framework, we must transform the input samples store in a vector -// data into a \subdoxygen{itk}{Statistics}{ListSample} which is the structure -// compatible with the machine learning classes. On the one hand, we are using feature vectors -// for the characterization of the classes, and on the other hand, the class labels -// are scalar values. We first re-project the input vector data over the input image, using the -// \doxygen{otb}{VectorDataIntoImageProjectionFilter} class. To convert the -// input samples store in a vector data into a -// \subdoxygen{itk}{Statistics}{ListSample}, we use the -// \doxygen{otb}{ListSampleGenerator} class. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet + typedef unsigned int InputPixelType; + const unsigned int Dimension = 2; + typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; + typedef otb::VectorData<double, 2> VectorDataType; + typedef otb::ImageFileReader<InputImageType> InputReaderType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataReaderType; + + // In this framework, we must transform the input samples store in a vector + // data into a \subdoxygen{itk}{Statistics}{ListSample} which is the structure + // compatible with the machine learning classes. On the one hand, we are using feature vectors + // for the characterization of the classes, and on the other hand, the class labels + // are scalar values. We first re-project the input vector data over the input image, using the + // \doxygen{otb}{VectorDataIntoImageProjectionFilter} class. To convert the + // input samples store in a vector data into a + // \subdoxygen{itk}{Statistics}{ListSample}, we use the + // \doxygen{otb}{ListSampleGenerator} class. + // VectorData projection filter - typedef otb::VectorDataIntoImageProjectionFilter<VectorDataType, InputImageType> - VectorDataReprojectionType; + typedef otb::VectorDataIntoImageProjectionFilter<VectorDataType, InputImageType> VectorDataReprojectionType; InputReaderType::Pointer inputReader = InputReaderType::New(); inputReader->SetFileName(inputImageFileName); @@ -109,9 +98,8 @@ int main(int itkNotUsed(argc), char* argv[]) vdreproj->Update(); - typedef otb::ListSampleGenerator<InputImageType, VectorDataType> - ListSampleGeneratorType; - ListSampleGeneratorType::Pointer sampleGenerator; + typedef otb::ListSampleGenerator<InputImageType, VectorDataType> ListSampleGeneratorType; + ListSampleGeneratorType::Pointer sampleGenerator; sampleGenerator = ListSampleGeneratorType::New(); sampleGenerator->SetInput(image); @@ -119,10 +107,9 @@ int main(int itkNotUsed(argc), char* argv[]) sampleGenerator->SetClassKey("Class"); sampleGenerator->Update(); - // Software Guide : EndCodeSnippet - //std::cout << "Number of classes: " << sampleGenerator->GetNumberOfClasses() << std::endl; + // std::cout << "Number of classes: " << sampleGenerator->GetNumberOfClasses() << std::endl; // typedef ListSampleGeneratorType::ListSampleType ListSampleType; // typedef otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType> ShiftScaleFilterType; @@ -135,24 +122,17 @@ int main(int itkNotUsed(argc), char* argv[]) // trainingShiftScaleFilter->Update(); -// Software Guide : BeginLatex -// -// Now, we need to declare the machine learning model which will be used by the -// classifier. In this example, we train an SVM model. The -// \doxygen{otb}{SVMMachineLearningModel} class inherits from the pure virtual -// class \doxygen{otb}{MachineLearningModel} which is templated over the type of -// values used for the measures and the type of pixels used for the labels. Most -// of the classification and regression algorithms available through this -// interface in OTB is based on the OpenCV library \cite{opencv_library}. Specific methods -// can be used to set classifier parameters. In the case of SVM, we set here the type -// of the kernel. Other parameters are let with their default values. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef otb::SVMMachineLearningModel - <InputImageType::InternalPixelType, - ListSampleGeneratorType::ClassLabelType> SVMType; + // Now, we need to declare the machine learning model which will be used by the + // classifier. In this example, we train an SVM model. The + // \doxygen{otb}{SVMMachineLearningModel} class inherits from the pure virtual + // class \doxygen{otb}{MachineLearningModel} which is templated over the type of + // values used for the measures and the type of pixels used for the labels. Most + // of the classification and regression algorithms available through this + // interface in OTB is based on the OpenCV library \cite{opencv_library}. Specific methods + // can be used to set classifier parameters. In the case of SVM, we set here the type + // of the kernel. Other parameters are let with their default values. + + typedef otb::SVMMachineLearningModel<InputImageType::InternalPixelType, ListSampleGeneratorType::ClassLabelType> SVMType; SVMType::Pointer SVMClassifier = SVMType::New(); @@ -160,30 +140,19 @@ int main(int itkNotUsed(argc), char* argv[]) SVMClassifier->SetTargetListSample(sampleGenerator->GetTrainingListLabel()); SVMClassifier->SetKernelType(CvSVM::LINEAR); - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The machine learning interface is generic and gives access to other classifiers. We now train the -// SVM model using the \code{Train} and save the model to a text file using the -// \code{Save} method. -// -// Software Guide : EndLatex + // The machine learning interface is generic and gives access to other classifiers. We now train the + // SVM model using the \code{Train} and save the model to a text file using the + // \code{Save} method. -// Software Guide : BeginCodeSnippet SVMClassifier->Train(); SVMClassifier->Save(outputModelFileName); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// You can now use the \code{Predict} method which takes a -// \subdoxygen{itk}{Statistics}{ListSample} as input and estimates the label of each -// input sample using the model. Finally, the -// \doxygen{otb}{ImageClassificationModel} inherits from the -// \doxygen{itk}{ImageToImageFilter} and allows classifying pixels in the -// input image by predicting their labels using a model. -// -// Software Guide : EndLatex + // You can now use the \code{Predict} method which takes a + // \subdoxygen{itk}{Statistics}{ListSample} as input and estimates the label of each + // input sample using the model. Finally, the + // \doxygen{otb}{ImageClassificationModel} inherits from the + // \doxygen{itk}{ImageToImageFilter} and allows classifying pixels in the + // input image by predicting their labels using a model. } diff --git a/Examples/Learning/TrainMachineLearningModelFromSamplesExample.cxx b/Examples/Learning/TrainMachineLearningModelFromSamplesExample.cxx index ec68f8d043ce16fc06d2bc49a0a5bff6f79c8ff0..76ce9fcd0a67f990a2786719d2cb8a1a05b20071 100644 --- a/Examples/Learning/TrainMachineLearningModelFromSamplesExample.cxx +++ b/Examples/Learning/TrainMachineLearningModelFromSamplesExample.cxx @@ -19,21 +19,16 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {1000}, {4}, {5}, {121212} -// OUTPUTS: {clSVMModelFromSamples.svm} -// Software Guide : EndCommandLineArgs +/* Example usage: +./TrainMachineLearningModelFromSamplesExample Input/1000 Input/4 Input/5 Input/121212 Output/clSVMModelFromSamples.svm +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{SVMMachineLearningModel} class, which inherits from the // \doxygen{otb}{MachineLearningModel} class. This class allows the // estimation of a classification model (supervised learning) from samples. In this example, we will train an SVM model // with 4 output classes, from 1000 randomly generated training samples, each of them having 7 components. // We start by including the appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet // List sample generator #include "otbListSampleGenerator.h" @@ -41,7 +36,6 @@ // SVM model Estimator #include "otbSVMMachineLearningModel.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) @@ -56,14 +50,12 @@ int main(int argc, char* argv[]) */ if (argc != 2) - { + { std::cerr << "Usage: " << argv[0] << " outputModelFileName" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex // The input parameters of the sample generator and of the SVM classifier are initialized. - // Software Guide : EndLatex /* int nbSamples = atoi(argv[1]); @@ -72,91 +64,78 @@ int main(int argc, char* argv[]) unsigned int inputSeed = atoi(argv[4]); */ - // Software Guide : BeginCodeSnippet - int nbSamples = 1000; + int nbSamples = 1000; int nbSampleComponents = 7; - int nbClasses = 4; - // Software Guide : EndCodeSnippet + int nbClasses = 4; -// unsigned int inputSeed = 121212; - const char* outputModelFileName = argv[1]; //argv[5]; + // unsigned int inputSeed = 121212; + const char* outputModelFileName = argv[1]; // argv[5]; - // Software Guide : BeginLatex // Two lists are generated into a \subdoxygen{itk}{Statistics}{ListSample} which is the structure // used to handle both lists of samples and of labels for the machine learning classes derived from // \doxygen{otb}{MachineLearningModel}. The first list is composed of feature vectors representing // multi-component samples, and the second one is filled with their corresponding class labels. The // list of labels is composed of scalar values. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet // Input related typedefs - typedef float InputValueType; - typedef itk::VariableLengthVector<InputValueType> InputSampleType; + typedef float InputValueType; + typedef itk::VariableLengthVector<InputValueType> InputSampleType; typedef itk::Statistics::ListSample<InputSampleType> InputListSampleType; // Target related typedefs - typedef int TargetValueType; - typedef itk::FixedArray<TargetValueType, 1> TargetSampleType; + typedef int TargetValueType; + typedef itk::FixedArray<TargetValueType, 1> TargetSampleType; typedef itk::Statistics::ListSample<TargetSampleType> TargetListSampleType; - InputListSampleType::Pointer InputListSample = InputListSampleType::New(); + InputListSampleType::Pointer InputListSample = InputListSampleType::New(); TargetListSampleType::Pointer TargetListSample = TargetListSampleType::New(); InputListSample->SetMeasurementVectorSize(nbSampleComponents); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // In this example, the list of multi-component training samples is randomly filled with a random number // generator based on the \subdoxygen{itk}{Statistics}{MersenneTwisterRandomVariateGenerator} class. // Each component's value is generated from a normal law centered around the corresponding class label of // each sample multiplied by 100, with a standard deviation of 10. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randGen; randGen = itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance(); // Filling the two input training lists for (int i = 0; i < nbSamples; ++i) - { + { InputSampleType sample; TargetValueType label = (i % nbClasses) + 1; // Multi-component sample randomly filled from a normal law for each component sample.SetSize(nbSampleComponents); for (int itComp = 0; itComp < nbSampleComponents; ++itComp) - { + { sample[itComp] = randGen->GetNormalVariate(100 * label, 10); - } + } InputListSample->PushBack(sample); TargetListSample->PushBack(label); - } - // Software Guide : EndCodeSnippet + } // Displays the corresponding values (not into the Software Guide) for (int i = 0; i < nbSamples; ++i) - { + { std::cout << i + 1 << "-label = " << TargetListSample->GetMeasurementVector(i) << std::endl; std::cout << "sample = " << InputListSample->GetMeasurementVector(i) << std::endl << std::endl; - } + } + + // Once both sample and label lists are generated, the second step consists in + // declaring the machine learning classifier. In our case we use an SVM model + // with the help of the \doxygen{otb}{SVMMachineLearningModel} class which is + // derived from the \doxygen{otb}{MachineLearningModel} class. + // This pure virtual class is based on the machine learning framework of the + // OpenCV library (\cite{opencv_library}) which handles other classifiers than + // the SVM. - // Software Guide : BeginLatex - //Once both sample and label lists are generated, the second step consists in - //declaring the machine learning classifier. In our case we use an SVM model - //with the help of the \doxygen{otb}{SVMMachineLearningModel} class which is - //derived from the \doxygen{otb}{MachineLearningModel} class. - //This pure virtual class is based on the machine learning framework of the - //OpenCV library (\cite{opencv_library}) which handles other classifiers than - //the SVM. - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet typedef otb::SVMMachineLearningModel<InputValueType, TargetValueType> SVMType; SVMType::Pointer SVMClassifier = SVMType::New(); @@ -165,22 +144,14 @@ int main(int argc, char* argv[]) SVMClassifier->SetTargetListSample(TargetListSample); SVMClassifier->SetKernelType(CvSVM::LINEAR); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Once the classifier is parametrized with both input lists and default parameters, except // for the kernel type in our example of SVM model estimation, the model // training is computed with the \code{Train} method. Finally, the \code{Save} method // exports the model to a text file. All the available classifiers based on OpenCV are // implemented with these interfaces. Like for the SVM model training, the other classifiers // can be parametrized with specific settings. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SVMClassifier->Train(); SVMClassifier->Save(outputModelFileName); - // Software Guide : EndCodeSnippet - } diff --git a/Examples/Markov/MarkovClassification1Example.cxx b/Examples/Markov/MarkovClassification1Example.cxx index ca9b64cba8dd7e37d2fa7f74edc2c1ea4f9a9abd..d1b5cf4b331eccaf73ee728058fecb354b0c4eac 100644 --- a/Examples/Markov/MarkovClassification1Example.cxx +++ b/Examples/Markov/MarkovClassification1Example.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./MarkovClassification1Example Input/QB_Suburb.png Output/MarkovRandomField1.png 1.0 20 1.0 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {MarkovRandomField1.png} -// 1.0 20 1.0 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the details of the \doxygen{otb}{MarkovRandomFieldFilter}. // This filter is an application of the Markov Random Fields for classification, // segmentation or restoration. @@ -38,8 +34,6 @@ // regularization energy is defined by a Potts model and the fidelity by a // Gaussian model. // -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -48,116 +42,76 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginLatex -// // The first step toward the use of this filter is the inclusion of the proper // header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMRFEnergyPotts.h" #include "otbMRFEnergyGaussianClassification.h" #include "otbMRFOptimizerMetropolis.h" #include "otbMRFSamplerRandom.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 7) - { + { std::cerr << "Missing Parameters " << argc << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << " inputImage output lambda iterations optimizerTemperature" << - std::endl; + std::cerr << " inputImage output lambda iterations optimizerTemperature" << std::endl; std::cerr << " useRandomValue" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We // choose to make all computations with double precision. // The labelled image is of type unsigned char which allows up to 256 different // classes. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef double InternalPixelType; typedef unsigned char LabelledPixelType; typedef otb::Image<InternalPixelType, Dimension> InputImageType; typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define a reader for the image to be classified, an initialization for the // classification (which could be random) and a writer for the final // classification. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<LabelledImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally, we define the different classes necessary for the Markov classification. // A \doxygen{otb}{MarkovRandomFieldFilter} is instantiated, this is the // main class which connect the other to do the Markov classification. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MarkovRandomFieldFilter - <InputImageType, LabelledImageType> MarkovRandomFieldFilterType; - // Software Guide : EndCodeSnippet + typedef otb::MarkovRandomFieldFilter<InputImageType, LabelledImageType> MarkovRandomFieldFilterType; - // Software Guide : BeginLatex - // // An \doxygen{otb}{MRFSamplerRandomMAP}, which derives from the // \doxygen{otb}{MRFSampler}, is instantiated. The sampler is in charge of // proposing a modification for a given site. The // \doxygen{otb}{MRFSamplerRandomMAP}, randomly pick one possible value // according to the MAP probability. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::MRFSamplerRandom<InputImageType, LabelledImageType> SamplerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // An \doxygen{otb}{MRFOptimizerMetropoli}, which derives from the // \doxygen{otb}{MRFOptimizer}, is instantiated. The optimizer is in charge // of accepting or rejecting the value proposed by the sampler. The // \doxygen{otb}{MRFSamplerRandomMAP}, accept the proposal according to the // variation of energy it causes and a temperature parameter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::MRFOptimizerMetropolis OptimizerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Two energy, deriving from the \doxygen{otb}{MRFEnergy} class need to be instantiated. One energy // is required for the regularization, taking into account the relashionship between neighborhing pixels // in the classified image. Here it is done with the \doxygen{otb}{MRFEnergyPotts} which implement @@ -165,72 +119,47 @@ int main(int argc, char* argv[]) // // The second energy is for the fidelity to the original data. Here it is done with an // \doxygen{otb}{MRFEnergyGaussianClassification} class, which defines a gaussian model for the data. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MRFEnergyPotts - <LabelledImageType, LabelledImageType> EnergyRegularizationType; - typedef otb::MRFEnergyGaussianClassification - <InputImageType, LabelledImageType> EnergyFidelityType; - // Software Guide : EndCodeSnippet + typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyRegularizationType; + typedef otb::MRFEnergyGaussianClassification<InputImageType, LabelledImageType> EnergyFidelityType; - // Software Guide : BeginLatex - // // The different filters composing our pipeline are created by invoking their // \code{New()} methods, assigning the results to smart pointers. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - MarkovRandomFieldFilterType::Pointer markovFilter = - MarkovRandomFieldFilterType::New(); - EnergyRegularizationType::Pointer energyRegularization = - EnergyRegularizationType::New(); - EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); - OptimizerType::Pointer optimizer = OptimizerType::New(); - SamplerType::Pointer sampler = SamplerType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); + EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); + EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); + OptimizerType::Pointer optimizer = OptimizerType::New(); + SamplerType::Pointer sampler = SamplerType::New(); + // Parameter for the \doxygen{otb}{MRFEnergyGaussianClassification} class, meand // and standard deviation are created. - // - // Software Guide : EndLatex - if ((bool) (atoi(argv[6])) == true) - { + if ((bool)(atoi(argv[6])) == true) + { // Overpass random calculation(for test only): sampler->InitializeSeed(0); optimizer->InitializeSeed(1); markovFilter->InitializeSeed(2); - } + } - // Software Guide : BeginCodeSnippet unsigned int nClass = 4; energyFidelity->SetNumberOfParameters(2 * nClass); EnergyFidelityType::ParametersType parameters; parameters.SetSize(energyFidelity->GetNumberOfParameters()); - parameters[0] = 10.0; //Class 0 mean - parameters[1] = 10.0; //Class 0 stdev - parameters[2] = 80.0; //Class 1 mean - parameters[3] = 10.0; //Class 1 stdev - parameters[4] = 150.0; //Class 2 mean - parameters[5] = 10.0; //Class 2 stdev - parameters[6] = 220.0; //Class 3 mean - parameters[7] = 10.0; //Class 3 stde + parameters[0] = 10.0; // Class 0 mean + parameters[1] = 10.0; // Class 0 stdev + parameters[2] = 80.0; // Class 1 mean + parameters[3] = 10.0; // Class 1 stdev + parameters[4] = 150.0; // Class 2 mean + parameters[5] = 10.0; // Class 2 stdev + parameters[6] = 220.0; // Class 3 mean + parameters[7] = 10.0; // Class 3 stde energyFidelity->SetParameters(parameters); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Parameters are given to the different class an the sampler, optimizer and // energies are connected with the Markov filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet OptimizerType::ParametersType param(1); param.Fill(atof(argv[5])); optimizer->SetParameters(param); @@ -244,41 +173,25 @@ int main(int argc, char* argv[]) markovFilter->SetEnergyFidelity(energyFidelity); markovFilter->SetOptimizer(optimizer); markovFilter->SetSampler(sampler); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The pipeline is connected. An \doxygen{itk}{RescaleIntensityImageFilter} // rescale the classified image before saving it. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet markovFilter->SetInput(reader->GetOutput()); - typedef itk::RescaleIntensityImageFilter - <LabelledImageType, LabelledImageType> RescaleType; - RescaleType::Pointer rescaleFilter = RescaleType::New(); + typedef itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType> RescaleType; + RescaleType::Pointer rescaleFilter = RescaleType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); rescaleFilter->SetInput(markovFilter->GetOutput()); writer->SetInput(rescaleFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Finally, the pipeline execution is trigerred. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:MRF_CLASSIFICATION1} shows the output of the Markov Random // Field classification after 20 iterations with a // random sampler and a Metropolis optimizer. @@ -294,9 +207,6 @@ int main(int argc, char* argv[]) // classification.} // \label{fig:MRF_CLASSIFICATION1} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Markov/MarkovClassification2Example.cxx b/Examples/Markov/MarkovClassification2Example.cxx index 0e6a230d9c93abcd1865b45d03fbad85eafcd0d5..533e8e7e4709e3ce6fb1113112dc9d10d7d35cf3 100644 --- a/Examples/Markov/MarkovClassification2Example.cxx +++ b/Examples/Markov/MarkovClassification2Example.cxx @@ -19,23 +19,17 @@ */ +/* Example usage: +./MarkovClassification2Example Input/QB_Suburb.png Output/MarkovRandomField2.png 1.0 5 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {MarkovRandomField2.png} -// 1.0 5 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // Using a similar structure as the previous program and the same energy // function, we are now going to slightly alter the program to use a // different sampler and optimizer. The proposed sample is proposed // randomly according to the MAP probability and the optimizer is the // ICM which accept the proposed sample if it enable a reduction of // the energy. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -44,31 +38,25 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginLatex -// // First, we need to include header specific to these class: -// -// Software Guide : EndLatex #include "otbMRFEnergyPotts.h" #include "otbMRFEnergyGaussianClassification.h" -// Software Guide : BeginCodeSnippet #include "otbMRFSamplerRandomMAP.h" #include "otbMRFOptimizerICM.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 6) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; std::cerr << " inputImage output lambda iterations" << std::endl; std::cerr << " useRandomValue" << std::endl; return 1; - } + } const unsigned int Dimension = 2; @@ -83,71 +71,53 @@ int main(int argc, char* argv[]) ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - typedef otb::MarkovRandomFieldFilter - <InputImageType, LabelledImageType> MarkovRandomFieldFilterType; + typedef otb::MarkovRandomFieldFilter<InputImageType, LabelledImageType> MarkovRandomFieldFilterType; - // Software Guide : BeginLatex - // // And to declare these new type: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MRFSamplerRandomMAP<InputImageType, - LabelledImageType> SamplerType; -// typedef otb::MRFSamplerRandom< InputImageType, LabelledImageType> SamplerType; -// Software Guide : EndCodeSnippet + typedef otb::MRFSamplerRandomMAP<InputImageType, LabelledImageType> SamplerType; + // typedef otb::MRFSamplerRandom< InputImageType, LabelledImageType> SamplerType; - // Software Guide : BeginCodeSnippet typedef otb::MRFOptimizerICM OptimizerType; - // Software Guide : EndCodeSnippet - - typedef otb::MRFEnergyPotts - <LabelledImageType, LabelledImageType> EnergyRegularizationType; - typedef otb::MRFEnergyGaussianClassification - <InputImageType, LabelledImageType> EnergyFidelityType; - - MarkovRandomFieldFilterType::Pointer markovFilter = - MarkovRandomFieldFilterType::New(); - EnergyRegularizationType::Pointer energyRegularization = - EnergyRegularizationType::New(); - EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); - OptimizerType::Pointer optimizer = OptimizerType::New(); - SamplerType::Pointer sampler = SamplerType::New(); - - if ((bool) (atoi(argv[5])) == true) - { + + typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyRegularizationType; + typedef otb::MRFEnergyGaussianClassification<InputImageType, LabelledImageType> EnergyFidelityType; + + MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); + EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); + EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); + OptimizerType::Pointer optimizer = OptimizerType::New(); + SamplerType::Pointer sampler = SamplerType::New(); + + if ((bool)(atoi(argv[5])) == true) + { // Overpass random calculation(for test only): sampler->InitializeSeed(0); markovFilter->InitializeSeed(1); - } + } unsigned int nClass = 4; energyFidelity->SetNumberOfParameters(2 * nClass); EnergyFidelityType::ParametersType parameters; parameters.SetSize(energyFidelity->GetNumberOfParameters()); - parameters[0] = 10.0; //Class 0 mean - parameters[1] = 10.0; //Class 0 stdev - parameters[2] = 80.0; //Class 1 mean - parameters[3] = 10.0; //Class 1 stdev - parameters[4] = 150.0; //Class 2 mean - parameters[5] = 10.0; //Class 2 stdev - parameters[6] = 220.0; //Class 3 mean - parameters[7] = 10.0; //Class 3 stde + parameters[0] = 10.0; // Class 0 mean + parameters[1] = 10.0; // Class 0 stdev + parameters[2] = 80.0; // Class 1 mean + parameters[3] = 10.0; // Class 1 stdev + parameters[4] = 150.0; // Class 2 mean + parameters[5] = 10.0; // Class 2 stdev + parameters[6] = 220.0; // Class 3 mean + parameters[7] = 10.0; // Class 3 stde energyFidelity->SetParameters(parameters); - // Software Guide : BeginLatex - // // As the \doxygen{otb}{MRFOptimizerICM} does not have any parameters, // the call to \code{optimizer->SetParameters()} must be removed - // - // Software Guide : EndLatex markovFilter->SetNumberOfClasses(nClass); markovFilter->SetMaximumNumberOfIterations(atoi(argv[4])); @@ -162,9 +132,8 @@ int main(int argc, char* argv[]) markovFilter->SetInput(reader->GetOutput()); - typedef itk::RescaleIntensityImageFilter - <LabelledImageType, LabelledImageType> RescaleType; - RescaleType::Pointer rescaleFilter = RescaleType::New(); + typedef itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType> RescaleType; + RescaleType::Pointer rescaleFilter = RescaleType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); @@ -174,14 +143,8 @@ int main(int argc, char* argv[]) writer->Update(); - // Software Guide : BeginLatex - // // Apart from these, no further modification is required. - // - // Software Guide : EndLatex - // Software Guide : BeginLatex - // // Figure~\ref{fig:MRF_CLASSIFICATION2} shows the output of the Markov Random // Field classification after 5 iterations with a // MAP random sampler and an ICM optimizer. @@ -197,9 +160,6 @@ int main(int argc, char* argv[]) // classification.} // \label{fig:MRF_CLASSIFICATION2} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Markov/MarkovClassification3Example.cxx b/Examples/Markov/MarkovClassification3Example.cxx index 86ecb41cc8c887dee02fd1064b29e89e2975b64c..b72cc339d316c6535ebf5dfc51479cd05451bfbf 100644 --- a/Examples/Markov/MarkovClassification3Example.cxx +++ b/Examples/Markov/MarkovClassification3Example.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./MarkovClassification3Example Input/QB_Suburb.png Output/MarkovRandomField3_gray_value.png Output/MarkovRandomField3_color_value.png 1.0 20 1.0 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {MarkovRandomField3_gray_value.png}, {MarkovRandomField3_color_value.png} -// 1.0 20 1.0 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the details of the MarkovRandomFieldFilter by using the Fisher distribution // to model the likelihood energy. // This filter is an application of the Markov Random Fields for classification. @@ -40,8 +36,6 @@ // The parameter of the Fisher distribution was determined for each class in a supervised step. // ( See the File OtbParameterEstimatioOfFisherDistribution ) // This example is a contribution from Jan Wegner. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" @@ -61,100 +55,68 @@ #include "otbMRFSamplerRandom.h" -int main(int argc, char* argv[] ) +int main(int argc, char* argv[]) { - if( argc != 8 ) - { - std::cerr << "Missing Parameters "<< argc << std::endl; + if (argc != 8) + { + std::cerr << "Missing Parameters " << argc << std::endl; std::cerr << "Usage: " << argv[0]; std::cerr << " inputImage output_gray_label output_color_label lambda iterations " - "optimizerTemperature useRandomValue " << std::endl; + "optimizerTemperature useRandomValue " + << std::endl; return 1; - } - // Software Guide : BeginLatex - // + } // Then we must decide what pixel type to use for the image. We // choose to make all computations with double precision. // The labeled image is of type unsigned char which allows up to 256 different // classes. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double InternalPixelType; typedef unsigned char LabelledPixelType; - typedef otb::Image<InternalPixelType, Dimension> InputImageType; - typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType; - // Software Guide : EndCodeSnippet + typedef otb::Image<InternalPixelType, Dimension> InputImageType; + typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType; - // Software Guide : BeginLatex - // // We define a reader for the image to be classified, an initialization for the // classification (which could be random) and a writer for the final // classification. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageFileReader< InputImageType > ReaderType; - typedef otb::ImageFileWriter< LabelledImageType > WriterType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<LabelledImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; - const char * outputRescaledImageFileName = argv[3]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; + const char* outputRescaledImageFileName = argv[3]; - reader->SetFileName( inputFilename ); - writer->SetFileName( outputFilename ); + reader->SetFileName(inputFilename); + writer->SetFileName(outputFilename); - // Software Guide : BeginLatex - // // Finally, we define the different classes necessary for the Markov classification. // A MarkovRandomFieldFilter is instantiated, this is the // main class which connect the other to do the Markov classification. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MarkovRandomFieldFilter - <InputImageType, LabelledImageType> MarkovRandomFieldFilterType; - // Software Guide : EndCodeSnippet + typedef otb::MarkovRandomFieldFilter<InputImageType, LabelledImageType> MarkovRandomFieldFilterType; - // Software Guide : BeginLatex - // // An MRFSamplerRandomMAP, which derives from the // MRFSampler, is instantiated. The sampler is in charge of // proposing a modification for a given site. The // MRFSamplerRandomMAP, randomly pick one possible value // according to the MAP probability. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MRFSamplerRandom< InputImageType, LabelledImageType> SamplerType; - // Software Guide : EndCodeSnippet + typedef otb::MRFSamplerRandom<InputImageType, LabelledImageType> SamplerType; - // Software Guide : BeginLatex - // // An MRFOptimizerMetropolis, which derives from the // MRFOptimizer, is instantiated. The optimizer is in charge // of accepting or rejecting the value proposed by the sampler. The // MRFSamplerRandomMAP, accept the proposal according to the // variation of energy it causes and a temperature parameter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::MRFOptimizerMetropolis OptimizerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Two energy, deriving from the MRFEnergy class need to be instantiated. One energy // is required for the regularization, taking into account the relationship between neighboring pixels // in the classified image. Here it is done with the MRFEnergyPotts, which implements @@ -162,80 +124,57 @@ int main(int argc, char* argv[] ) // // The second energy is used for the fidelity to the original data. Here it is done with a // MRFEnergyFisherClassification class, which defines a Fisher distribution to model the data. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MRFEnergyPotts - <LabelledImageType, LabelledImageType> EnergyRegularizationType; - typedef otb::MRFEnergyFisherClassification - <InputImageType, LabelledImageType> EnergyFidelityType; - // Software Guide : EndCodeSnippet + typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyRegularizationType; + typedef otb::MRFEnergyFisherClassification<InputImageType, LabelledImageType> EnergyFidelityType; - // Software Guide : BeginLatex - // // The different filters composing our pipeline are created by invoking their // New() methods, assigning the results to smart pointers. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); - EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); - EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); - OptimizerType::Pointer optimizer = OptimizerType::New(); - SamplerType::Pointer sampler = SamplerType::New(); - // Software Guide : EndCodeSnippet + MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); + EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); + EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); + OptimizerType::Pointer optimizer = OptimizerType::New(); + SamplerType::Pointer sampler = SamplerType::New(); - // Software Guide : BeginLatex - // // Parameter for the MRFEnergyFisherClassification class are created. The shape parameters M, L // and the weighting parameter mu are computed in a supervised step - // - // Software Guide : EndLatex if ((bool)(atoi(argv[6])) == true) - { + { // Overpass random calculation(for test only): sampler->InitializeSeed(0); optimizer->InitializeSeed(1); markovFilter->InitializeSeed(1); - } + } - // Software Guide : BeginCodeSnippet - unsigned int nClass =4; - energyFidelity->SetNumberOfParameters(3*nClass); + unsigned int nClass = 4; + energyFidelity->SetNumberOfParameters(3 * nClass); EnergyFidelityType::ParametersType parameters; parameters.SetSize(energyFidelity->GetNumberOfParameters()); - //Class 0 - parameters[0] = 12.353042; //Class 0 mu - parameters[1] = 2.156422; //Class 0 L - parameters[2] = 4.920403; //Class 0 M - //Class 1 - parameters[3] = 72.068291; //Class 1 mu - parameters[4] = 11.000000; //Class 1 L - parameters[5] = 50.950001; //Class 1 M - //Class 2 - parameters[6] = 146.665985; //Class 2 mu - parameters[7] = 11.000000; //Class 2 L - parameters[8] = 50.900002; //Class 2 M - //Class 3 - parameters[9] = 200.010132; //Class 3 mu - parameters[10] = 11.000000; //Class 3 L - parameters[11] = 50.950001; //Class 3 M + // Class 0 + parameters[0] = 12.353042; // Class 0 mu + parameters[1] = 2.156422; // Class 0 L + parameters[2] = 4.920403; // Class 0 M + // Class 1 + parameters[3] = 72.068291; // Class 1 mu + parameters[4] = 11.000000; // Class 1 L + parameters[5] = 50.950001; // Class 1 M + // Class 2 + parameters[6] = 146.665985; // Class 2 mu + parameters[7] = 11.000000; // Class 2 L + parameters[8] = 50.900002; // Class 2 M + // Class 3 + parameters[9] = 200.010132; // Class 3 mu + parameters[10] = 11.000000; // Class 3 L + parameters[11] = 50.950001; // Class 3 M energyFidelity->SetParameters(parameters); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Parameters are given to the different classes and the sampler, optimizer and // energies are connected with the Markov filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet OptimizerType::ParametersType param(1); param.Fill(atof(argv[6])); optimizer->SetParameters(param); @@ -249,58 +188,42 @@ int main(int argc, char* argv[] ) markovFilter->SetEnergyFidelity(energyFidelity); markovFilter->SetOptimizer(optimizer); markovFilter->SetSampler(sampler); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The pipeline is connected. An itkRescaleIntensityImageFilter // rescales the classified image before saving it. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet markovFilter->SetInput(reader->GetOutput()); - typedef itk::RescaleIntensityImageFilter - < LabelledImageType, LabelledImageType > RescaleType; - RescaleType::Pointer rescaleFilter = RescaleType::New(); + typedef itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType> RescaleType; + RescaleType::Pointer rescaleFilter = RescaleType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); - rescaleFilter->SetInput( markovFilter->GetOutput() ); + rescaleFilter->SetInput(markovFilter->GetOutput()); - writer->SetInput( rescaleFilter->GetOutput() ); + writer->SetInput(rescaleFilter->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - //convert output image to color - typedef itk::RGBPixel<unsigned char> RGBPixelType; - typedef otb::Image<RGBPixelType, 2> RGBImageType; - typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType; + // convert output image to color + typedef itk::RGBPixel<unsigned char> RGBPixelType; + typedef otb::Image<RGBPixelType, 2> RGBImageType; + typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType; - typedef itk::UnaryFunctorImageFilter< LabelledImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType; - ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); + typedef itk::UnaryFunctorImageFilter<LabelledImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType; + ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); - colormapper->SetInput( rescaleFilter->GetOutput() ); - // Software Guide : BeginLatex - // + colormapper->SetInput(rescaleFilter->GetOutput()); // We can now create an image file writer and save the image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<RGBImageType> WriterRescaledType; WriterRescaledType::Pointer writerRescaled = WriterRescaledType::New(); - writerRescaled->SetFileName( outputRescaledImageFileName ); - writerRescaled->SetInput( colormapper->GetOutput() ); + writerRescaled->SetFileName(outputRescaledImageFileName); + writerRescaled->SetInput(colormapper->GetOutput()); writerRescaled->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Figure~\ref{fig:MRF_CLASSIFICATION3} shows the output of the Markov Random // Field classification into four classes using the // Fisher-distribution as likelihood term. @@ -316,9 +239,6 @@ int main(int argc, char* argv[] ) // classification.} // \label{fig:MRF_CLASSIFICATION3} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Markov/MarkovRegularizationExample.cxx b/Examples/Markov/MarkovRegularizationExample.cxx index 6e5fc8562815eac96d7d5a71742fadce1a8fcb28..8f23044653549c4e058f28bc732f35841df67403 100644 --- a/Examples/Markov/MarkovRegularizationExample.cxx +++ b/Examples/Markov/MarkovRegularizationExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./MarkovRegularizationExample Input/ROI_QB_MUL_1_SVN_CLASS_MULTI.png Output/MarkovRegularization.png Output/MarkovRegularization-scaled.png 0.2 20 0.0 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROI_QB_MUL_1_SVN_CLASS_MULTI.png} -// OUTPUTS: {MarkovRegularization.png}, {MarkovRegularization-scaled.png} -// 0.2 20 0.0 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{MarkovRandomFieldFilter}. // to regularize a classification obtained previously by another classifier. Here // we will apply the regularization to the output of an SVM classifier presented @@ -41,8 +37,6 @@ // program structure to use the MRF framework, we are not going to repeat the entire // example. However, remember you can find the full source code for this example // in your OTB source directory. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -60,15 +54,13 @@ int main(int argc, char* argv[]) { if (argc != 8) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputClassificationImage outputClassification outputClassificationScaled lambda iterations temperature " - << std::endl; + std::cerr << " inputClassificationImage outputClassification outputClassificationScaled lambda iterations temperature " << std::endl; std::cerr << " useRandomValue" << std::endl; return 1; - } + } const unsigned int Dimension = 2; @@ -81,60 +73,47 @@ int main(int argc, char* argv[]) ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; - const char * outputScaledFilename = argv[3]; + const char* inputFilename = argv[1]; + const char* outputFilename = argv[2]; + const char* outputScaledFilename = argv[3]; reader->SetFileName(inputFilename); writer->SetFileName(outputFilename); - typedef otb::MarkovRandomFieldFilter - <LabelledImageType, LabelledImageType> MarkovRandomFieldFilterType; + typedef otb::MarkovRandomFieldFilter<LabelledImageType, LabelledImageType> MarkovRandomFieldFilterType; - typedef otb::MRFSamplerRandom<LabelledImageType, - LabelledImageType> SamplerType; + typedef otb::MRFSamplerRandom<LabelledImageType, LabelledImageType> SamplerType; typedef otb::MRFOptimizerMetropolis OptimizerType; - typedef otb::MRFEnergyPotts - <LabelledImageType, LabelledImageType> EnergyRegularizationType; - typedef otb::MRFEnergyPotts - <LabelledImageType, LabelledImageType> EnergyFidelityType; - - MarkovRandomFieldFilterType::Pointer markovFilter - = MarkovRandomFieldFilterType::New(); - EnergyRegularizationType::Pointer energyRegularization - = EnergyRegularizationType::New(); - EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); - OptimizerType::Pointer optimizer = OptimizerType::New(); - SamplerType::Pointer sampler = SamplerType::New(); - - if ((bool) (atoi(argv[7])) == true) - { + typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyRegularizationType; + typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyFidelityType; + + MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); + EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); + EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); + OptimizerType::Pointer optimizer = OptimizerType::New(); + SamplerType::Pointer sampler = SamplerType::New(); + + if ((bool)(atoi(argv[7])) == true) + { // Overpass random calculation(for test only): sampler->InitializeSeed(0); optimizer->InitializeSeed(1); markovFilter->InitializeSeed(2); - } + } - // Software Guide : BeginLatex - // // To find the number of classes available in the original image we use the // \doxygen{itk}{LabelStatisticsImageFilter} and more particularly the method // \code{GetNumberOfLabels()}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::LabelStatisticsImageFilter - <LabelledImageType, LabelledImageType> LabelledStatType; - LabelledStatType::Pointer labelledStat = LabelledStatType::New(); + typedef itk::LabelStatisticsImageFilter<LabelledImageType, LabelledImageType> LabelledStatType; + LabelledStatType::Pointer labelledStat = LabelledStatType::New(); labelledStat->SetInput(reader->GetOutput()); labelledStat->SetLabelInput(reader->GetOutput()); labelledStat->Update(); unsigned int nClass = labelledStat->GetNumberOfLabels(); - // Software Guide : EndCodeSnippet optimizer->SetSingleParameter(0.0); markovFilter->SetNumberOfClasses(nClass); @@ -155,9 +134,8 @@ int main(int argc, char* argv[]) writer->Update(); - typedef itk::RescaleIntensityImageFilter - <LabelledImageType, LabelledImageType> RescaleType; - RescaleType::Pointer rescaleFilter = RescaleType::New(); + typedef itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType> RescaleType; + RescaleType::Pointer rescaleFilter = RescaleType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); @@ -169,8 +147,6 @@ int main(int argc, char* argv[]) writer->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:MRF_REGULARIZATION} shows the output of the Markov Random // Field regularization on the classification output of another method. // @@ -184,9 +160,6 @@ int main(int argc, char* argv[]) // classification} // \label{fig:MRF_REGULARIZATION} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Markov/MarkovRestorationExample.cxx b/Examples/Markov/MarkovRestorationExample.cxx index 856cbd10c2cca1579a6919ed9069bc9a950b465b..7bdb98a213b59d461eecc75120c8c3c8406b5303 100644 --- a/Examples/Markov/MarkovRestorationExample.cxx +++ b/Examples/Markov/MarkovRestorationExample.cxx @@ -19,15 +19,11 @@ */ +/* Example usage: +./MarkovRestorationExample Input/QB_Suburb.png Input/QB_Suburb.png Output/MarkovRestoration.png 10.0 30 1.0 1 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png}, {QB_Suburb.png} -// OUTPUTS: {MarkovRestoration.png} -// 10.0 30 1.0 1 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // The Markov Random Field framework can be used to apply an edge preserving // filtering, thus playing a role of restoration. // @@ -47,8 +43,6 @@ // // The starting state of the Markov Random Field is given by the image itself // as the final state should not be too far from it. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -57,130 +51,86 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginLatex -// // The first step toward the use of this filter is the inclusion of the proper // header files: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMRFEnergyEdgeFidelity.h" #include "otbMRFEnergyGaussian.h" #include "otbMRFOptimizerMetropolis.h" #include "otbMRFSamplerRandom.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 8) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputImage inputInitialization output lambda iterations optimizerTemperature" - << std::endl; + std::cerr << " inputImage inputInitialization output lambda iterations optimizerTemperature" << std::endl; std::cerr << " useRandomValue" << std::endl; return 1; - } + } -// Software Guide : BeginLatex -// -// We declare the usual types: -// -// Software Guide : EndLatex + // We declare the usual types: - // Software Guide : BeginCodeSnippet const unsigned int Dimension = 2; typedef double InternalPixelType; typedef unsigned char LabelledPixelType; typedef otb::Image<InternalPixelType, Dimension> InputImageType; typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We need to declare an additional reader for the initial state of the // MRF. This reader has to be instantiated on the LabelledImageType. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileReader<LabelledImageType> ReaderLabelledType; typedef otb::ImageFileWriter<LabelledImageType> WriterType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); ReaderLabelledType::Pointer reader2 = ReaderLabelledType::New(); - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); - const char * inputFilename = argv[1]; - const char * labelledFilename = argv[2]; - const char * outputFilename = argv[3]; + const char* inputFilename = argv[1]; + const char* labelledFilename = argv[2]; + const char* outputFilename = argv[3]; reader->SetFileName(inputFilename); reader2->SetFileName(labelledFilename); writer->SetFileName(outputFilename); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare all the necessary types for the MRF: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MarkovRandomFieldFilter - <InputImageType, LabelledImageType> MarkovRandomFieldFilterType; + typedef otb::MarkovRandomFieldFilter<InputImageType, LabelledImageType> MarkovRandomFieldFilterType; typedef otb::MRFSamplerRandom<InputImageType, LabelledImageType> SamplerType; typedef otb::MRFOptimizerMetropolis OptimizerType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The regularization and the fidelity energy are declared and instantiated: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MRFEnergyEdgeFidelity - <LabelledImageType, LabelledImageType> EnergyRegularizationType; - typedef otb::MRFEnergyGaussian - <InputImageType, LabelledImageType> EnergyFidelityType; - // Software Guide : EndCodeSnippet + typedef otb::MRFEnergyEdgeFidelity<LabelledImageType, LabelledImageType> EnergyRegularizationType; + typedef otb::MRFEnergyGaussian<InputImageType, LabelledImageType> EnergyFidelityType; -// Software Guide : BeginCodeSnippet - MarkovRandomFieldFilterType::Pointer markovFilter = - MarkovRandomFieldFilterType::New(); + MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New(); - EnergyRegularizationType::Pointer energyRegularization = - EnergyRegularizationType::New(); - EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); + EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New(); + EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New(); OptimizerType::Pointer optimizer = OptimizerType::New(); - SamplerType::Pointer sampler = SamplerType::New(); - // Software Guide : EndCodeSnippet + SamplerType::Pointer sampler = SamplerType::New(); - if ((bool) (atoi(argv[7])) == true) - { + if ((bool)(atoi(argv[7])) == true) + { // Overpass random calculation(for test only): sampler->InitializeSeed(0); optimizer->InitializeSeed(1); markovFilter->InitializeSeed(2); - } + } - // Software Guide : BeginLatex - // // The number of possible states for each pixel is 256 as the image is assumed // to be coded on one byte and we pass the parameters to the markovFilter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet unsigned int nClass = 256; optimizer->SetSingleParameter(atof(argv[6])); @@ -194,31 +144,18 @@ int main(int argc, char* argv[]) markovFilter->SetEnergyFidelity(energyFidelity); markovFilter->SetOptimizer(optimizer); markovFilter->SetSampler(sampler); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The original state of the MRF filter is passed through the // \code{SetTrainingInput()} method: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet markovFilter->SetTrainingInput(reader2->GetOutput()); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And we plug the pipeline: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet markovFilter->SetInput(reader->GetOutput()); - typedef itk::RescaleIntensityImageFilter - <LabelledImageType, LabelledImageType> RescaleType; - RescaleType::Pointer rescaleFilter = RescaleType::New(); + typedef itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType> RescaleType; + RescaleType::Pointer rescaleFilter = RescaleType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); @@ -227,19 +164,16 @@ int main(int argc, char* argv[]) writer->SetInput(rescaleFilter->GetOutput()); try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& err) - { + { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return -1; - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // Figure~\ref{fig:MRF_RESTORATION} shows the output of the Markov Random // Field restoration. // @@ -253,9 +187,6 @@ int main(int argc, char* argv[]) // with edge preservation.} // \label{fig:MRF_RESTORATION} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/OBIA/HooverMetricsEstimation.cxx b/Examples/OBIA/HooverMetricsEstimation.cxx index 263a4e3aae41c76a1d45c7d1e610db8302330258..3a08bd9d296dcb44264b02a001a28d4418b3af54 100644 --- a/Examples/OBIA/HooverMetricsEstimation.cxx +++ b/Examples/OBIA/HooverMetricsEstimation.cxx @@ -20,14 +20,11 @@ */ +/* Example usage: +./HooverMetricsEstimation Input/maur_GT.tif Input/maur_labelled.tif Output/maur_colored_GT.tif +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {maur_GT.tif}, {maur_labelled.tif} -// OUTPUTS: {maur_colored_GT.tif} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // The following example shows how to compare two segmentations, using Hoover // metrics. For instance, it can be used to compare a segmentation produced // by your algorithm against a partial ground truth segmentation. In this @@ -52,14 +49,10 @@ // Note that a region can be tagged with two types. When the Hoover instance // have been found, the instance filter computes overall scores for each // category : they are the Hoover metrics \footnote{see http://www.trop.mips.uha.fr/pdf/ORASIS-2009.pdf}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbHooverMatrixFilter.h" #include "otbHooverInstanceFilter.h" #include "otbLabelMapToAttributeImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbVectorImage.h" @@ -69,36 +62,30 @@ int main(int argc, char* argv[]) { - if(argc != 4) - { + if (argc != 4) + { std::cerr << "Usage: " << argv[0]; std::cerr << " segmentationGT segmentationMS outputAttributeImage" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex // The filters \doxygen{otb}{HooverMatrixFilter} and \doxygen{otb}{HooverInstanceFilter} // are designed to handle \doxygen{itk}{LabelMap} images, made with \doxygen{otb}{AttributesMapLabelObject}. // This type of label object allows storing generic attributes. Each region can store // a set of attributes: in this case, Hoover instances and metrics will be stored. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::AttributesMapLabelObject<unsigned int, 2, float> LabelObjectType; - typedef itk::LabelMap<LabelObjectType> LabelMapType; - typedef otb::HooverMatrixFilter<LabelMapType> HooverMatrixFilterType; - typedef otb::HooverInstanceFilter<LabelMapType> InstanceFilterType; + typedef itk::LabelMap<LabelObjectType> LabelMapType; + typedef otb::HooverMatrixFilter<LabelMapType> HooverMatrixFilterType; + typedef otb::HooverInstanceFilter<LabelMapType> InstanceFilterType; - typedef otb::Image<unsigned int, 2> ImageType; - typedef itk::LabelImageToLabelMapFilter - <ImageType, LabelMapType> ImageToLabelMapFilterType; + typedef otb::Image<unsigned int, 2> ImageType; + typedef itk::LabelImageToLabelMapFilter<ImageType, LabelMapType> ImageToLabelMapFilterType; - typedef otb::VectorImage<float, 2> VectorImageType; - typedef otb::LabelMapToAttributeImageFilter - <LabelMapType, VectorImageType> AttributeImageFilterType; - // Software Guide : EndCodeSnippet - typedef otb::ImageFileReader<ImageType> ImageReaderType; - typedef otb::ImageFileWriter<VectorImageType> WriterType; + typedef otb::VectorImage<float, 2> VectorImageType; + typedef otb::LabelMapToAttributeImageFilter<LabelMapType, VectorImageType> AttributeImageFilterType; + typedef otb::ImageFileReader<ImageType> ImageReaderType; + typedef otb::ImageFileWriter<VectorImageType> WriterType; ImageReaderType::Pointer gt_reader = ImageReaderType::New(); gt_reader->SetFileName(argv[1]); @@ -106,14 +93,11 @@ int main(int argc, char* argv[]) ImageReaderType::Pointer ms_reader = ImageReaderType::New(); ms_reader->SetFileName(argv[2]); - // Software Guide : BeginLatex // The first step is to convert the images to label maps : we use // \doxygen{itk}{LabelImageToLabelMapFilter}. The background value sets // the label value of regions considered as background: there is no label object for the // background region. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageToLabelMapFilterType::Pointer gt_filter = ImageToLabelMapFilterType::New(); gt_filter->SetInput(gt_reader->GetOutput()); gt_filter->SetBackgroundValue(0); @@ -121,21 +105,15 @@ int main(int argc, char* argv[]) ImageToLabelMapFilterType::Pointer ms_filter = ImageToLabelMapFilterType::New(); ms_filter->SetInput(ms_reader->GetOutput()); ms_filter->SetBackgroundValue(0); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The Hoover matrix filter has to be updated here. This matrix must be computed // before being given to the instance filter. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet HooverMatrixFilterType::Pointer hooverFilter = HooverMatrixFilterType::New(); hooverFilter->SetGroundTruthLabelMap(gt_filter->GetOutput()); hooverFilter->SetMachineSegmentationLabelMap(ms_filter->GetOutput()); hooverFilter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The instance filter computes the Hoover metrics for each region. These metrics // are stored as attributes in each label object. The threshold parameter // corresponds to the overlapping ratio above which two regions can be matched. @@ -143,24 +121,18 @@ int main(int argc, char* argv[]) // associations between MS and GT regions : i.e. if a GT region has been matched // as a correct detection, it will carry an attribute containing the label value // of the associated MS region (the same principle goes for other types of instance). - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet InstanceFilterType::Pointer instances = InstanceFilterType::New(); instances->SetGroundTruthLabelMap(gt_filter->GetOutput()); instances->SetMachineSegmentationLabelMap(ms_filter->GetOutput()); instances->SetThreshold(0.75); instances->SetHooverMatrix(hooverFilter->GetHooverConfusionMatrix()); instances->SetUseExtendedAttributes(false); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The \doxygen{otb}{LabelMapToAttributeImageFilter} is designed to extract attributes // values from a label map and output them in the channels of a vector image. We set // the attribute to plot in each channel. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet AttributeImageFilterType::Pointer attributeImageGT = AttributeImageFilterType::New(); attributeImageGT->SetInput(instances->GetOutputGroundTruthLabelMap()); attributeImageGT->SetAttributeForNthChannel(0, InstanceFilterType::GetNameFromAttribute(InstanceFilterType::ATTRIBUTE_RC)); @@ -172,26 +144,19 @@ int main(int argc, char* argv[]) writer->SetInput(attributeImageGT->GetOutput()); writer->SetFileName(argv[3]); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The output image contains for each GT region its correct detection score ("RC", band 1), // its over-segmentation score ("RF", band 2), its under-segmentation score ("RA", band 3) // and its missed detection score ("RM", band 4). - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - std::cout << "Mean RC ="<< instances->GetMeanRC() << std::endl; - std::cout << "Mean RF ="<< instances->GetMeanRF() << std::endl; - std::cout << "Mean RA ="<< instances->GetMeanRA() << std::endl; - std::cout << "Mean RM ="<< instances->GetMeanRM() << std::endl; - std::cout << "Mean RN ="<< instances->GetMeanRN() << std::endl; - // Software Guide : EndCodeSnippet + std::cout << "Mean RC =" << instances->GetMeanRC() << std::endl; + std::cout << "Mean RF =" << instances->GetMeanRF() << std::endl; + std::cout << "Mean RA =" << instances->GetMeanRA() << std::endl; + std::cout << "Mean RM =" << instances->GetMeanRM() << std::endl; + std::cout << "Mean RN =" << instances->GetMeanRN() << std::endl; - // Software Guide : BeginLatex // The Hoover scores are also computed for the whole segmentations. Here is some explanation about the score names : // C = correct, F = fragmentation, A = aggregation, M = missed, N = noise. - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/OBIA/LabelMapToVectorData.cxx b/Examples/OBIA/LabelMapToVectorData.cxx index 41f887ee4d2235370dc4ea8365155497d8a2f675..001d38ecf9d139292dbcf9ffda681be03a85e87c 100644 --- a/Examples/OBIA/LabelMapToVectorData.cxx +++ b/Examples/OBIA/LabelMapToVectorData.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {rcc8_mire1.png} -// OUTPUTS: {rcc8_mire2_vectorizer.shp} -// Software Guide : EndCommandLineArgs +/* Example usage: +./LabelMapToVectorData Input/rcc8_mire1.png Output/rcc8_mire2_vectorizer.shp +*/ + -// Software Guide : BeginLatex -// // \index{otb::LabelMapToVectorDataFilter} // // @@ -38,7 +36,6 @@ // follows a finite state machine described in \cite{Francis2000}. // // Only polygon conversion is available yet. -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbVectorDataFileWriter.h" @@ -50,149 +47,95 @@ #include "otbImage.h" -// Software Guide : BeginLatex -// // These are the main header files which need to be included: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbLabelMapToVectorDataFilter.h" #include "otbAttributesMapLabelObject.h" -// Software Guide : EndCodeSnippet #include "itkLabelImageToLabelMapFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { /** Use the labelObjecttopolygon functor (not thread safe) only polygon conversion is available yet*/ if (argc != 3) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " inputImageFile outputVectorfile(shp)" << std::endl; return EXIT_FAILURE; - } - const char * infname = argv[1]; - const char * outfname = argv[2]; + } + const char* infname = argv[1]; + const char* outfname = argv[2]; - // Software Guide : BeginLatex - // // The image types are defined using pixel types and // dimension. The input image is defined as an \doxygen{itk}{Image}, // the output is a \doxygen{otb}{VectorData}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef unsigned short LabelType; typedef otb::Image<LabelType, Dimension> LabeledImageType; typedef otb::VectorData<double, 2> VectorDataType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types typedef otb::ImageFileReader<LabeledImageType> LabeledReaderType; typedef otb::VectorDataFileWriter<VectorDataType> WriterType; // Label map typedef - // Software Guide : BeginLatex - // // The Attribute Label Map is // instantiated using the image pixel types as template parameters. // The LabelObjectToPolygonFunctor is instantiated with LabelObjectType and PolygonType. - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::AttributesMapLabelObject<LabelType, Dimension, - double> - LabelObjectType; - typedef itk::LabelMap<LabelObjectType> - LabelMapType; - typedef itk::LabelImageToLabelMapFilter<LabeledImageType, - LabelMapType> - LabelMapFilterType; - // Software Guide : EndCodeSnippet + + typedef otb::AttributesMapLabelObject<LabelType, Dimension, double> LabelObjectType; + typedef itk::LabelMap<LabelObjectType> LabelMapType; + typedef itk::LabelImageToLabelMapFilter<LabeledImageType, LabelMapType> LabelMapFilterType; LabeledReaderType::Pointer lreader = LabeledReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex // Now the reader and writer are instantiated and // the input image is set and a name is given to the output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet lreader->SetFileName(infname); writer->SetFileName(outfname); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, the input image is converted to a map of label objects. // Here each white region connected regions are converted. So the background is define all zero pixels. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LabelMapFilterType::Pointer labelMapFilter = LabelMapFilterType::New(); labelMapFilter->SetInput(lreader->GetOutput()); labelMapFilter->SetBackgroundValue(itk::NumericTraits<LabelType>::min()); labelMapFilter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, the \doxygen{otb}{LabelMapToVectorDataFilter} is instantiated. This is // the main filter which performs the vectorization. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::LabelMapToVectorDataFilter<LabelMapType, - VectorDataType> - LabelMapToVectorDataFilterType; + typedef otb::LabelMapToVectorDataFilter<LabelMapType, VectorDataType> LabelMapToVectorDataFilterType; - LabelMapToVectorDataFilterType::Pointer MyFilter = - LabelMapToVectorDataFilterType::New(); + LabelMapToVectorDataFilterType::Pointer MyFilter = LabelMapToVectorDataFilterType::New(); MyFilter->SetInput(labelMapFilter->GetOutput()); MyFilter->Update(); - MyFilter->GetOutput()->SetProjectionRef( - lreader->GetOutput()->GetProjectionRef()); - // Software Guide : EndCodeSnippet + MyFilter->GetOutput()->SetProjectionRef(lreader->GetOutput()->GetProjectionRef()); - // Software Guide : BeginLatex - // // The output can be passed to a writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetInput(MyFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The invocation of the \code{Update()} method on the writer triggers the // execution of the pipeline. As usual, it is recommended to place update calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); return EXIT_SUCCESS; - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; - } diff --git a/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx b/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx index d10effcec3cb6e228cfa18000a1c352bea311a2e..32bd5654d1c8e8a1075a74507b6ae47ca945b469 100644 --- a/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx +++ b/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx @@ -19,14 +19,20 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {OBIARadiometricAttribute1.png}, {qb_ExtractRoad_Radiometry_pretty.jpg} -// STATS::Band1::Mean 0 0.5 16 16 50 1.0 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// +/* Example usage: +./RadiometricAttributesLabelMapFilterExample Input/qb_RoadExtract.tif \ + Output/OBIARadiometricAttribute1.png \ + Output/qb_ExtractRoad_Radiometry_pretty.jpg \ + STATS::Band1::Mean \ + 0 \ + 0.5 \ + 16 \ + 16 \ + 50 \ + 1.0 +*/ + + // This example shows the basic approach to perform object based analysis on a image. // The input image is firstly segmented using the \doxygen{otb}{MeanShiftSegmentationFilter} // Then each segmented region is converted to a Map of labeled objects. @@ -38,8 +44,6 @@ // STATS, the band number and the statistical attribute separated by colons. In this example // the mean of the first band (which contains the NDVI) is access over all the regions // with the attribute: 'STATS::Band1::Mean'. -// -// Software Guide : EndLatex #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -55,73 +59,55 @@ #include "otbMultiChannelRAndNIRIndexImageFilter.h" #include "otbImageToVectorImageCastFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 11) - { - std::cerr << "Usage: " << argv[0] << - " reffname outfname outprettyfname attribute_name "; - std::cerr << - "lowerThan tresh spatialRadius rangeRadius minregionsize scale" << - std::endl; + { + std::cerr << "Usage: " << argv[0] << " reffname outfname outprettyfname attribute_name "; + std::cerr << "lowerThan tresh spatialRadius rangeRadius minregionsize scale" << std::endl; return EXIT_FAILURE; - } - - const char * reffname = argv[1]; - const char * outfname = argv[2]; - const char * outprettyfname = argv[3]; - const char * attr = argv[4]; - bool lowerThan = atoi(argv[5]); - double thresh = atof(argv[6]); - - const unsigned int spatialRadius = atoi(argv[7]); - const double rangeRadius = atof(argv[8]); - const unsigned int minRegionSize = atoi(argv[9]); + } + + const char* reffname = argv[1]; + const char* outfname = argv[2]; + const char* outprettyfname = argv[3]; + const char* attr = argv[4]; + bool lowerThan = atoi(argv[5]); + double thresh = atof(argv[6]); + + const unsigned int spatialRadius = atoi(argv[7]); + const double rangeRadius = atof(argv[8]); + const unsigned int minRegionSize = atoi(argv[9]); /* const double scale = atoi(argv[10]); */ const unsigned int Dimension = 2; // Labeled image type - typedef unsigned int LabelType; - typedef unsigned char MaskPixelType; - typedef double PixelType; - typedef otb::Image<LabelType, Dimension> LabeledImageType; - typedef otb::Image<MaskPixelType, Dimension> MaskImageType; - typedef otb::Image<PixelType, Dimension> ImageType; - typedef otb::VectorImage<PixelType, Dimension> VectorImageType; - typedef otb::VectorImage<unsigned char, Dimension> OutputVectorImageType; - typedef otb::ImageFileReader<LabeledImageType> LabeledReaderType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileReader<VectorImageType> VectorReaderType; - typedef otb::ImageFileWriter<MaskImageType> WriterType; - typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; - typedef otb::VectorRescaleIntensityImageFilter - <VectorImageType, OutputVectorImageType> VectorRescalerType; - typedef otb::MultiChannelExtractROI<unsigned char, - unsigned char> ChannelExtractorType; + typedef unsigned int LabelType; + typedef unsigned char MaskPixelType; + typedef double PixelType; + typedef otb::Image<LabelType, Dimension> LabeledImageType; + typedef otb::Image<MaskPixelType, Dimension> MaskImageType; + typedef otb::Image<PixelType, Dimension> ImageType; + typedef otb::VectorImage<PixelType, Dimension> VectorImageType; + typedef otb::VectorImage<unsigned char, Dimension> OutputVectorImageType; + typedef otb::ImageFileReader<LabeledImageType> LabeledReaderType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileReader<VectorImageType> VectorReaderType; + typedef otb::ImageFileWriter<MaskImageType> WriterType; + typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType, OutputVectorImageType> VectorRescalerType; + typedef otb::MultiChannelExtractROI<unsigned char, unsigned char> ChannelExtractorType; // Label map typedef - typedef otb::AttributesMapLabelObject<LabelType, Dimension, - double> - LabelObjectType; - typedef itk::LabelMap<LabelObjectType> - LabelMapType; - typedef itk::LabelImageToLabelMapFilter<LabeledImageType, - LabelMapType> - LabelMapFilterType; - typedef otb::ShapeAttributesLabelMapFilter<LabelMapType> - ShapeLabelMapFilterType; - typedef otb::BandsStatisticsAttributesLabelMapFilter<LabelMapType, - VectorImageType> - RadiometricLabelMapFilterType; - typedef otb::AttributesMapOpeningLabelMapFilter<LabelMapType> - OpeningLabelMapFilterType; - typedef itk::LabelMapToBinaryImageFilter<LabelMapType, - MaskImageType> - LabelMapToBinaryImageFilterType; - typedef otb::MultiChannelRAndNIRIndexImageFilter<VectorImageType, - ImageType> NDVIImageFilterType; - typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> - ImageToVectorImageCastFilterType; + typedef otb::AttributesMapLabelObject<LabelType, Dimension, double> LabelObjectType; + typedef itk::LabelMap<LabelObjectType> LabelMapType; + typedef itk::LabelImageToLabelMapFilter<LabeledImageType, LabelMapType> LabelMapFilterType; + typedef otb::ShapeAttributesLabelMapFilter<LabelMapType> ShapeLabelMapFilterType; + typedef otb::BandsStatisticsAttributesLabelMapFilter<LabelMapType, VectorImageType> RadiometricLabelMapFilterType; + typedef otb::AttributesMapOpeningLabelMapFilter<LabelMapType> OpeningLabelMapFilterType; + typedef itk::LabelMapToBinaryImageFilter<LabelMapType, MaskImageType> LabelMapToBinaryImageFilterType; + typedef otb::MultiChannelRAndNIRIndexImageFilter<VectorImageType, ImageType> NDVIImageFilterType; + typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> ImageToVectorImageCastFilterType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(reffname); @@ -132,67 +118,38 @@ int main(int argc, char * argv[]) VectorReaderType::Pointer vreader = VectorReaderType::New(); vreader->SetFileName(reffname); vreader->Update(); - // Software Guide : BeginLatex - // // Firstly, segment the input image by using the Mean Shift algorithm (see \ref{sec:MeanShift} for deeper // explanations). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MeanShiftSegmentationFilter - <VectorImageType, LabeledImageType, VectorImageType> FilterType; - FilterType::Pointer filter = FilterType::New(); + typedef otb::MeanShiftSegmentationFilter<VectorImageType, LabeledImageType, VectorImageType> FilterType; + FilterType::Pointer filter = FilterType::New(); filter->SetSpatialBandwidth(spatialRadius); filter->SetRangeBandwidth(rangeRadius); filter->SetMinRegionSize(minRegionSize); filter->SetThreshold(0.1); filter->SetMaxIterationNumber(100); - // Software Guide : EndCodeSnippet // For non regression tests, set the number of threads to 1 // because MeanShift results depends on the number of threads filter->SetNumberOfThreads(1); - // Software Guide : BeginLatex - // // The \doxygen{otb}{MeanShiftSegmentationFilter} type is instantiated using the image // types. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(vreader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{itk}{LabelImageToLabelMapFilter} type is instantiated using the output // of the \doxygen{otb}{MeanShiftSegmentationFilter}. This filter produces a labeled image // where each segmented region has a unique label. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LabelMapFilterType::Pointer labelMapFilter = LabelMapFilterType::New(); labelMapFilter->SetInput(filter->GetLabelOutput()); labelMapFilter->SetBackgroundValue(itk::NumericTraits<LabelType>::min()); - ShapeLabelMapFilterType::Pointer shapeLabelMapFilter = - ShapeLabelMapFilterType::New(); + ShapeLabelMapFilterType::Pointer shapeLabelMapFilter = ShapeLabelMapFilterType::New(); shapeLabelMapFilter->SetInput(labelMapFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Instantiate the \doxygen{otb}{RadiometricLabelMapFilterType} to // compute statistics of the feature image on each label object. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - RadiometricLabelMapFilterType::Pointer radiometricLabelMapFilter - = RadiometricLabelMapFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + RadiometricLabelMapFilterType::Pointer radiometricLabelMapFilter = RadiometricLabelMapFilterType::New(); // Feature image could be one of the following image: // \begin{itemize} // \item GEMI @@ -206,64 +163,40 @@ int main(int argc, char * argv[]) // // Input image must be convert to the desired coefficient. // In our case, statistics are computed on the NDVI coefficient on each label object. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - NDVIImageFilterType:: Pointer ndviImageFilter = NDVIImageFilterType::New(); + NDVIImageFilterType::Pointer ndviImageFilter = NDVIImageFilterType::New(); ndviImageFilter->SetRedIndex(3); ndviImageFilter->SetNIRIndex(4); ndviImageFilter->SetInput(vreader->GetOutput()); - ImageToVectorImageCastFilterType::Pointer ndviVectorImageFilter = - ImageToVectorImageCastFilterType::New(); + ImageToVectorImageCastFilterType::Pointer ndviVectorImageFilter = ImageToVectorImageCastFilterType::New(); ndviVectorImageFilter->SetInput(ndviImageFilter->GetOutput()); radiometricLabelMapFilter->SetInput(shapeLabelMapFilter->GetOutput()); radiometricLabelMapFilter->SetFeatureImage(ndviVectorImageFilter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{AttributesMapOpeningLabelMapFilter} will perform the selection. // There are three parameters. \code{AttributeName} specifies the radiometric attribute, \code{Lambda} // controls the thresholding of the input and \code{ReverseOrdering} make this filter to remove the // object with an attribute value greater than \code{Lambda} instead. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet OpeningLabelMapFilterType::Pointer opening = OpeningLabelMapFilterType::New(); opening->SetInput(radiometricLabelMapFilter->GetOutput()); opening->SetAttributeName(attr); opening->SetLambda(thresh); opening->SetReverseOrdering(lowerThan); opening->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Then, Label objects selected are transform in a Label Image using the // \doxygen{itk}{LabelMapToLabelImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - LabelMapToBinaryImageFilterType::Pointer labelMap2LabeledImage - = LabelMapToBinaryImageFilterType::New(); + LabelMapToBinaryImageFilterType::Pointer labelMap2LabeledImage = LabelMapToBinaryImageFilterType::New(); labelMap2LabeledImage->SetInput(opening->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And finally, we declare the writer and call its \code{Update()} method to // trigger the full pipeline execution. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outfname); writer->SetInput(labelMap2LabeledImage->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet OutputVectorImageType::PixelType minimum, maximum; minimum.SetSize(vreader->GetOutput()->GetNumberOfComponentsPerPixel()); @@ -292,8 +225,6 @@ int main(int argc, char * argv[]) return EXIT_SUCCESS; } -// Software Guide : BeginLatex -// // Figure~\ref{fig:RADIOMETRIC_LABEL_MAP_FILTER} shows the result of applying // the object selection based on radiometric attributes. // \begin{figure} [htbp] @@ -303,5 +234,3 @@ int main(int argc, char * argv[]) // \itkcaption[Object based extraction based on ]{Vegetation mask resulting from processing.} // \label{fig:RADIOMETRIC_LABEL_MAP_FILTER} // \end{figure} -// -// Software Guide : EndLatex diff --git a/Examples/Patented/SIFTDensityExample.cxx b/Examples/Patented/SIFTDensityExample.cxx index d9a77d91e7e1ccf0f6b3dfe26851838bcdd115cb..90e818e5e9aea2d4dde0861b0862f6060a41f7cc 100644 --- a/Examples/Patented/SIFTDensityExample.cxx +++ b/Examples/Patented/SIFTDensityExample.cxx @@ -27,14 +27,11 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -// Software Guide : BeginCommandLineArgs -// INPUTS: {suburb2.jpeg} -// OUTPUTS: {SIFTDensityOutput.tif}, {PrettySIFTDensityOutput.png} -// 3 3 7 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SIFTDensityExample Input/suburb2.jpeg Output/SIFTDensityOutput.tif Output/PrettySIFTDensityOutput.png 3 3 7 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{otb}{KeyPointDensityImageFilter}. // This filter computes a local density of keypoints (SIFT or SURF, @@ -44,137 +41,76 @@ // the way the keypoints are detected can be chosen by the user. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbKeyPointDensityImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageToSIFTKeyPointSetFilter.h" int main(int itkNotUsed(argc), char* argv[]) { - const char * infname = argv[1]; - const char * outfname = argv[2]; - const char * prettyfname = argv[3]; - const unsigned int scales = atoi(argv[4]); - const unsigned int octaves = atoi(argv[5]); - const unsigned int radius = atoi(argv[6]); + const char* infname = argv[1]; + const char* outfname = argv[2]; + const char* prettyfname = argv[3]; + const unsigned int scales = atoi(argv[4]); + const unsigned int octaves = atoi(argv[5]); + const unsigned int radius = atoi(argv[6]); const unsigned int Dimension = 2; - typedef float PixelType; + typedef float PixelType; - // Software Guide : BeginLatex - // // As usual, we start by defining the types for the images, the reader // and the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We define now the type for the keypoint detection. The keypoints // will be stored in vector form (they may contain many descriptors) // into a point set. The filter for detecting the SIFT is templated // over the input image type and the output pointset type. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef itk::VariableLengthVector<PixelType> RealVectorType; - typedef itk::PointSet<RealVectorType, Dimension> PointSetType; - typedef otb::ImageToSIFTKeyPointSetFilter<ImageType, PointSetType> - DetectorType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef itk::VariableLengthVector<PixelType> RealVectorType; + typedef itk::PointSet<RealVectorType, Dimension> PointSetType; + typedef otb::ImageToSIFTKeyPointSetFilter<ImageType, PointSetType> DetectorType; // We can now define the filter which will compute the SIFT // density. It will be templated over the input and output image // types and the SIFT detector. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::KeyPointDensityImageFilter<ImageType, ImageType, DetectorType> - FilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef otb::KeyPointDensityImageFilter<ImageType, ImageType, DetectorType> FilterType; // We can instantiate the reader and the writer as wella s the // filter and the detector. The detector needs to be instantiated in // order to set its parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + FilterType::Pointer filter = FilterType::New(); DetectorType::Pointer detector = DetectorType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We set the file names for the input and the output images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(infname); writer->SetFileName(outfname); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We set the parameters for the SIFT detector (the number of // octaves and the number of scales per octave). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet detector->SetOctavesNumber(octaves); detector->SetScalesNumber(scales); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And we pass the detector to the filter and we set the radius for // the density estimation. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetDetector(detector); filter->SetNeighborhoodRadius(radius); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We plug the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We trigger the execution by calling th \code{Update()} method on // the writer, but before that we run the // \code{GenerateOutputInformation()} on the reader so the filter // gets the information about the image size (needed for the SIFT // computation). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->GenerateOutputInformation(); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:SIFTDENSITY_FILTER} shows the result of applying // the key point density filter to an image using the SIFT // detector. The main difference with respect to figure @@ -190,15 +126,12 @@ int main(int itkNotUsed(argc), char* argv[]) // original image, SIF density.} // \label{fig:SIFTDENSITY_FILTER} // \end{figure} - // - // Software Guide : EndLatex /************* Image for printing **************/ typedef otb::Image<unsigned char, 2> OutputImageType; - typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> - RescalerType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; RescalerType::Pointer rescaler = RescalerType::New(); @@ -208,7 +141,7 @@ int main(int itkNotUsed(argc), char* argv[]) rescaler->SetInput(filter->GetOutput()); typedef otb::ImageFileWriter<OutputImageType> OutputWriterType; - OutputWriterType::Pointer outwriter = OutputWriterType::New(); + OutputWriterType::Pointer outwriter = OutputWriterType::New(); outwriter->SetFileName(prettyfname); outwriter->SetInput(rescaler->GetOutput()); diff --git a/Examples/Patented/SIFTDisparityMapEstimation.cxx b/Examples/Patented/SIFTDisparityMapEstimation.cxx index b7fdaf6569af5827c74c375c53e7247e2c6535cc..e56bd0c55d00f87994e99f91ab753f80d875777b 100644 --- a/Examples/Patented/SIFTDisparityMapEstimation.cxx +++ b/Examples/Patented/SIFTDisparityMapEstimation.cxx @@ -19,14 +19,11 @@ */ +/* Example usage: +./SIFTDisparityMapEstimation Input/ROISpot5.png Input/ROISpot5Warped.png Output/SIFTdeformationFieldOutput.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png}, {ROISpot5Warped.png} -// OUTPUTS: {SIFTdeformationFieldOutput.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // This example demonstrates the use of the // \doxygen{otb}{KeyPointSetsMatchingFilter} for disparity map // estimation. The idea here is to match SIFTs extracted from both the @@ -40,14 +37,10 @@ // // The first step toward the use of these filters is to include the // appropriate header files. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbKeyPointSetsMatchingFilter.h" #include "otbSiftFastImageFilter.h" #include "itkLandmarkDisplacementFieldSource.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" @@ -60,127 +53,68 @@ int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << "fixedFileName movingFileName fieldOutName" << std::endl; return EXIT_FAILURE; - } + } const unsigned int Dimension = 2; - // Software Guide : BeginLatex - // // Then we must decide what pixel type to use for the image. We choose to do // all the computations in floating point precision and rescale the results // between 0 and 255 in order to export PNG images. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef double RealType; typedef unsigned char OutputPixelType; typedef otb::Image<RealType, Dimension> ImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The SIFTs obtained for the matching will be stored in vector -// form inside a point set. So we need the following types: -// -// Software Guide : EndLatex + // The SIFTs obtained for the matching will be stored in vector + // form inside a point set. So we need the following types: - // Software Guide : BeginCodeSnippet typedef itk::VariableLengthVector<RealType> RealVectorType; typedef itk::PointSet<RealVectorType, Dimension> PointSetType; - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The filter for computing the SIFTs has a type defined as follows: -// -// Software Guide : EndLatex + // The filter for computing the SIFTs has a type defined as follows: - // Software Guide : BeginCodeSnippet - typedef otb::SiftFastImageFilter<ImageType, PointSetType> - ImageToSIFTKeyPointSetFilterType; - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Although many choices for evaluating the distances during the -// matching procedure exist, we choose here to use a simple -// Euclidean distance. We can then define the type for the matching filter. -// -// Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef itk::Statistics::EuclideanDistanceMetric<RealVectorType> DistanceType; - typedef otb::KeyPointSetsMatchingFilter<PointSetType, DistanceType> - EuclideanDistanceMetricMatchingFilterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + typedef otb::SiftFastImageFilter<ImageType, PointSetType> ImageToSIFTKeyPointSetFilterType; + // Although many choices for evaluating the distances during the + // matching procedure exist, we choose here to use a simple + // Euclidean distance. We can then define the type for the matching filter. + + typedef itk::Statistics::EuclideanDistanceMetric<RealVectorType> DistanceType; + typedef otb::KeyPointSetsMatchingFilter<PointSetType, DistanceType> EuclideanDistanceMetricMatchingFilterType; // The following types are needed for dealing with the matched points. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef PointSetType::PointType PointType; - typedef std::pair<PointType, PointType> MatchType; - typedef std::vector<MatchType> MatchVectorType; - typedef EuclideanDistanceMetricMatchingFilterType::LandmarkListType - LandmarkListType; - // Software Guide : EndCodeSnippet + typedef PointSetType::PointType PointType; + typedef std::pair<PointType, PointType> MatchType; + typedef std::vector<MatchType> MatchVectorType; + typedef EuclideanDistanceMetricMatchingFilterType::LandmarkListType LandmarkListType; - // Software Guide : BeginLatex - // // We define the type for the image reader. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Two readers are instantiated : one for the fixed image, and one // for the moving image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - ReaderType::Pointer fixedReader = ReaderType::New(); + ReaderType::Pointer fixedReader = ReaderType::New(); ReaderType::Pointer movingReader = ReaderType::New(); fixedReader->SetFileName(argv[1]); movingReader->SetFileName(argv[2]); fixedReader->UpdateOutputInformation(); movingReader->UpdateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We will now instantiate the 2 SIFT filters and the filter used // for the matching of the points. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - ImageToSIFTKeyPointSetFilterType::Pointer filter1 = - ImageToSIFTKeyPointSetFilterType::New(); - ImageToSIFTKeyPointSetFilterType::Pointer filter2 = - ImageToSIFTKeyPointSetFilterType::New(); - EuclideanDistanceMetricMatchingFilterType::Pointer euclideanMatcher = - EuclideanDistanceMetricMatchingFilterType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + ImageToSIFTKeyPointSetFilterType::Pointer filter1 = ImageToSIFTKeyPointSetFilterType::New(); + ImageToSIFTKeyPointSetFilterType::Pointer filter2 = ImageToSIFTKeyPointSetFilterType::New(); + EuclideanDistanceMetricMatchingFilterType::Pointer euclideanMatcher = EuclideanDistanceMetricMatchingFilterType::New(); // We plug the pipeline and set the parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet double secondOrderThreshold = 0.5; - bool useBackMatching = 0; + bool useBackMatching = 0; filter1->SetInput(0, fixedReader->GetOutput()); filter1->SetScalesNumber(3); @@ -195,31 +129,22 @@ int main(int argc, char* argv[]) euclideanMatcher->SetDistanceThreshold(secondOrderThreshold); euclideanMatcher->SetUseBackMatching(useBackMatching); euclideanMatcher->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The matched points will be stored into a landmark list. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LandmarkListType::Pointer landmarkList; landmarkList = euclideanMatcher->GetOutput(); - // Software Guide : EndCodeSnippet MatchVectorType trueSecondOrder; - for (LandmarkListType::Iterator it = landmarkList->Begin(); - it != landmarkList->End(); ++it) - { + for (LandmarkListType::Iterator it = landmarkList->Begin(); it != landmarkList->End(); ++it) + { PointType point1 = it.Get()->GetPoint1(); PointType point2 = it.Get()->GetPoint2(); trueSecondOrder.push_back(MatchType(point1, point2)); - } + } // Displaying the matches - typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> - PrintableFilterType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> PrintableFilterType; PrintableFilterType::Pointer printable1 = PrintableFilterType::New(); PrintableFilterType::Pointer printable2 = PrintableFilterType::New(); @@ -239,16 +164,12 @@ int main(int argc, char* argv[]) RGBImageType::Pointer rgbimage1 = RGBImageType::New(); rgbimage1->SetRegions(printable1->GetOutput()->GetLargestPossibleRegion()); rgbimage1->Allocate(); - itk::ImageRegionIterator<RGBImageType> outIt1( - rgbimage1, - rgbimage1-> - GetLargestPossibleRegion()); - itk::ImageRegionIterator<OutputImageType> inIt1( - printable1->GetOutput(), printable1->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionIterator<RGBImageType> outIt1(rgbimage1, rgbimage1->GetLargestPossibleRegion()); + itk::ImageRegionIterator<OutputImageType> inIt1(printable1->GetOutput(), printable1->GetOutput()->GetLargestPossibleRegion()); outIt1.GoToBegin(); inIt1.GoToBegin(); while (!inIt1.IsAtEnd() && !outIt1.IsAtEnd()) - { + { itk::RGBPixel<unsigned char> pixel; pixel.SetRed(inIt1.Get()); pixel.SetGreen(inIt1.Get()); @@ -256,20 +177,17 @@ int main(int argc, char* argv[]) outIt1.Set(pixel); ++inIt1; ++outIt1; - } + } RGBImageType::Pointer rgbimage2 = RGBImageType::New(); rgbimage2->SetRegions(printable2->GetOutput()->GetLargestPossibleRegion()); rgbimage2->Allocate(); - itk::ImageRegionIterator<RGBImageType> - outIt2(rgbimage2, rgbimage2->GetLargestPossibleRegion()); - itk::ImageRegionIterator<OutputImageType> - inIt2(printable2->GetOutput(), - printable2->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionIterator<RGBImageType> outIt2(rgbimage2, rgbimage2->GetLargestPossibleRegion()); + itk::ImageRegionIterator<OutputImageType> inIt2(printable2->GetOutput(), printable2->GetOutput()->GetLargestPossibleRegion()); outIt2.GoToBegin(); inIt2.GoToBegin(); while (!inIt2.IsAtEnd() && !outIt2.IsAtEnd()) - { + { itk::RGBPixel<unsigned char> pixel; pixel.SetRed(inIt2.Get()); pixel.SetGreen(inIt2.Get()); @@ -277,69 +195,42 @@ int main(int argc, char* argv[]) outIt2.Set(pixel); ++inIt2; ++outIt2; - } + } - // Software Guide : BeginLatex - // // The landmarks are used for building a deformation field. The // deformation field is an image of vectors created by the // \doxygen{itk}{DisplacementFieldSource} class. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::Vector<RealType, Dimension> VectorType; - typedef otb::Image<VectorType, Dimension> DisplacementFieldType; + typedef itk::Vector<RealType, Dimension> VectorType; + typedef otb::Image<VectorType, Dimension> DisplacementFieldType; - typedef itk::LandmarkDisplacementFieldSource<DisplacementFieldType> DisplacementSourceType; + typedef itk::LandmarkDisplacementFieldSource<DisplacementFieldType> DisplacementSourceType; DisplacementSourceType::Pointer deformer = DisplacementSourceType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The deformation field needs information about the extent and // spacing of the images on which it is defined. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::ConstPointer fixedImage = fixedReader->GetOutput(); deformer->SetOutputSpacing(fixedImage->GetSignedSpacing()); deformer->SetOutputOrigin(fixedImage->GetOrigin()); deformer->SetOutputRegion(fixedImage->GetLargestPossibleRegion()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We will need some intermediate variables in order to pass the // matched SIFTs to the deformation field source. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef DisplacementSourceType::LandmarkContainer - LandmarkContainerType; + typedef DisplacementSourceType::LandmarkContainer LandmarkContainerType; typedef DisplacementSourceType::LandmarkPointType LandmarkPointType; - LandmarkContainerType::Pointer sourceLandmarks = - LandmarkContainerType::New(); - LandmarkContainerType::Pointer targetLandmarks = - LandmarkContainerType::New(); + LandmarkContainerType::Pointer sourceLandmarks = LandmarkContainerType::New(); + LandmarkContainerType::Pointer targetLandmarks = LandmarkContainerType::New(); LandmarkPointType sourcePoint; LandmarkPointType targetPoint; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now iterate through the list of matched points and store -// them in the intermediate landmark sets. -// -// Software Guide : EndLatex + // We can now iterate through the list of matched points and store + // them in the intermediate landmark sets. - // Software Guide : BeginCodeSnippet unsigned int pointId = 0; - for (LandmarkListType::Iterator it = landmarkList->Begin(); - it != landmarkList->End(); ++it) - { + for (LandmarkListType::Iterator it = landmarkList->Begin(); it != landmarkList->End(); ++it) + { PointType point1 = it.Get()->GetPoint1(); PointType point2 = it.Get()->GetPoint2(); @@ -353,49 +244,38 @@ int main(int argc, char* argv[]) targetLandmarks->InsertElement(pointId, targetPoint); ++pointId; - } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We pass the landmarks to the deformer and we run it. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + } + // We pass the landmarks to the deformer and we run it. deformer->SetSourceLandmarks(sourceLandmarks.GetPointer()); deformer->SetTargetLandmarks(targetLandmarks.GetPointer()); deformer->UpdateLargestPossibleRegion(); - DisplacementFieldType::ConstPointer deformationField = - deformer->GetOutput(); + DisplacementFieldType::ConstPointer deformationField = deformer->GetOutput(); deformer->Update(); - // Software Guide : EndCodeSnippet ImageType::Pointer outdf = ImageType::New(); outdf->SetRegions(fixedReader->GetOutput()->GetLargestPossibleRegion()); outdf->Allocate(); - itk::ImageRegionIterator<ImageType> outIt(outdf, - outdf->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ImageType> outIt(outdf, outdf->GetLargestPossibleRegion()); - itk::ImageRegionIterator<DisplacementFieldType> inIt( - deformer->GetOutput(), deformer->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionIterator<DisplacementFieldType> inIt(deformer->GetOutput(), deformer->GetOutput()->GetLargestPossibleRegion()); outIt.GoToBegin(); inIt.GoToBegin(); while (!inIt.IsAtEnd() && !outIt.IsAtEnd()) - { - //std::cout << inIt.Get() << std::endl; + { + // std::cout << inIt.Get() << std::endl; outIt.Set(inIt.Get()[1]); ++inIt; ++outIt; - } + } - typedef itk::RescaleIntensityImageFilter<ImageType, - OutputImageType> RescaleType; + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescaleType; RescaleType::Pointer rescaler = RescaleType::New(); rescaler->SetInput(outdf); @@ -403,14 +283,12 @@ int main(int argc, char* argv[]) rescaler->SetOutputMaximum(255); typedef otb::ImageFileWriter<OutputImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetInput(rescaler->GetOutput()); writer->SetFileName(argv[3]); writer->Update(); - // Software Guide : BeginLatex - // // Figure~\ref{fig:SIFTDME} shows the result of applying the SIFT // disparity map estimation. Only the horizontal component of the // deformation is shown. @@ -425,8 +303,6 @@ int main(int argc, char* argv[]) // estimated deformation field in the horizontal direction.} // \label{fig:SIFTDME} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Patented/SIFTExample.cxx b/Examples/Patented/SIFTExample.cxx index 66c889b686f3fcd0e1c0d51a7cf93c7f9ca509b6..2edddf27fa994f23d69950e61692cf0f6efb8acd 100644 --- a/Examples/Patented/SIFTExample.cxx +++ b/Examples/Patented/SIFTExample.cxx @@ -19,34 +19,27 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5SIFT0.png} -// "SIFT0.txt" 2 3 0 0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5SIFT1.png} -// "SIFT1.txt" 2 3 1 0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5SIFT2.png} -// "SIFT2.txt" 2 3 2 0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {QB_SuburbSIFT5.png} -// "SIFT2.txt" 2 3 5 0 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_SuburbRotated10.png} -// OUTPUTS: {QB_SuburbSIFT5Rotated10.png} -// "SIFT2.txt" 2 3 5 0 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// +/* Example usage: +./SIFTExample Input/ROISpot5.png Output/ROISpot5SIFT0.png Output/SIFT0.txt 2 3 0 0 +*/ + +/* Example usage: +./SIFTExample Input/ROISpot5.png Output/ROISpot5SIFT1.png Output/SIFT1.txt 2 3 1 0 +*/ + +/* Example usage: +./SIFTExample Input/ROISpot5.png Output/ROISpot5SIFT2.png Output/SIFT2.txt 2 3 2 0 +*/ + +/* Example usage: +./SIFTExample Input/QB_Suburb.png Output/QB_SuburbSIFT5.png Output/SIFT2.txt 2 3 5 0 +*/ + +/* Example usage: +./SIFTExample Input/QB_SuburbRotated10.png Output/QB_SuburbSIFT5Rotated10.png Output/SIFT2.txt 2 3 5 0 +*/ + + // This example illustrates the use of the \doxygen{otb}{ImageToSIFTKeyPointSetFilter}. // The Scale-Invariant Feature Transform (or SIFT) is an algorithm in // computer vision to detect and describe local features in @@ -59,12 +52,8 @@ // occlusion and minor changes in viewpoint. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageToSIFTKeyPointSetFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -76,89 +65,66 @@ #include <iostream> #include <fstream> -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 8) - { + { std::cerr << "Usage: " << argv[0]; - std::cerr << - " InputImage OutputImage OutputSIFTFile octaves scales threshold ratio" << - std::endl; + std::cerr << " InputImage OutputImage OutputSIFTFile octaves scales threshold ratio" << std::endl; return 1; - } - const char * infname = argv[1]; - const char * outfname = argv[3]; - const char * outputImageFilename = argv[2]; + } + const char* infname = argv[1]; + const char* outfname = argv[3]; + const char* outputImageFilename = argv[2]; - const unsigned int octaves = atoi(argv[4]); - const unsigned int scales = atoi(argv[5]); + const unsigned int octaves = atoi(argv[4]); + const unsigned int scales = atoi(argv[5]); float threshold = atof(argv[6]); - float ratio = atof(argv[7]); + float ratio = atof(argv[7]); - typedef float RealType; + typedef float RealType; const unsigned int Dimension = 2; -// Software Guide : BeginLatex -// The \doxygen{otb}{ImageToSIFTKeyPointSetFilter} is templated over -// its input image type and the output point set type. Therefore, we -// start by defining the needed types. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef otb::Image<RealType, Dimension> ImageType; - typedef itk::VariableLengthVector<RealType> RealVectorType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef itk::PointSet<RealVectorType, - Dimension> PointSetType; - - typedef otb::ImageToSIFTKeyPointSetFilter<ImageType, - PointSetType> - ImageToSIFTKeyPointSetFilterType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// Since the SIFT detector produces a point set, we will need -// iterators for the coordinates of the points and the data associated -// with them. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef PointSetType::PointsContainer PointsContainerType; - typedef PointsContainerType::Iterator PointsIteratorType; -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// We can now instantiate the reader and the SIFT filter and plug the pipeline. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // The \doxygen{otb}{ImageToSIFTKeyPointSetFilter} is templated over + // its input image type and the output point set type. Therefore, we + // start by defining the needed types. + typedef otb::Image<RealType, Dimension> ImageType; + typedef itk::VariableLengthVector<RealType> RealVectorType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef itk::PointSet<RealVectorType, Dimension> PointSetType; + + typedef otb::ImageToSIFTKeyPointSetFilter<ImageType, PointSetType> ImageToSIFTKeyPointSetFilterType; + + // Since the SIFT detector produces a point set, we will need + // iterators for the coordinates of the points and the data associated + // with them. + typedef PointSetType::PointsContainer PointsContainerType; + typedef PointsContainerType::Iterator PointsIteratorType; + + // We can now instantiate the reader and the SIFT filter and plug the pipeline. ReaderType::Pointer reader = ReaderType::New(); - ImageToSIFTKeyPointSetFilterType::Pointer filter = - ImageToSIFTKeyPointSetFilterType::New(); + ImageToSIFTKeyPointSetFilterType::Pointer filter = ImageToSIFTKeyPointSetFilterType::New(); reader->SetFileName(infname); filter->SetInput(reader->GetOutput()); -// Software Guide : EndCodeSnippet - -// Software Guide : BeginLatex -// The SIFT filter needs the following parameters: -// \begin{itemize} -// \item the number of octaves, that is, the number of levels of undersampling, -// \item the number of scales (blurring) per octave, -// \item the low contrast threshold to be applied to each point for the detection -// on the difference of Gaussians image, -// \item the threshold on the responses to consider a point as an edge. -// \end{itemize} -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + + // The SIFT filter needs the following parameters: + // \begin{itemize} + // \item the number of octaves, that is, the number of levels of undersampling, + // \item the number of scales (blurring) per octave, + // \item the low contrast threshold to be applied to each point for the detection + // on the difference of Gaussians image, + // \item the threshold on the responses to consider a point as an edge. + // \end{itemize} filter->SetOctavesNumber(octaves); filter->SetScalesNumber(scales); filter->SetDoGThreshold(threshold); filter->SetEdgeThreshold(ratio); -// Software Guide : EndCodeSnippet filter->Update(); - // Software Guide : BeginLatex // Figure~\ref{fig:SIFT} shows the result of applying the SIFT // point detector to a small patch extracted from a Spot 5 image // using different threshold values. @@ -188,13 +154,12 @@ int main(int argc, char * argv[]) // and a rotated image respectively.} // \label{fig:SIFT2} // \end{figure} - // Software Guide : EndLatex // - //Building the output image for visualization - ImageType::OffsetType t = {{ 0, 1}}; - ImageType::OffsetType b = {{ 0, -1}}; - ImageType::OffsetType r = {{ 1, 0}}; + // Building the output image for visualization + ImageType::OffsetType t = {{0, 1}}; + ImageType::OffsetType b = {{0, -1}}; + ImageType::OffsetType r = {{1, 0}}; ImageType::OffsetType l = {{-1, 0}}; typedef itk::RGBPixel<unsigned char> RGBPixelType; @@ -217,13 +182,11 @@ int main(int argc, char * argv[]) outputImage->SetRegions(region); outputImage->Allocate(); - itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, - reader->GetOutput()-> - GetLargestPossibleRegion()); + itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, reader->GetOutput()->GetLargestPossibleRegion()); for (iterOutput.GoToBegin(); !iterOutput.IsAtEnd(); ++iterOutput) - { - ImageType::IndexType index = iterOutput.GetIndex(); + { + ImageType::IndexType index = iterOutput.GetIndex(); ImageType::PixelType grayPix = reader->GetOutput()->GetPixel(index); OutputImageType::PixelType rgbPixel; rgbPixel.SetRed(static_cast<unsigned char>(grayPix)); @@ -231,57 +194,44 @@ int main(int argc, char * argv[]) rgbPixel.SetBlue(static_cast<unsigned char>(grayPix)); iterOutput.Set(rgbPixel); - } + } - PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); + PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing(); - ImageType::PointType origin = reader->GetOutput()->GetOrigin(); - OutputImageType::SizeType size = - outputImage->GetLargestPossibleRegion().GetSize(); + ImageType::PointType origin = reader->GetOutput()->GetOrigin(); + OutputImageType::SizeType size = outputImage->GetLargestPossibleRegion().GetSize(); while (pIt != filter->GetOutput()->GetPoints()->End()) - { + { ImageType::IndexType index; - index[0] = (unsigned int) - (std::floor - ((double) ((pIt.Value()[0] - origin[0]) / spacing[0] + 0.5))); + index[0] = (unsigned int)(std::floor((double)((pIt.Value()[0] - origin[0]) / spacing[0] + 0.5))); - index[1] = (unsigned int) - (std::floor - ((double) ((pIt.Value()[1] - origin[1]) / spacing[1] + 0.5))); + index[1] = (unsigned int)(std::floor((double)((pIt.Value()[1] - origin[1]) / spacing[1] + 0.5))); OutputImageType::PixelType keyPixel; keyPixel.SetRed(0); keyPixel.SetGreen(255); keyPixel.SetBlue(0); - if ( - static_cast<unsigned int>(index[1]) < - static_cast<unsigned int>(size[1]) - && static_cast<unsigned int>(index[0]) < - static_cast<unsigned int>(size[0])) - { + if (static_cast<unsigned int>(index[1]) < static_cast<unsigned int>(size[1]) && static_cast<unsigned int>(index[0]) < static_cast<unsigned int>(size[0])) + { outputImage->SetPixel(index, keyPixel); - if (static_cast<unsigned int>(index[1]) < - static_cast<unsigned int>(size[1] - 1)) - outputImage->SetPixel( - index + t, - keyPixel); + if (static_cast<unsigned int>(index[1]) < static_cast<unsigned int>(size[1] - 1)) + outputImage->SetPixel(index + t, keyPixel); - if (index[1] > 0) outputImage->SetPixel(index + b, keyPixel); + if (index[1] > 0) + outputImage->SetPixel(index + b, keyPixel); - if (static_cast<unsigned int>(index[0]) < - static_cast<unsigned int>(size[0] - 1)) - outputImage->SetPixel( - index + r, - keyPixel); + if (static_cast<unsigned int>(index[0]) < static_cast<unsigned int>(size[0] - 1)) + outputImage->SetPixel(index + r, keyPixel); - if (index[0] > 0) outputImage->SetPixel(index + l, keyPixel); - } - ++pIt; + if (index[0] > 0) + outputImage->SetPixel(index + l, keyPixel); } + ++pIt; + } std::ofstream outfile(outfname); outfile << filter; diff --git a/Examples/Patented/SIFTFastExample.cxx b/Examples/Patented/SIFTFastExample.cxx index 456c000d0422e01be9b76278bf7ea87274580add..5ffeb433686bbec444eeded0e02e8153e28c6084 100644 --- a/Examples/Patented/SIFTFastExample.cxx +++ b/Examples/Patented/SIFTFastExample.cxx @@ -18,14 +18,11 @@ * limitations under the License. */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {ROISpot5.png} -// OUTPUTS: {ROISpot5SIFTFast.png} -// 3 -// Software Guide : EndCommandLineArgs +/* Example usage: +./SIFTFastExample Input/ROISpot5.png Output/ROISpot5SIFTFast.png 3 +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the \doxygen{otb}{SiftFastImageFilter}. // The Scale-Invariant Feature Transform (or SIFT) is an algorithm in // computer vision to detect and describe local features in @@ -38,12 +35,8 @@ // occlusion and minor changes in viewpoint. // // The first step required to use this filter is to include its header file. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSiftFastImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "itkPointSet.h" @@ -54,292 +47,158 @@ #include <iostream> #include <fstream> -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { + { std::cerr << "Usage: " << argv[0]; std::cerr << " InputImage OutputImage scales" << std::endl; return 1; - } - const char * infname = argv[1]; - const char * outputImageFilename = argv[2]; + } + const char* infname = argv[1]; + const char* outputImageFilename = argv[2]; const unsigned int scales = atoi(argv[3]); const unsigned int Dimension = 2; -// Software Guide : BeginLatex -// -// We will start by defining the required types. We will work with a -// scalar image of float pixels. We also define the corresponding -// image reader. -// -// Software Guide : EndLatex + // We will start by defining the required types. We will work with a + // scalar image of float pixels. We also define the corresponding + // image reader. -// Software Guide : BeginCodeSnippet typedef float RealType; typedef otb::Image<RealType, Dimension> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The SIFT descriptors will be stored in a point set containing the -// vector of features. -// -// Software Guide : EndLatex + // The SIFT descriptors will be stored in a point set containing the + // vector of features. -// Software Guide : BeginCodeSnippet typedef itk::VariableLengthVector<RealType> RealVectorType; typedef itk::PointSet<RealVectorType, Dimension> PointSetType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The SIFT filter itself is templated over the input image and the -// generated point set. -// -// Software Guide : EndLatex + // The SIFT filter itself is templated over the input image and the + // generated point set. -// Software Guide : BeginCodeSnippet - typedef otb::SiftFastImageFilter<ImageType, PointSetType> - ImageToFastSIFTKeyPointSetFilterType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the reader. -// -// Software Guide : EndLatex + typedef otb::SiftFastImageFilter<ImageType, PointSetType> ImageToFastSIFTKeyPointSetFilterType; + // We instantiate the reader. -// Software Guide : BeginCodeSnippet ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We instantiate the filter. -// -// Software Guide : EndLatex + // We instantiate the filter. -// Software Guide : BeginCodeSnippet - ImageToFastSIFTKeyPointSetFilterType::Pointer filter = - ImageToFastSIFTKeyPointSetFilterType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We plug the filter and set the number of scales for the SIFT -// computation. We can afterwards run the processing with the -// \code{Update()} method. -// -// Software Guide : EndLatex + ImageToFastSIFTKeyPointSetFilterType::Pointer filter = ImageToFastSIFTKeyPointSetFilterType::New(); + // We plug the filter and set the number of scales for the SIFT + // computation. We can afterwards run the processing with the + // \code{Update()} method. -// Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); filter->SetScalesNumber(scales); filter->Update(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Once the SIFT are computed, we may want to draw them on top of the -// input image. In order to do this, we will create the following RGB -// image and the corresponding writer: -// -// Software Guide : EndLatex + // Once the SIFT are computed, we may want to draw them on top of the + // input image. In order to do this, we will create the following RGB + // image and the corresponding writer: -// Software Guide : BeginCodeSnippet typedef unsigned char PixelType; typedef itk::RGBPixel<PixelType> RGBPixelType; typedef otb::Image<RGBPixelType, 2> OutputImageType; typedef otb::ImageFileWriter<OutputImageType> WriterType; OutputImageType::Pointer outputImage = OutputImageType::New(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We set the regions of the image by copying the information from the -// input image and we allocate the memory for the output image. -// -// Software Guide : EndLatex + // We set the regions of the image by copying the information from the + // input image and we allocate the memory for the output image. -// Software Guide : BeginCodeSnippet outputImage->SetRegions(reader->GetOutput()->GetLargestPossibleRegion()); outputImage->Allocate(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now proceed to copy the input image into the output one -// using region iterators. The input image is a grey level one. The -// output image will be made of color crosses for each SIFT on top of -// the grey level input image. So we start by copying the grey level -// values on each of the 3 channels of the color image. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - itk::ImageRegionIterator<OutputImageType> iterOutput( - outputImage, - outputImage-> - GetLargestPossibleRegion()); - itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), - reader->GetOutput()-> - GetLargestPossibleRegion()); - - for (iterOutput.GoToBegin(), iterInput.GoToBegin(); - !iterOutput.IsAtEnd(); - ++iterOutput, ++iterInput) - { + // We can now proceed to copy the input image into the output one + // using region iterators. The input image is a grey level one. The + // output image will be made of color crosses for each SIFT on top of + // the grey level input image. So we start by copying the grey level + // values on each of the 3 channels of the color image. + + itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, outputImage->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion()); + + for (iterOutput.GoToBegin(), iterInput.GoToBegin(); !iterOutput.IsAtEnd(); ++iterOutput, ++iterInput) + { OutputImageType::PixelType rgbPixel; rgbPixel.SetRed(static_cast<PixelType>(iterInput.Get())); rgbPixel.SetGreen(static_cast<PixelType>(iterInput.Get())); rgbPixel.SetBlue(static_cast<PixelType>(iterInput.Get())); iterOutput.Set(rgbPixel); - } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We are now going to plot color crosses on the output image. We will -// need to define offsets (top, bottom, left and right) with respect -// to the SIFT position in order to draw the cross segments. -// -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - ImageType::OffsetType t = {{ 0, 1}}; - ImageType::OffsetType b = {{ 0, -1}}; - ImageType::OffsetType l = {{ 1, 0}}; + } + // We are now going to plot color crosses on the output image. We will + // need to define offsets (top, bottom, left and right) with respect + // to the SIFT position in order to draw the cross segments. + + ImageType::OffsetType t = {{0, 1}}; + ImageType::OffsetType b = {{0, -1}}; + ImageType::OffsetType l = {{1, 0}}; ImageType::OffsetType r = {{-1, 0}}; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Now, we are going to access the point set generated by the SIFT -// filter. The points are stored into a points container that we are -// going to walk through using an iterator. These are the types needed -// for this task: -// -// Software Guide : EndLatex + // Now, we are going to access the point set generated by the SIFT + // filter. The points are stored into a points container that we are + // going to walk through using an iterator. These are the types needed + // for this task: -// Software Guide : BeginCodeSnippet typedef PointSetType::PointsContainer PointsContainerType; typedef PointsContainerType::Iterator PointsIteratorType; -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We set the iterator to the beginning of the point set. -// -// Software Guide : EndLatex + // We set the iterator to the beginning of the point set. -// Software Guide : BeginCodeSnippet PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We get the information about image size and spacing before drawing -// the crosses. -// -// Software Guide : EndLatex + // We get the information about image size and spacing before drawing + // the crosses. -// Software Guide : BeginCodeSnippet - ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing(); - ImageType::PointType origin = reader->GetOutput()->GetOrigin(); -// Software Guide : EndCodeSnippet + ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing(); + ImageType::PointType origin = reader->GetOutput()->GetOrigin(); -// Software Guide : BeginLatex -// -// And we iterate through the SIFT set: -// -// Software Guide : EndLatex + // And we iterate through the SIFT set: -// Software Guide : BeginCodeSnippet while (pIt != filter->GetOutput()->GetPoints()->End()) - { -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We get the pixel coordinates for each SIFT by using the -// \code{Value()} method on the point set iterator. We use the -// information about size and spacing in order to convert the physical -// coordinates of the point into pixel coordinates. -// -// Software Guide : EndLatex + { + // We get the pixel coordinates for each SIFT by using the + // \code{Value()} method on the point set iterator. We use the + // information about size and spacing in order to convert the physical + // coordinates of the point into pixel coordinates. -// Software Guide : BeginCodeSnippet ImageType::IndexType index; - index[0] = static_cast<unsigned int>(std::floor( - static_cast<double>( - (pIt.Value()[0] - - origin[0]) / spacing[0] + 0.5 - ))); - - index[1] = static_cast<unsigned int>(std::floor( - static_cast<double>( - (pIt.Value()[1] - - origin[1]) / spacing[1] + 0.5 - ))); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We create a green pixel. -// -// Software Guide : EndLatex + index[0] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[0] - origin[0]) / spacing[0] + 0.5))); + + index[1] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[1] - origin[1]) / spacing[1] + 0.5))); + // We create a green pixel. -// Software Guide : BeginCodeSnippet OutputImageType::PixelType keyPixel; keyPixel.SetRed(0); keyPixel.SetGreen(255); keyPixel.SetBlue(0); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We draw the crosses using the offsets and checking that we are -// inside the image, since SIFTs on the image borders would cause an -// out of bounds pixel access. -// -// Software Guide : EndLatex + // We draw the crosses using the offsets and checking that we are + // inside the image, since SIFTs on the image borders would cause an + // out of bounds pixel access. -// Software Guide : BeginCodeSnippet if (outputImage->GetLargestPossibleRegion().IsInside(index)) - { + { outputImage->SetPixel(index, keyPixel); - if (outputImage->GetLargestPossibleRegion().IsInside(index + - t)) - outputImage-> - SetPixel(index + t, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - b)) - outputImage-> - SetPixel(index + b, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - l)) - outputImage-> - SetPixel(index + l, keyPixel); - - if (outputImage->GetLargestPossibleRegion().IsInside(index + - r)) - outputImage-> - SetPixel(index + r, keyPixel); - } - ++pIt; + if (outputImage->GetLargestPossibleRegion().IsInside(index + t)) + outputImage->SetPixel(index + t, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + b)) + outputImage->SetPixel(index + b, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + l)) + outputImage->SetPixel(index + l, keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index + r)) + outputImage->SetPixel(index + r, keyPixel); } -// Software Guide : EndCodeSnippet + ++pIt; + } -// Software Guide : BeginLatex -// -// Finally, we write the image. -// -// Software Guide : EndLatex + // Finally, we write the image. -// Software Guide : BeginCodeSnippet WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputImageFilename); writer->SetInput(outputImage); writer->Update(); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Figure~\ref{fig:SIFTFast} shows the result of applying the SIFT // point detector to a small patch extracted from a Spot 5 image. // \begin{figure} @@ -351,7 +210,6 @@ int main(int argc, char * argv[]) // image.} // \label{fig:SIFTFast} // \end{figure} - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Projections/EstimateRPCSensorModelExample.cxx b/Examples/Projections/EstimateRPCSensorModelExample.cxx index 043fa567eb70c3ec0ee5ecc3e5b6830ee851a29f..67aaebd2767122020ed4ac651aef48cd41fb6a45 100644 --- a/Examples/Projections/EstimateRPCSensorModelExample.cxx +++ b/Examples/Projections/EstimateRPCSensorModelExample.cxx @@ -19,8 +19,6 @@ */ -// Software Guide : BeginLatex -// // \index{otb::GCPsToRPCSensorModelImageFilter} // \index{otb::GCPsToRPCSensorModelImageFilter!header} // @@ -37,68 +35,48 @@ // algorithm. First, the following header defining the // \doxygen{otb}{GCPsToRPCSensorModelImageFilter} class must be // included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include <ios> #include "otbImage.h" #include "otbImageFileReader.h" #include "otbGCPsToRPCSensorModelImageFilter.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc < 3) - { - std::cerr << "Usage: " << argv[0] << - " infname outfname a1x a1y b1x b1y b1z ... aNx aNy bNx bNy bNz" << - std::endl; + { + std::cerr << "Usage: " << argv[0] << " infname outfname a1x a1y b1x b1y b1z ... aNx aNy bNx bNy bNz" << std::endl; return EXIT_FAILURE; - } + } else if ((argc - 3) % 5 != 0) - { + { std::cerr << "Inconsistent GCPs description!" << std::endl; return EXIT_FAILURE; - } + } - const char * infname = argv[1]; - const char * outfname = argv[2]; + const char* infname = argv[1]; + const char* outfname = argv[2]; - // Software Guide : BeginLatex - // // We declare the image type based on a particular pixel type and // dimension. In this case the \code{float} type is used for the pixels. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<float, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::GCPsToRPCSensorModelImageFilter<ImageType> - GCPsToSensorModelFilterType; + typedef otb::GCPsToRPCSensorModelImageFilter<ImageType> GCPsToSensorModelFilterType; typedef GCPsToSensorModelFilterType::Point2DType Point2DType; typedef GCPsToSensorModelFilterType::Point3DType Point3DType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); - // Software Guide : BeginLatex - // // The \doxygen{otb}{GCPsToRPCSensorModelImageFilter} is instantiated. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - GCPsToSensorModelFilterType::Pointer rpcEstimator = - GCPsToSensorModelFilterType::New(); + GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New(); rpcEstimator->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // We retrieve the command line parameters and put them in the // correct variables. Firstly, We determine the number of GCPs // set from the command line parameters and they are stored in: @@ -110,15 +88,13 @@ int main(int argc, char* argv[]) // ground point and use the DEM or MeanElevation to get // the corresponding elevation. // \end{itemize} - // Software Guide : EndLatex unsigned int nbGCPs = (argc - 3) / 5; std::cout << "Receiving " << nbGCPs << " from command line." << std::endl; - // Software Guide : BeginCodeSnippet for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) - { + { Point2DType sensorPoint; sensorPoint[0] = atof(argv[3 + gcpId * 5]); sensorPoint[1] = atof(argv[4 + gcpId * 5]); @@ -128,33 +104,24 @@ int main(int argc, char* argv[]) geoPoint[1] = atof(argv[6 + 5 * gcpId]); geoPoint[2] = atof(argv[7 + 5 * gcpId]); - std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << - geoPoint << std::endl; + std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl; rpcEstimator->AddGCP(sensorPoint, geoPoint); - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex // Note that the \doxygen{otb}{GCPsToRPCSensorModelImageFilter} needs // at least 20 GCPs to estimate a proper RPC sensor model, // although no warning will be reported to the user if // the number of GCPs is lower than 20. // Actual estimation of the sensor model takes place in the // \code{GenerateOutputInformation()} method. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet rpcEstimator->GetOutput()->UpdateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The result of the RPC model estimation and the residual ground // error is then save in a txt file. Note that This filter does // not modify the image buffer, but only the metadata. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet std::ofstream ofs; ofs.open(outfname); @@ -162,17 +129,13 @@ int main(int argc, char* argv[]) ofs.setf(std::ios::fixed, std::ios::floatfield); ofs.precision(10); - ofs << (ImageType::Pointer) rpcEstimator->GetOutput() << std::endl; - ofs << "Residual ground error: " << rpcEstimator->GetRMSGroundError() << - std::endl; + ofs << (ImageType::Pointer)rpcEstimator->GetOutput() << std::endl; + ofs << "Residual ground error: " << rpcEstimator->GetRMSGroundError() << std::endl; ofs.close(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The output image can be now given to the \doxygen{otb}{orthorectificationFilter}. // Note that this filter allows also to import GCPs from the image // metadata, if any. - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Projections/GeometriesProjectionExample.cxx b/Examples/Projections/GeometriesProjectionExample.cxx index 6432e057471267c783ed4d41f38d904869f19ebc..686ea45145804d7142c7173601c81ca70bf6cba7 100644 --- a/Examples/Projections/GeometriesProjectionExample.cxx +++ b/Examples/Projections/GeometriesProjectionExample.cxx @@ -19,16 +19,12 @@ */ -// Software Guide : BeginLatex -// // Instead of using \doxygen{otb}{VectorData} to apply projections as // explained in \ref{sec:VectorDataProjection}, we can also \emph{directly} work // on OGR data types thanks to \doxygen{otb}{GeometriesProjectionFilter}. // // This example demonstrates how to proceed with this alternative set of vector // data types. -// -// Software Guide : EndLatex #include "otbGeometriesProjectionFilter.h" #include "otbGeometriesSet.h" @@ -39,91 +35,54 @@ int main(int argc, char* argv[]) { if (argc < 4) - { - std::cerr << argv[0] << - " <input vector filename> <input image name> <output vector filename>\n"; + { + std::cerr << argv[0] << " <input vector filename> <input image name> <output vector filename>\n"; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Declare the geometries type that you would like to use in your // application. Unlike \doxygen{otb}{VectorData}, \doxygen{otb}{GeometriesSet} // is a single type for any kind of geometries set (OGR data source, or OGR // layer). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::GeometriesSet InputGeometriesType; typedef otb::GeometriesSet OutputGeometriesType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // First, declare and instantiate the data source // \subdoxygen{otb}{ogr}{DataSource}. Then, encapsulate this data source into // a \doxygen{otb}{GeometriesSet}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( - argv[1], otb::ogr::DataSource::Modes::Read); - InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); - // Software Guide : EndCodeSnippet + otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New(argv[1], otb::ogr::DataSource::Modes::Read); + InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); - // Software Guide : BeginLatex - // // We need the image only to retrieve its projection information, // i.e. map projection or sensor model parameters. Hence, the image // pixels won't be read, only the header information using the // \code{UpdateOutputInformation()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<unsigned short int, 2> ImageType; typedef otb::ImageFileReader<ImageType> ImageReaderType; - ImageReaderType::Pointer imageReader = ImageReaderType::New(); + ImageReaderType::Pointer imageReader = ImageReaderType::New(); imageReader->SetFileName(argv[2]); imageReader->UpdateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{GeometriesProjectionFilter} will do the work of // converting the geometries coordinates. It is usually a good idea // to use it when you design applications reading or saving vector // data. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::GeometriesProjectionFilter GeometriesFilterType; - GeometriesFilterType::Pointer filter = GeometriesFilterType::New(); - // Software Guide : EndCodeSnippet + GeometriesFilterType::Pointer filter = GeometriesFilterType::New(); - // Software Guide : BeginLatex - // // Information concerning the original projection of the vector data // will be automatically retrieved from the metadata. Nothing else // is needed from you: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(in_set); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Information about the target projection is retrieved directly from // the image: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet // necessary for sensors filter->SetOutputKeywordList(imageReader->GetOutput()->GetImageKeywordlist()); // necessary for sensors @@ -131,11 +90,8 @@ int main(int argc, char* argv[]) // necessary for sensors filter->SetOutputSpacing(imageReader->GetOutput()->GetSignedSpacing()); // ~ wkt - filter->SetOutputProjectionRef( imageReader->GetOutput()->GetProjectionRef()); - // Software Guide : EndCodeSnippet + filter->SetOutputProjectionRef(imageReader->GetOutput()->GetProjectionRef()); - // Software Guide : BeginLatex - // // Finally, the result is saved into a new vector file. // Unlike other OTB filters, \doxygen{otb}{GeometriesProjectionFilter} expects // to be given a valid output geometries set where to store the result of its @@ -146,26 +102,16 @@ int main(int argc, char* argv[]) // serialization of the results is guaranteed to be completed when the output // geometries set object goes out of scope, or when \code{SyncToDisk} is // called. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New( - argv[3], otb::ogr::DataSource::Modes::Update_LayerCreateOnly); + otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New(argv[3], otb::ogr::DataSource::Modes::Update_LayerCreateOnly); OutputGeometriesType::Pointer out_set = OutputGeometriesType::New(output); filter->SetOutput(out_set); filter->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Once again, it is worth noting that none of this code is specific to the // vector data format. Whether you pass a shapefile, or a KML file, the // correct driver will be automatically instantiated. - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Projections/OrthoRectificationExample.cxx b/Examples/Projections/OrthoRectificationExample.cxx index 3e36ee3432726ce2b4b4e6a8365cb7ea78118047..c365fcfc06b8d3a88c5ee8a7f33df9d6b886ab06 100644 --- a/Examples/Projections/OrthoRectificationExample.cxx +++ b/Examples/Projections/OrthoRectificationExample.cxx @@ -19,12 +19,9 @@ */ - #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -// Software Guide : BeginLatex -// // This example demonstrates the use of the // \doxygen{otb}{OrthoRectificationFilter}. This filter is intended to // orthorectify images which are in a distributor format with the @@ -34,40 +31,32 @@ // The first step toward the use of these filters is to include the // proper header files: the one for the ortho-rectification filter and // the one defining the different projections available in OTB. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbOrthoRectificationFilter.h" #include "otbMapProjections.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 11) - { - std::cout << argv[0] << - " <input_filename> <output_filename> <utm zone> <hemisphere N/S> <x_ground_upper_left_corner> <y_ground_upper_left_corner> <x_Size> <y_Size> <x_groundSamplingDistance> <y_groundSamplingDistance> (should be negative since origin is upper left)>" + { + std::cout << argv[0] + << " <input_filename> <output_filename> <utm zone> <hemisphere N/S> <x_ground_upper_left_corner> <y_ground_upper_left_corner> <x_Size> <y_Size> " + "<x_groundSamplingDistance> <y_groundSamplingDistance> (should be negative since origin is upper left)>" << std::endl; return EXIT_FAILURE; - } + } -// Software Guide : BeginLatex -// -// We will start by defining the types for the images, the image file -// reader and the image file writer. The writer will be a -// \doxygen{otb}{ImageFileWriter} which will allow us to set -// the number of stream divisions we want to apply when writing the -// output image, which can be very large. -// -// Software Guide : EndLatex + // We will start by defining the types for the images, the image file + // reader and the image file writer. The writer will be a + // \doxygen{otb}{ImageFileWriter} which will allow us to set + // the number of stream divisions we want to apply when writing the + // output image, which can be very large. -// Software Guide : BeginCodeSnippet - typedef otb::Image<int, 2> ImageType; - typedef otb::VectorImage<int, 2> VectorImageType; - typedef otb::ImageFileReader<VectorImageType> ReaderType; + typedef otb::Image<int, 2> ImageType; + typedef otb::VectorImage<int, 2> VectorImageType; + typedef otb::ImageFileReader<VectorImageType> ReaderType; typedef otb::ImageFileWriter<VectorImageType> WriterType; ReaderType::Pointer reader = ReaderType::New(); @@ -75,65 +64,37 @@ int main(int argc, char* argv[]) reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now proceed to declare the type for the ortho-rectification -// filter. The class \doxygen{otb}{OrthoRectificationFilter} is -// templated over the input and the output image types as well as over -// the cartographic projection. We define therefore the -// type of the projection we want, which is an UTM projection for this case. -// -// Software Guide : EndLatex + // We can now proceed to declare the type for the ortho-rectification + // filter. The class \doxygen{otb}{OrthoRectificationFilter} is + // templated over the input and the output image types as well as over + // the cartographic projection. We define therefore the + // type of the projection we want, which is an UTM projection for this case. -// Software Guide : BeginCodeSnippet - typedef otb::UtmInverseProjection utmMapProjectionType; - typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, - utmMapProjectionType> - OrthoRectifFilterType; + typedef otb::UtmInverseProjection utmMapProjectionType; + typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, utmMapProjectionType> OrthoRectifFilterType; - OrthoRectifFilterType::Pointer orthoRectifFilter = - OrthoRectifFilterType::New(); -// Software Guide : EndCodeSnippet + OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); -// Software Guide : BeginLatex -// -// Now we need to -// instantiate the map projection, set the {\em zone} and {\em hemisphere} -// parameters and pass this projection to the orthorectification filter. -// -// Software Guide : EndLatex + // Now we need to + // instantiate the map projection, set the {\em zone} and {\em hemisphere} + // parameters and pass this projection to the orthorectification filter. -// Software Guide : BeginCodeSnippet - utmMapProjectionType::Pointer utmMapProjection = - utmMapProjectionType::New(); + utmMapProjectionType::Pointer utmMapProjection = utmMapProjectionType::New(); utmMapProjection->SetZone(atoi(argv[3])); utmMapProjection->SetHemisphere(*(argv[4])); orthoRectifFilter->SetMapProjection(utmMapProjection); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We then wire the input image to the orthorectification filter. -// -// Software Guide : EndLatex + // We then wire the input image to the orthorectification filter. -// Software Guide : BeginCodeSnippet orthoRectifFilter->SetInput(reader->GetOutput()); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Using the user-provided information, we define the output region -// for the image generated by the orthorectification filter. -// We also define the spacing of the deformation grid where actual -// deformation values are estimated. Choosing a bigger deformation field -// spacing will speed up computation. -// -// Software Guide : EndLatex + // Using the user-provided information, we define the output region + // for the image generated by the orthorectification filter. + // We also define the spacing of the deformation grid where actual + // deformation values are estimated. Choosing a bigger deformation field + // spacing will speed up computation. -// Software Guide : BeginCodeSnippet ImageType::IndexType start; start[0] = 0; start[1] = 0; @@ -150,47 +111,33 @@ int main(int argc, char* argv[]) orthoRectifFilter->SetOutputSpacing(spacing); ImageType::SpacingType gridSpacing; - gridSpacing[0] = 2.*atof(argv[9]); - gridSpacing[1] = 2.*atof(argv[10]); + gridSpacing[0] = 2. * atof(argv[9]); + gridSpacing[1] = 2. * atof(argv[10]); orthoRectifFilter->SetDisplacementFieldSpacing(gridSpacing); ImageType::PointType origin; origin[0] = strtod(argv[5], nullptr); origin[1] = strtod(argv[6], nullptr); orthoRectifFilter->SetOutputOrigin(origin); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// We can now set plug the ortho-rectification filter to the writer -// and set the number of tiles we want to split the output image in -// for the writing step. -// -// Software Guide : EndLatex + // We can now set plug the ortho-rectification filter to the writer + // and set the number of tiles we want to split the output image in + // for the writing step. -// Software Guide : BeginCodeSnippet writer->SetInput(orthoRectifFilter->GetOutput()); writer->SetAutomaticTiledStreaming(); -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// Finally, we trigger the pipeline execution by calling the -// \code{Update()} method on the writer. Please note that the -// ortho-rectification filter is derived from the -// \doxygen{otb}{StreamingResampleImageFilter} in order to be able to -// compute the input image regions which are needed to build the -// output image. Since the resampler applies a geometric -// transformation (scale, rotation, etc.), this region computation is -// not trivial. -// -// Software Guide : EndLatex + // Finally, we trigger the pipeline execution by calling the + // \code{Update()} method on the writer. Please note that the + // ortho-rectification filter is derived from the + // \doxygen{otb}{StreamingResampleImageFilter} in order to be able to + // compute the input image regions which are needed to build the + // output image. Since the resampler applies a geometric + // transformation (scale, rotation, etc.), this region computation is + // not trivial. -// Software Guide : BeginCodeSnippet writer->Update(); -// Software Guide : EndCodeSnippet return EXIT_SUCCESS; - } diff --git a/Examples/Projections/PlaceNameToLonLatExample.cxx b/Examples/Projections/PlaceNameToLonLatExample.cxx index 4f765937c1d4ce333b07406233f976cf6e725381..82f17c393f4b205ccd15412054794334994ddffa 100644 --- a/Examples/Projections/PlaceNameToLonLatExample.cxx +++ b/Examples/Projections/PlaceNameToLonLatExample.cxx @@ -19,61 +19,39 @@ */ - -// Software Guide : BeginLatex -// // This example will show how to retrieve the longitude and latitude from // a place using the name of the city or the address. For that, we will // use the \doxygen{otb}{PlaceNameToLonLat} class. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbPlaceNameToLonLat.h" -// Software Guide : EndCodeSnippet int main(int argc, char* argv[]) { if (argc != 2) - { - std::cout << argv[0] << " <place name> " - << std::endl; + { + std::cout << argv[0] << " <place name> " << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // You instantiate the class and pass the name you want to look for as a // std::string to the SetPlaceName method. // // The call to evaluate will trigger the retrival process. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet otb::PlaceNameToLonLat::Pointer pn2LL = otb::PlaceNameToLonLat::New(); pn2LL->SetPlaceName(std::string(argv[1])); pn2LL->Evaluate(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To get the data, you can simply call the GetLon and GetLat methods. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet double lon = pn2LL->GetLon(); double lat = pn2LL->GetLat(); std::cout << "Latitude: " << lat << std::endl; std::cout << "Longitude: " << lon << std::endl; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // If you tried with a string such as "Toulouse" -- a city where the // heart of OTB relies -- you should obtain something // like: @@ -82,9 +60,6 @@ int main(int argc, char* argv[]) // Latitude: 43.6044 // Longitude: 1.44295 // \end{verbatim} - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Projections/VectorDataExtractROIExample.cxx b/Examples/Projections/VectorDataExtractROIExample.cxx index 25107aa1da893160bc0aa2d6751acfb5665e8ef0..3194eea322bd8f9df819a9459f34b430e8a1c690 100644 --- a/Examples/Projections/VectorDataExtractROIExample.cxx +++ b/Examples/Projections/VectorDataExtractROIExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // There is some vector data sets widely available on the internet. These data // sets can be huge, covering an entire country, with hundreds of thousands // objects. @@ -35,8 +32,6 @@ // // This example demonstrates the use of the // \doxygen{otb}{VectorDataExtractROI}. -// -// Software Guide : EndLatex #include "otbVectorData.h" #include "otbVectorDataExtractROI.h" @@ -51,18 +46,15 @@ int main(int argc, char* argv[]) { if (argc < 4) - { - std::cout << argv[0] << - " <input vector filename> <input image name> <output vector filename> " - << - std::endl; + { + std::cout << argv[0] << " <input vector filename> <input image name> <output vector filename> " << std::endl; return EXIT_FAILURE; - } + } - const char * inVectorName = argv[1]; - const char * inImageName = argv[2]; - const char * outVectorName = argv[3]; + const char* inVectorName = argv[1]; + const char* inImageName = argv[2]; + const char* outVectorName = argv[3]; typedef double Type; typedef otb::VectorData<> VectorDataType; @@ -70,77 +62,53 @@ int main(int argc, char* argv[]) typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; typedef otb::VectorDataFileWriter<VectorDataType> VectorDataWriterType; - typedef otb::RemoteSensingRegion<Type> TypedRegion; + typedef otb::RemoteSensingRegion<Type> TypedRegion; typedef otb::Image<unsigned char, 2> ImageType; typedef otb::ImageFileReader<ImageType> ImageReaderType; - ImageReaderType::Pointer imageReader = ImageReaderType::New(); + ImageReaderType::Pointer imageReader = ImageReaderType::New(); imageReader->SetFileName(inImageName); imageReader->UpdateOutputInformation(); - // Software Guide : BeginLatex - // // After the usual declaration (you can check the source file for the details), // we can declare the \doxygen{otb}{VectorDataExtractROI}: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorDataExtractROI<VectorDataType> FilterType; - FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet + FilterType::Pointer filter = FilterType::New(); - // Software Guide : BeginLatex - // // Then, we need to specify the region to extract. This region is a bit special as // it contains also information related to its reference system (cartographic projection // or sensor model projection). We retrieve all these information from the image // we gave as an input. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet TypedRegion region; TypedRegion::SizeType size; TypedRegion::IndexType index; - size[0] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] - * imageReader->GetOutput()->GetSignedSpacing()[0]; - size[1] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] - * imageReader->GetOutput()->GetSignedSpacing()[1]; - index[0] = imageReader->GetOutput()->GetOrigin()[0] - - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[0]; - index[1] = imageReader->GetOutput()->GetOrigin()[1] - - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[1]; + size[0] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] * imageReader->GetOutput()->GetSignedSpacing()[0]; + size[1] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] * imageReader->GetOutput()->GetSignedSpacing()[1]; + index[0] = imageReader->GetOutput()->GetOrigin()[0] - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[0]; + index[1] = imageReader->GetOutput()->GetOrigin()[1] - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[1]; region.SetSize(size); region.SetOrigin(index); - otb::ImageMetadataInterfaceBase::Pointer imageMetadataInterface - = otb::ImageMetadataInterfaceFactory::CreateIMI( - imageReader->GetOutput()->GetMetaDataDictionary()); - region.SetRegionProjection( - imageMetadataInterface->GetProjectionRef()); + otb::ImageMetadataInterfaceBase::Pointer imageMetadataInterface = + otb::ImageMetadataInterfaceFactory::CreateIMI(imageReader->GetOutput()->GetMetaDataDictionary()); + region.SetRegionProjection(imageMetadataInterface->GetProjectionRef()); region.SetKeywordList(imageReader->GetOutput()->GetImageKeywordlist()); filter->SetRegion(region); - // Software Guide : EndCodeSnippet VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); VectorDataWriterType::Pointer writer = VectorDataWriterType::New(); reader->SetFileName(inVectorName); writer->SetFileName(outVectorName); - // Software Guide : BeginLatex - // // And finally, we can plug the filter in the pipeline: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet writer->Update(); diff --git a/Examples/Projections/VectorDataProjectionExample.cxx b/Examples/Projections/VectorDataProjectionExample.cxx index a2cbd14eb8169bdc677dfae4ce53e29f307e6bc7..7a063a172bc5288e1220b6c1174c71d77a1ed4e8 100644 --- a/Examples/Projections/VectorDataProjectionExample.cxx +++ b/Examples/Projections/VectorDataProjectionExample.cxx @@ -19,9 +19,6 @@ */ - -// Software Guide : BeginLatex -// // Let's assume that you have a KML file (hence in geographical coordinates) // that you would like to superpose to some image with a specific map projection. // Of course, you could use the handy ogr2ogr tool to do that, but it won't @@ -34,8 +31,6 @@ // // This example demonstrates the use of the // \doxygen{otb}{VectorDataProjectionFilter}. -// -// Software Guide : EndLatex #include "otbVectorDataProjectionFilter.h" #include "otbVectorData.h" @@ -48,129 +43,71 @@ int main(int argc, char* argv[]) { if (argc < 4) - { - std::cout << argv[0] << - " <input vector filename> <input image name> <output vector filename> " << - std::endl; + { + std::cout << argv[0] << " <input vector filename> <input image name> <output vector filename> " << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Declare the vector data type that you would like to use in your // application. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::VectorData<double> InputVectorDataType; typedef otb::VectorData<double> OutputVectorDataType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Declare and instantiate the vector data reader: // \doxygen{otb}{VectorDataFileReader}. The call to the // \code{UpdateOutputInformation()} method fill up the header information. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VectorDataFileReader<InputVectorDataType> - VectorDataFileReaderType; - VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + typedef otb::VectorDataFileReader<InputVectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); reader->SetFileName(argv[1]); reader->UpdateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We need the image only to retrieve its projection information, // i.e. map projection or sensor model parameters. Hence, the image // pixels won't be read, only the header information using the // \code{UpdateOutputInformation()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<unsigned short int, 2> ImageType; typedef otb::ImageFileReader<ImageType> ImageReaderType; - ImageReaderType::Pointer imageReader = ImageReaderType::New(); + ImageReaderType::Pointer imageReader = ImageReaderType::New(); imageReader->SetFileName(argv[2]); imageReader->UpdateOutputInformation(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{VectorDataProjectionFilter} will do the work of // converting the vector data coordinates. It is usually a good idea // to use it when you design applications reading or saving vector // data. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::VectorDataProjectionFilter<InputVectorDataType, - OutputVectorDataType> - VectorDataFilterType; - VectorDataFilterType::Pointer vectorDataProjection = - VectorDataFilterType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + typedef otb::VectorDataProjectionFilter<InputVectorDataType, OutputVectorDataType> VectorDataFilterType; + VectorDataFilterType::Pointer vectorDataProjection = VectorDataFilterType::New(); + // Information concerning the original projection of the vector data // will be automatically retrieved from the metadata. Nothing else // is needed from you: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet vectorDataProjection->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Information about the target projection is retrieved directly from // the image: - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - vectorDataProjection->SetOutputKeywordList( - imageReader->GetOutput()->GetImageKeywordlist()); - vectorDataProjection->SetOutputOrigin( - imageReader->GetOutput()->GetOrigin()); - vectorDataProjection->SetOutputSpacing( - imageReader->GetOutput()->GetSignedSpacing()); - vectorDataProjection->SetOutputProjectionRef( - imageReader->GetOutput()->GetProjectionRef()); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + + vectorDataProjection->SetOutputKeywordList(imageReader->GetOutput()->GetImageKeywordlist()); + vectorDataProjection->SetOutputOrigin(imageReader->GetOutput()->GetOrigin()); + vectorDataProjection->SetOutputSpacing(imageReader->GetOutput()->GetSignedSpacing()); + vectorDataProjection->SetOutputProjectionRef(imageReader->GetOutput()->GetProjectionRef()); + // Finally, the result is saved into a new vector file. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::VectorDataFileWriter<OutputVectorDataType> - VectorDataFileWriterType; - VectorDataFileWriterType::Pointer writer = VectorDataFileWriterType::New(); + typedef otb::VectorDataFileWriter<OutputVectorDataType> VectorDataFileWriterType; + VectorDataFileWriterType::Pointer writer = VectorDataFileWriterType::New(); writer->SetFileName(argv[3]); writer->SetInput(vectorDataProjection->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // It is worth noting that none of this code is specific to the // vector data format. Whether you pass a shapefile, or a KML file, // the correct driver will be automatically instantiated. - // - // Software Guide : EndLatex return EXIT_SUCCESS; - } diff --git a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index ebb93bff4c933bb8e9222467abd031345200b9d8..26d2bf45be16036466ed806a8ca7f434776a51cb 100644 --- a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -19,15 +19,18 @@ */ +/* Example usage: +./ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter Input/VegetationIndex.hd \ + Output/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif \ + Output/pretty_VegetationIndex.png \ + Output/pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.png \ + 1 \ + 3 \ + 2 \ + 0.6 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {VegetationIndex.hd} -// OUTPUTS: {ARVIMultiChannelRAndBAndNIRVegetationIndex.tif} , {pretty_VegetationIndex.png} , {pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.png} -// 1 3 2 0.6 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // \index{otb::MultiChannelRAndBAndNIRIndexImageFilter} // \index{otb::MultiChannelRAndBAndNIRIndexImageFilter!header} // \index{otb::VegetationIndices} @@ -80,11 +83,8 @@ // Let's look at the minimal code required to use this algorithm. First, the following header // defining the \doxygen{otb}{MultiChannelRAndBAndNIRIndexImageFilter} // class must be included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMultiChannelRAndBAndNIRIndexImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -94,178 +94,105 @@ #include "otbMultiChannelExtractROI.h" #include "itkThresholdImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 8) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputImage , outputImage , prettyInput , prettyOutput , redChannel , blueChannel , nirChannel , gama" - << std::endl; + std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , blueChannel , nirChannel , gama" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // The image types are now defined using pixel types and // dimension. The input image is defined as an \doxygen{otb}{VectorImage}, // the output is a \doxygen{otb}{Image}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double InputPixelType; typedef float OutputPixelType; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : BeginLatex - // // The ARVI (Atmospherically Resistant Vegetation Index) is // instantiated using the image pixel types as template parameters. // Note that we also can use other functors which operate with the // Red, Blue and Nir channels such as EVI, ARVI and TSARVI. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Functor::ARVI<InputPixelType, - InputPixelType, - InputPixelType, - OutputPixelType> FunctorType; - // Software Guide : EndCodeSnippet + typedef otb::Functor::ARVI<InputPixelType, InputPixelType, InputPixelType, OutputPixelType> FunctorType; - // Software Guide : BeginLatex - // // The // \doxygen{otb}{MultiChannelRAndBAndNIRIndexImageFilter} // type is defined using the image types and the ARVI functor as // template parameters. We then instantiate the filter itself. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MultiChannelRAndBAndNIRIndexImageFilter - <InputImageType, - OutputImageType, - FunctorType> - MultiChannelRAndBAndNIRIndexImageFilterType; + typedef otb::MultiChannelRAndBAndNIRIndexImageFilter<InputImageType, OutputImageType, FunctorType> MultiChannelRAndBAndNIRIndexImageFilterType; - MultiChannelRAndBAndNIRIndexImageFilterType::Pointer - filter = MultiChannelRAndBAndNIRIndexImageFilterType::New(); - // Software Guide : EndCodeSnippet + MultiChannelRAndBAndNIRIndexImageFilterType::Pointer filter = MultiChannelRAndBAndNIRIndexImageFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex - // // Now the input image is set and a name is given to the output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The three used index bands (red, blue and NIR) are declared. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetRedIndex(::atoi(argv[5])); filter->SetBlueIndex(::atoi(argv[6])); filter->SetNIRIndex(::atoi(argv[7])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The $\gamma$ parameter is set. The // \doxygen{otb}{MultiChannelRAndBAndNIRIndexImageFilter} // class sets the default value of $\gamma$ to $0.5$. This parameter // is used to reduce the atmospheric effect on a global scale. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->GetFunctor().SetGamma(::atof(argv[8])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter input is linked to the reader output and // the filter output is linked to the writer input. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// -// The invocation of the \code{Update()} method on the writer triggers the -// execution of the pipeline. It is recommended to place update calls in a -// \code{try/catch} block in case errors occur and exceptions are thrown. -// -// Software Guide : EndLatex + // The invocation of the \code{Update()} method on the writer triggers the + // execution of the pipeline. It is recommended to place update calls in a + // \code{try/catch} block in case errors occur and exceptions are thrown. - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } // Pretty image creation for the printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::VectorImage<unsigned char, - Dimension> - OutputVectorPrettyImageType; - typedef otb::ImageFileWriter<OutputVectorPrettyImageType> - WriterVectorPrettyType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyType; - typedef itk::RescaleIntensityImageFilter<OutputImageType, - OutputPrettyImageType> - RescalerType; - typedef otb::VectorRescaleIntensityImageFilter<InputImageType, - OutputVectorPrettyImageType> - VectorRescalerType; - typedef otb::MultiChannelExtractROI<unsigned char, - unsigned char> - ChannelExtractorType; - - VectorRescalerType::Pointer vectRescaler = - VectorRescalerType::New(); - ChannelExtractorType::Pointer selecter = - ChannelExtractorType::New(); - WriterVectorPrettyType::Pointer vectPrettyWriter = - WriterVectorPrettyType::New(); + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::VectorImage<unsigned char, Dimension> OutputVectorPrettyImageType; + typedef otb::ImageFileWriter<OutputVectorPrettyImageType> WriterVectorPrettyType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputPrettyImageType> RescalerType; + typedef otb::VectorRescaleIntensityImageFilter<InputImageType, OutputVectorPrettyImageType> VectorRescalerType; + typedef otb::MultiChannelExtractROI<unsigned char, unsigned char> ChannelExtractorType; + + VectorRescalerType::Pointer vectRescaler = VectorRescalerType::New(); + ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); + WriterVectorPrettyType::Pointer vectPrettyWriter = WriterVectorPrettyType::New(); OutputVectorPrettyImageType::PixelType minimum, maximum; minimum.SetSize(reader->GetOutput()->GetNumberOfComponentsPerPixel()); @@ -302,25 +229,23 @@ int main(int argc, char *argv[]) prettyWriter->SetInput(rescaler->GetOutput()); try - { + { prettyWriter->Update(); vectPrettyWriter->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; - // Software Guide : BeginLatex - // // Let's now run this example using as input the image // \code{IndexVegetation.hd} (image kindly and free of charge given // by SISA and CNES) and $\gamma$=0.6 provided in the @@ -333,7 +258,4 @@ int main(int argc, char *argv[]) // \itkcaption[ARVI Example]{ARVI result on the right with the left image in input.} // \label{fig:ARVIMultiChannelRAndBAndNIRIndexImageFilter} // \end{figure} - // - // Software Guide : EndLatex - } diff --git a/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx index a95b7f4b03cf4c25496fa52924712558010c5aa1..ebaaf182df290622a6dc4adf20fe150d215d86dc 100644 --- a/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx @@ -19,15 +19,20 @@ */ +/* Example usage: +./AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter Input/verySmallFSATSW.tif \ + Output/AVIMultiChannelRAndGAndNIRVegetationIndex.tif \ + Output/pretty_FSATSW.png \ + Output/pretty_AVIMultiChannelRAndGAndNIRVegetationIndex.png \ + 3 \ + 2 \ + 4 \ + 660 \ + 560 \ + 830 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {verySmallFSATSW.tif} -// OUTPUTS: {AVIMultiChannelRAndGAndNIRVegetationIndex.tif} , {pretty_FSATSW.png} , {pretty_AVIMultiChannelRAndGAndNIRVegetationIndex.png} -// 3 2 4 660 560 830 -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // \index{otb::MultiChannelRAndGAndNIRIndexImageFilter} // \index{otb::MultiChannelRAndGAndNIRIndexImageFilter!header} // \index{otb::VegetationIndex} @@ -65,11 +70,8 @@ // algorithm. First, the following header defining the // \doxygen{otb}{MultiChannelRAndGAndNIRIndexImageFilter} // class must be included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMultiChannelRAndGAndNIRIndexImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" @@ -79,174 +81,106 @@ #include "otbMultiChannelExtractROI.h" #include "itkThresholdImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 11) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ,"; + std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ,"; std::cerr << " lambdaR, lambdaG, lambdaNIR " << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // The image types are now defined using pixel types and // dimension. The input image is defined as an \doxygen{otb}{VectorImage}, // the output is a \doxygen{otb}{Image}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double InputPixelType; typedef float OutputPixelType; typedef otb::VectorImage<InputPixelType, Dimension> InputImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : BeginLatex - // // The AVI (Angular Vegetation Index) is // instantiated using the image pixel types as template parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Functor::AVI<InputPixelType, InputPixelType, - InputPixelType, OutputPixelType> FunctorType; - // Software Guide : EndCodeSnippet + typedef otb::Functor::AVI<InputPixelType, InputPixelType, InputPixelType, OutputPixelType> FunctorType; - // Software Guide : BeginLatex - // // The // \doxygen{otb}{MultiChannelRAndGAndNIRIndexImageFilter} // type is defined using the image types and the AVI functor as // template parameters. We then instantiate the filter itself. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::MultiChannelRAndGAndNIRIndexImageFilter - <InputImageType, OutputImageType, FunctorType> - MultiChannelRAndGAndNIRIndexImageFilterType; + typedef otb::MultiChannelRAndGAndNIRIndexImageFilter<InputImageType, OutputImageType, FunctorType> MultiChannelRAndGAndNIRIndexImageFilterType; - MultiChannelRAndGAndNIRIndexImageFilterType::Pointer - filter = MultiChannelRAndGAndNIRIndexImageFilterType::New(); - // Software Guide : EndCodeSnippet + MultiChannelRAndGAndNIRIndexImageFilterType::Pointer filter = MultiChannelRAndGAndNIRIndexImageFilterType::New(); ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex - // // Now the input image is set and a name is given to the output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The three used index bands (red, green and NIR) are declared. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetRedIndex(::atoi(argv[5])); filter->SetGreenIndex(::atoi(argv[6])); filter->SetNIRIndex(::atoi(argv[7])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The $\lambda$ R, G and NIR parameters are set. The // \doxygen{otb}{MultiChannelRAndGAndNIRIndexImageFilter} // class sets the default values of $\lambda$ to $660$, $560$ and // $830$. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->GetFunctor().SetLambdaR(::atof(argv[8])); filter->GetFunctor().SetLambdaG(::atof(argv[9])); filter->GetFunctor().SetLambdaNir(::atof(argv[10])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The filter input is linked to the reader output and // the filter output is linked to the writer input. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The invocation of the \code{Update()} method on the writer triggers the // execution of the pipeline. It is recommended to place update calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } // Pretty image creation for the printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::VectorImage<unsigned char, - Dimension> - OutputVectorPrettyImageType; - typedef otb::ImageFileWriter<OutputVectorPrettyImageType> - WriterVectorPrettyType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyType; - typedef itk::RescaleIntensityImageFilter<OutputImageType, - OutputPrettyImageType> - RescalerType; - typedef otb::VectorRescaleIntensityImageFilter<InputImageType, - OutputVectorPrettyImageType> - VectorRescalerType; - typedef otb::MultiChannelExtractROI<unsigned char, - unsigned char> - ChannelExtractorType; - - VectorRescalerType::Pointer vectRescaler = - VectorRescalerType::New(); - ChannelExtractorType::Pointer selecter = - ChannelExtractorType::New(); - WriterVectorPrettyType::Pointer vectPrettyWriter = - WriterVectorPrettyType::New(); + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::VectorImage<unsigned char, Dimension> OutputVectorPrettyImageType; + typedef otb::ImageFileWriter<OutputVectorPrettyImageType> WriterVectorPrettyType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputPrettyImageType> RescalerType; + typedef otb::VectorRescaleIntensityImageFilter<InputImageType, OutputVectorPrettyImageType> VectorRescalerType; + typedef otb::MultiChannelExtractROI<unsigned char, unsigned char> ChannelExtractorType; + + VectorRescalerType::Pointer vectRescaler = VectorRescalerType::New(); + ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); + WriterVectorPrettyType::Pointer vectPrettyWriter = WriterVectorPrettyType::New(); OutputVectorPrettyImageType::PixelType minimum, maximum; minimum.SetSize(reader->GetOutput()->GetNumberOfComponentsPerPixel()); @@ -255,7 +189,7 @@ int main(int argc, char *argv[]) maximum.Fill(255); vectRescaler->SetOutputMinimum(minimum); vectRescaler->SetOutputMaximum(maximum); -// vectRescaler->SetClampThreshold(1); + // vectRescaler->SetClampThreshold(1); vectRescaler->SetInput(reader->GetOutput()); selecter->SetInput(vectRescaler->GetOutput()); @@ -283,25 +217,23 @@ int main(int argc, char *argv[]) prettyWriter->SetInput(rescaler->GetOutput()); try - { + { prettyWriter->Update(); vectPrettyWriter->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; - // Software Guide : BeginLatex - // // Let's now run this example using as input the image // \code{verySmallFSATSW.tif} provided in the // directory \code{Examples/Data}. @@ -313,7 +245,4 @@ int main(int argc, char *argv[]) // \itkcaption[AVI Example]{AVI result on the right with the left image in input.} // \label{fig:AVIMultiChannelRAndGAndNIRIndexImageFilter} // \end{figure} - // - // Software Guide : EndLatex - } diff --git a/Examples/Radiometry/AtmosphericCorrectionSequencement.cxx b/Examples/Radiometry/AtmosphericCorrectionSequencement.cxx index b898b50f47bfdae842a731fb27f44876ef99ca92..28a339949480182697f9196357063d1cf7d7ca9f 100644 --- a/Examples/Radiometry/AtmosphericCorrectionSequencement.cxx +++ b/Examples/Radiometry/AtmosphericCorrectionSequencement.cxx @@ -19,15 +19,27 @@ */ +/* Example usage: +./AtmosphericCorrectionSequencement Input/Romania_Extract.tif \ + Output/AtmosphericCorrectionSequencement.tif \ + Input/atmosphericCorrectionSequencement_alpha_beta.txt \ + Input/atmosphericCorrectionSequencement_solar_illumination.txt \ + Input/atmosphericCorrectionSequencement_wavelength_spectral_bands_spot4_1.txt \ + 27.3 \ + 4 \ + 12 \ + 152.7 \ + 2.5 \ + -77.0 \ + 1013. \ + 2.48134 \ + 0.34400 \ + 1 \ + 0.199854 \ + 2 \ + 0.020 +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {Romania_Extract.tif} -// OUTPUTS: {AtmosphericCorrectionSequencement.tif} -// ${OTB_DATA_ROOT}/Input/atmosphericCorrectionSequencement_alpha_beta.txt ${OTB_DATA_ROOT}/Input/atmosphericCorrectionSequencement_solar_illumination.txt ${OTB_DATA_ROOT}/Input/atmosphericCorrectionSequencement_wavelength_spectral_bands_spot4_1.txt 27.3 4 12 152.7 2.5 -77.0 1013. 2.48134 0.34400 1 0.199854 2 0.020 -// Software Guide : EndCommandLineArgs - -// Software Guide : BeginLatex -// // \index{otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter} // \index{otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter!header} // \index{otb::VegetationIndex} @@ -65,16 +77,12 @@ // refletance image, and reflectance to atmospheric correction image // corrections and the neighborhood correction, four header files are // required. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageToRadianceImageFilter.h" #include "otbRadianceToReflectanceImageFilter.h" #include "otbReflectanceToSurfaceReflectanceImageFilter.h" #include "otbSurfaceAdjacencyEffectCorrectionSchemeFilter.h" -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex // In version 4.2, the class \code{SurfaceAdjacencyEffect6SCorrectionSchemeFilter} // has been renamed into \doxygen{otb}{SurfaceAdjacencyEffectCorrectionSchemeFilter}, // but it still does the same thing. @@ -101,83 +109,67 @@ // contains a single static method that calls the 6S library. The header // also includes the classes to manipulate correction parameters and radiative // terms. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include <string> -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 19) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0] << std::endl; - std::cerr << - " inputImage outputImage atmosphericCorrectionSequencement_alpha_beta.txt atmosphericCorrectionSequencement_solar_illumination.txt atmosphericCorrectionSequencement_wavelength_spectral_bands_spot4_1.txt SolarZenithalAngle day month SolarAzimuthalAngle ViewingZenithalAngle ViewingAzimuthalAngle AtmosphericPresure WaterVaporAmount OzoneAmount AerosolModel AerosolOpticalThickness WindowRadiusForAdjacencyCorrection PixelSpacing" + std::cerr << " inputImage outputImage atmosphericCorrectionSequencement_alpha_beta.txt atmosphericCorrectionSequencement_solar_illumination.txt " + "atmosphericCorrectionSequencement_wavelength_spectral_bands_spot4_1.txt SolarZenithalAngle day month SolarAzimuthalAngle " + "ViewingZenithalAngle ViewingAzimuthalAngle AtmosphericPresure WaterVaporAmount OzoneAmount AerosolModel AerosolOpticalThickness " + "WindowRadiusForAdjacencyCorrection PixelSpacing" << std::endl; std::cerr << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // Image types are now defined using pixel types and // dimension. The input image is defined as an \doxygen{otb}{VectorImage}, // the output image is a \doxygen{otb}{VectorImage}. To simplify, input and // output image types are the same one. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double PixelType; typedef otb::VectorImage<PixelType, Dimension> ImageType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); - // Software Guide : BeginLatex - // // The \code{GenerateOutputInformation()} reader method is called // to know the number of component per pixel of the image. It is // recommended to // place \code{GenerateOutputInformation} calls in a \code{try/catch} block in case // errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); try - { + { reader->GenerateOutputInformation(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } - unsigned int nbOfComponent = - reader->GetOutput()->GetNumberOfComponentsPerPixel(); + unsigned int nbOfComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel(); //------------------------------- - // Software Guide : BeginLatex - // // The \doxygen{otb}{ImageToRadianceImageFilter} // type is defined and instancied. This class uses a functor applied // to each component of each pixel ($\mathbf{X^{k}}$) whose formula is: @@ -194,46 +186,34 @@ int main(int argc, char *argv[]) // \item $\alpha_{k}$ is the absolute calibration gain for the channel k; // \item $\beta_{k}$ is the absolute calibration bias for the channel k. // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::ImageToRadianceImageFilter<ImageType, ImageType> - ImageToRadianceImageFilterType; + typedef otb::ImageToRadianceImageFilter<ImageType, ImageType> ImageToRadianceImageFilterType; - ImageToRadianceImageFilterType::Pointer filterImageToRadiance - = ImageToRadianceImageFilterType::New(); -// Software Guide : EndCodeSnippet + ImageToRadianceImageFilterType::Pointer filterImageToRadiance = ImageToRadianceImageFilterType::New(); typedef ImageToRadianceImageFilterType::VectorType VectorType; - VectorType alpha(nbOfComponent); - VectorType beta(nbOfComponent); + VectorType alpha(nbOfComponent); + VectorType beta(nbOfComponent); alpha.Fill(0); beta.Fill(0); std::ifstream fin; fin.open(argv[3]); double dalpha(0.), dbeta(0.); for (unsigned int i = 0; i < nbOfComponent; ++i) - { + { fin >> dalpha; fin >> dbeta; alpha[i] = dalpha; - beta[i] = dbeta; - } + beta[i] = dbeta; + } fin.close(); - // Software Guide : BeginLatex // Here, $\alpha$ and $\beta$ are read from an ASCII file given in input, // stored in a vector and passed to the class. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filterImageToRadiance->SetAlpha(alpha); filterImageToRadiance->SetBeta(beta); - // Software Guide : EndCodeSnippet //------------------------------- - // Software Guide : BeginLatex - // // The \doxygen{otb}{RadianceToReflectanceImageFilter} // type is defined and instancied. // This class used a functor applied to each component of each pixel @@ -255,15 +235,9 @@ int main(int argc, char *argv[]) // In the last case (that is the one of this example), the user has to precise // the month and the day of the acquisition. // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::RadianceToReflectanceImageFilter<ImageType, ImageType> - RadianceToReflectanceImageFilterType; - RadianceToReflectanceImageFilterType::Pointer filterRadianceToReflectance - = RadianceToReflectanceImageFilterType::New(); -// Software Guide : EndCodeSnippet + typedef otb::RadianceToReflectanceImageFilter<ImageType, ImageType> RadianceToReflectanceImageFilterType; + RadianceToReflectanceImageFilterType::Pointer filterRadianceToReflectance = RadianceToReflectanceImageFilterType::New(); typedef RadianceToReflectanceImageFilterType::VectorType VectorType; @@ -273,77 +247,54 @@ int main(int argc, char *argv[]) fin.open(argv[4]); double dsolarIllumination(0.); for (unsigned int i = 0; i < nbOfComponent; ++i) - { + { fin >> dsolarIllumination; solarIllumination[i] = dsolarIllumination; - } + } fin.close(); - // Software Guide : BeginLatex // The solar illumination is read from a ASCII file given in input, // stored in a vector // and given to the class. // Day, month and zenital solar angle are inputs and can be directly given to the class. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - filterRadianceToReflectance->SetZenithalSolarAngle( - static_cast<double>(atof(argv[6]))); + filterRadianceToReflectance->SetZenithalSolarAngle(static_cast<double>(atof(argv[6]))); filterRadianceToReflectance->SetDay(atoi(argv[7])); filterRadianceToReflectance->SetMonth(atoi(argv[8])); filterRadianceToReflectance->SetSolarIllumination(solarIllumination); - // Software Guide : EndCodeSnippet -//------------------------------- -// Software Guide : BeginLatex -// -// At this step of the chain, radiative information are nedeed to compute -// the contribution of the atmosphere (such as atmosphere transmittance -// and reflectance). Those information will be computed from different -// correction parameters stored in \doxygen{otb}{AtmosphericCorrectionParameters} -// and \doxygen{otb}{ImageMetadataCorrectionParameters} instances. -// These {\em containers} will be given to the static function \texttt{Compute} -// from \doxygen{otb}{RadiometryCorrectionParametersToAtmosphericRadiativeTerms} -// class, which will call a 6S routine that will compute the needed -// radiometric information and store them in a -// \doxygen{otb}{AtmosphericRadiativeTerms} class instance. -// For this, -// \doxygen{otb}{RadiometryCorrectionParametersToAtmosphericRadiativeTerms}, -// \doxygen{otb}{AtmosphericCorrectionParameters}, -// \doxygen{otb}{ImageMetadataCorrectionParameters} and -// \doxygen{otb}{AtmosphericRadiativeTerms} -// types are defined and instancied. -// -// Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::RadiometryCorrectionParametersToAtmosphericRadiativeTerms - RadiometryCorrectionParametersToRadiativeTermsType; - - typedef otb::AtmosphericCorrectionParameters - AtmosphericCorrectionParametersType; - - typedef otb::ImageMetadataCorrectionParameters - AcquisitionCorrectionParametersType; - - typedef otb::AtmosphericRadiativeTerms - AtmosphericRadiativeTermsType; - // Software Guide : EndCodeSnippet - typedef AtmosphericCorrectionParametersType::AerosolModelType - AerosolModelType; - typedef otb::FilterFunctionValues - FilterFunctionValuesType; - typedef FilterFunctionValuesType::ValuesVectorType - ValuesVectorType; - - AtmosphericCorrectionParametersType::Pointer - dataAtmosphericCorrectionParameters = - AtmosphericCorrectionParametersType::New(); - AcquisitionCorrectionParametersType::Pointer - dataAcquisitionCorrectionParameters = - AcquisitionCorrectionParametersType::New(); - AtmosphericRadiativeTermsType::Pointer dataAtmosphericRadiativeTerms = - AtmosphericRadiativeTermsType::New(); + //------------------------------- + // At this step of the chain, radiative information are nedeed to compute + // the contribution of the atmosphere (such as atmosphere transmittance + // and reflectance). Those information will be computed from different + // correction parameters stored in \doxygen{otb}{AtmosphericCorrectionParameters} + // and \doxygen{otb}{ImageMetadataCorrectionParameters} instances. + // These {\em containers} will be given to the static function \texttt{Compute} + // from \doxygen{otb}{RadiometryCorrectionParametersToAtmosphericRadiativeTerms} + // class, which will call a 6S routine that will compute the needed + // radiometric information and store them in a + // \doxygen{otb}{AtmosphericRadiativeTerms} class instance. + // For this, + // \doxygen{otb}{RadiometryCorrectionParametersToAtmosphericRadiativeTerms}, + // \doxygen{otb}{AtmosphericCorrectionParameters}, + // \doxygen{otb}{ImageMetadataCorrectionParameters} and + // \doxygen{otb}{AtmosphericRadiativeTerms} + // types are defined and instancied. + + typedef otb::RadiometryCorrectionParametersToAtmosphericRadiativeTerms RadiometryCorrectionParametersToRadiativeTermsType; + + typedef otb::AtmosphericCorrectionParameters AtmosphericCorrectionParametersType; + + typedef otb::ImageMetadataCorrectionParameters AcquisitionCorrectionParametersType; + + typedef otb::AtmosphericRadiativeTerms AtmosphericRadiativeTermsType; + typedef AtmosphericCorrectionParametersType::AerosolModelType AerosolModelType; + typedef otb::FilterFunctionValues FilterFunctionValuesType; + typedef FilterFunctionValuesType::ValuesVectorType ValuesVectorType; + + AtmosphericCorrectionParametersType::Pointer dataAtmosphericCorrectionParameters = AtmosphericCorrectionParametersType::New(); + AcquisitionCorrectionParametersType::Pointer dataAcquisitionCorrectionParameters = AcquisitionCorrectionParametersType::New(); + AtmosphericRadiativeTermsType::Pointer dataAtmosphericRadiativeTerms = AtmosphericRadiativeTermsType::New(); float minSpectralValue(0.); float maxSpectralValue(0.); @@ -358,7 +309,7 @@ int main(int argc, char *argv[]) fin.open(argv[5]); fin >> nbBands; for (unsigned int i = 0; i < nbBands; ++i) - { + { vector.clear(); fin >> sString; fin >> minSpectralValue; @@ -366,25 +317,20 @@ int main(int argc, char *argv[]) fin >> userStep; fin >> nbValuesPerBand; for (unsigned int j = 0; j < nbValuesPerBand; ++j) - { + { fin >> value; vector.push_back(value); - } - FilterFunctionValuesType::Pointer functionValues = - FilterFunctionValuesType::New(); + } + FilterFunctionValuesType::Pointer functionValues = FilterFunctionValuesType::New(); functionValues->SetFilterFunctionValues(vector); functionValues->SetMinSpectralValue(minSpectralValue); functionValues->SetMaxSpectralValue(maxSpectralValue); functionValues->SetUserStep(userStep); - dataAcquisitionCorrectionParameters->SetWavelengthSpectralBandWithIndex( - i, - functionValues); - } + dataAcquisitionCorrectionParameters->SetWavelengthSpectralBandWithIndex(i, functionValues); + } fin.close(); - // Software Guide : BeginLatex - // // The \doxygen{otb}{ImageMetadataCorrectionParameters} class stores // several parameters that are generally present in the image metadata : // \begin{itemize} @@ -402,30 +348,20 @@ int main(int argc, char *argv[]) // When this container is not set in the ReflectanceToSurfaceReflectance // filter, it is automatically filled using the image metadata. The // following lines show that it is also possible to set the values manually. - // - // Software Guide : EndLatex // Set parameters - // Software Guide : BeginCodeSnippet - dataAcquisitionCorrectionParameters->SetSolarZenithalAngle( - static_cast<double>(atof(argv[6]))); + dataAcquisitionCorrectionParameters->SetSolarZenithalAngle(static_cast<double>(atof(argv[6]))); - dataAcquisitionCorrectionParameters->SetSolarAzimutalAngle( - static_cast<double>(atof(argv[9]))); + dataAcquisitionCorrectionParameters->SetSolarAzimutalAngle(static_cast<double>(atof(argv[9]))); - dataAcquisitionCorrectionParameters->SetViewingZenithalAngle( - static_cast<double>(atof(argv[10]))); + dataAcquisitionCorrectionParameters->SetViewingZenithalAngle(static_cast<double>(atof(argv[10]))); - dataAcquisitionCorrectionParameters->SetViewingAzimutalAngle( - static_cast<double>(atof(argv[11]))); + dataAcquisitionCorrectionParameters->SetViewingAzimutalAngle(static_cast<double>(atof(argv[11]))); dataAcquisitionCorrectionParameters->SetMonth(atoi(argv[8])); dataAcquisitionCorrectionParameters->SetDay(atoi(argv[7])); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // The \doxygen{otb}{AtmosphericCorrectionParameters} class stores // physical parameters of the atmosphere that are not impacted // by the viewing angles of the image : @@ -439,48 +375,29 @@ int main(int argc, char *argv[]) // \item The aerosol optical thickness at 550 nm that is the is the Radiative impact // of aerosol for the reference wavelength 550 nm; // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - dataAtmosphericCorrectionParameters->SetAtmosphericPressure( - static_cast<double>(atof(argv[12]))); + dataAtmosphericCorrectionParameters->SetAtmosphericPressure(static_cast<double>(atof(argv[12]))); - dataAtmosphericCorrectionParameters->SetWaterVaporAmount( - static_cast<double>(atof(argv[13]))); + dataAtmosphericCorrectionParameters->SetWaterVaporAmount(static_cast<double>(atof(argv[13]))); - dataAtmosphericCorrectionParameters->SetOzoneAmount( - static_cast<double>(atof(argv[14]))); + dataAtmosphericCorrectionParameters->SetOzoneAmount(static_cast<double>(atof(argv[14]))); - AerosolModelType aerosolModel = - static_cast<AerosolModelType>(::atoi(argv[15])); + AerosolModelType aerosolModel = static_cast<AerosolModelType>(::atoi(argv[15])); dataAtmosphericCorrectionParameters->SetAerosolModel(aerosolModel); - dataAtmosphericCorrectionParameters->SetAerosolOptical( - static_cast<double>(atof(argv[16]))); - // Software Guide : EndCodeSnippet + dataAtmosphericCorrectionParameters->SetAerosolOptical(static_cast<double>(atof(argv[16]))); - // Software Guide : BeginLatex - // // Once those parameters are loaded, they are used by the 6S library // to compute the needed radiometric information. The // RadiometryCorrectionParametersToAtmosphericRadiativeTerms class // provides a static function to perform this step\footnote{Before version // 4.2, it was done with the filter // AtmosphericCorrectionParametersTo6SAtmosphericRadiativeTerms}. - // - // Software Guide : EndLatex -// Software Guide : BeginCodeSnippet AtmosphericRadiativeTermsType::Pointer atmosphericRadiativeTerms = - RadiometryCorrectionParametersToRadiativeTermsType::Compute( - dataAtmosphericCorrectionParameters, - dataAcquisitionCorrectionParameters); - // Software Guide : EndCodeSnippet + RadiometryCorrectionParametersToRadiativeTermsType::Compute(dataAtmosphericCorrectionParameters, dataAcquisitionCorrectionParameters); - // Software Guide : BeginLatex - // // The output is stored inside an instance of the // \doxygen{otb}{AtmosphericRadiativeTerms} class. // This class contains (for each channel of the image) @@ -492,26 +409,16 @@ int main(int argc, char *argv[]) // \item The total transmittance of the atmosphere from sun to ground (downward transmittance) // and from ground to space sensor (upward transmittance). // \end{itemize} - // - // Software Guide : EndLatex -//------------------------------- -// Software Guide : BeginLatex -// Atmospheric corrections can now start. -// First, an instance of \doxygen{otb}{ReflectanceToSurfaceReflectanceImageFilter} is created. -// Software Guide : EndLatex + //------------------------------- + // Atmospheric corrections can now start. + // First, an instance of \doxygen{otb}{ReflectanceToSurfaceReflectanceImageFilter} is created. - // Software Guide : BeginCodeSnippet - typedef otb::ReflectanceToSurfaceReflectanceImageFilter<ImageType, - ImageType> - ReflectanceToSurfaceReflectanceImageFilterType; + typedef otb::ReflectanceToSurfaceReflectanceImageFilter<ImageType, ImageType> ReflectanceToSurfaceReflectanceImageFilterType; - ReflectanceToSurfaceReflectanceImageFilterType::Pointer - filterReflectanceToSurfaceReflectanceImageFilter - = ReflectanceToSurfaceReflectanceImageFilterType::New(); - // Software Guide : EndCodeSnippet + ReflectanceToSurfaceReflectanceImageFilterType::Pointer filterReflectanceToSurfaceReflectanceImageFilter = + ReflectanceToSurfaceReflectanceImageFilterType::New(); - // Software Guide : BeginLatex // The aim of the atmospheric correction is to invert the surface reflectance // (for each pixel of the input image) from the TOA reflectance and from simulations // of the atmospheric radiative functions corresponding to the geometrical conditions @@ -539,71 +446,57 @@ int main(int argc, char *argv[]) // \end{itemize} // All those parameters are contained in the AtmosphericRadiativeTerms // container. - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - filterReflectanceToSurfaceReflectanceImageFilter-> - SetAtmosphericRadiativeTerms(atmosphericRadiativeTerms); - // Software Guide : EndCodeSnippet - -//------------------------------- -// Software Guide : BeginLatex -// Next (and last step) is the neighborhood correction. -// For this, the SurfaceAdjacencyEffectCorrectionSchemeFilter class is used. -// The previous surface reflectance inversion is performed under the assumption of a -// homogeneous ground environment. The following step allows correcting the adjacency -// effect on the radiometry of pixels. The method is based on the decomposition of -// the observed signal as the summation of the own contribution of the target pixel and -// of the contributions of neighbored pixels moderated by their distance to the target pixel. -// A simplified relation may be : -// \begin{equation} -// \rho{S} = \frac{ \rho_{S}^{unif}.T(\mu_{V}) - <\rho{S}>.t_{d}(\mu_{V}) }{ exp(-\delta/\mu_{V}) } -// \end{equation} -// With : -// \begin{itemize} -// \item $\rho_{S}^{unif}$ is the ground reflectance under assumption of an homogeneous environment; -// \item $T(\mu_{V})$ is the upward transmittance; -// \item $t_{d}(\mu_{S})$ is the upward diffus transmittance; -// \item $exp(-\delta/\mu_{V})$ is the upward direct transmittance; -// \item $\rho_{S}$ is the environment contribution to the pixel target reflectance in the total -// observed signal. -// \begin{equation} -// \rho{S} = \sum{j}\sum{i}f(r(i, j))\times \rho_{S}^{unif}(i, j) -// \end{equation} -// where, -// \begin{itemize} -// \item r(i, j) is the distance between the pixel(i, j) and the central pixel of the window in $km$; -// \item f(r) is the global environment function. -// \begin{equation} -// f(r) = \frac{t_{d}^{R}(\mu_{V}).f_{R}(r)+t_{d}^{A}(\mu_{V}).f_{A}(r)}{ t_{d}(\mu_{V}) } -// \end{equation} -// \end{itemize} -// \end{itemize} -// The neighborhood consideration window size is given by the window radius. -// -// An instance of \doxygen{otb}{SurfaceAdjacencyEffectCorrectionSchemeFilter} -// is created. This class has an interface quite similar to -// \doxygen{otb}{ReflectanceToSurfaceReflectance}. They both need radiative terms -// (\doxygen{otb}{AtmosphericRadiativeTerms}), so it is possible to compute -// them outside the filter and set them directly in the filter. The other -// solution is to give as input the two parameters containers ("atmospheric" -// and "acquisition" parameters), then the filter will compute the radiative -// terms internally. If the "acquisition" correction parameters are not -// present, the filter will try to get them from the image metadata. -// -// Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::SurfaceAdjacencyEffectCorrectionSchemeFilter<ImageType, - ImageType> - SurfaceAdjacencyEffectCorrectionSchemeFilterType; - SurfaceAdjacencyEffectCorrectionSchemeFilterType::Pointer - filterSurfaceAdjacencyEffectCorrectionSchemeFilter - = SurfaceAdjacencyEffectCorrectionSchemeFilterType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex + + filterReflectanceToSurfaceReflectanceImageFilter->SetAtmosphericRadiativeTerms(atmosphericRadiativeTerms); + + //------------------------------- + // Next (and last step) is the neighborhood correction. + // For this, the SurfaceAdjacencyEffectCorrectionSchemeFilter class is used. + // The previous surface reflectance inversion is performed under the assumption of a + // homogeneous ground environment. The following step allows correcting the adjacency + // effect on the radiometry of pixels. The method is based on the decomposition of + // the observed signal as the summation of the own contribution of the target pixel and + // of the contributions of neighbored pixels moderated by their distance to the target pixel. + // A simplified relation may be : + // \begin{equation} + // \rho{S} = \frac{ \rho_{S}^{unif}.T(\mu_{V}) - <\rho{S}>.t_{d}(\mu_{V}) }{ exp(-\delta/\mu_{V}) } + // \end{equation} + // With : + // \begin{itemize} + // \item $\rho_{S}^{unif}$ is the ground reflectance under assumption of an homogeneous environment; + // \item $T(\mu_{V})$ is the upward transmittance; + // \item $t_{d}(\mu_{S})$ is the upward diffus transmittance; + // \item $exp(-\delta/\mu_{V})$ is the upward direct transmittance; + // \item $\rho_{S}$ is the environment contribution to the pixel target reflectance in the total + // observed signal. + // \begin{equation} + // \rho{S} = \sum{j}\sum{i}f(r(i, j))\times \rho_{S}^{unif}(i, j) + // \end{equation} + // where, + // \begin{itemize} + // \item r(i, j) is the distance between the pixel(i, j) and the central pixel of the window in $km$; + // \item f(r) is the global environment function. + // \begin{equation} + // f(r) = \frac{t_{d}^{R}(\mu_{V}).f_{R}(r)+t_{d}^{A}(\mu_{V}).f_{A}(r)}{ t_{d}(\mu_{V}) } + // \end{equation} + // \end{itemize} + // \end{itemize} + // The neighborhood consideration window size is given by the window radius. // + // An instance of \doxygen{otb}{SurfaceAdjacencyEffectCorrectionSchemeFilter} + // is created. This class has an interface quite similar to + // \doxygen{otb}{ReflectanceToSurfaceReflectance}. They both need radiative terms + // (\doxygen{otb}{AtmosphericRadiativeTerms}), so it is possible to compute + // them outside the filter and set them directly in the filter. The other + // solution is to give as input the two parameters containers ("atmospheric" + // and "acquisition" parameters), then the filter will compute the radiative + // terms internally. If the "acquisition" correction parameters are not + // present, the filter will try to get them from the image metadata. + + typedef otb::SurfaceAdjacencyEffectCorrectionSchemeFilter<ImageType, ImageType> SurfaceAdjacencyEffectCorrectionSchemeFilterType; + SurfaceAdjacencyEffectCorrectionSchemeFilterType::Pointer filterSurfaceAdjacencyEffectCorrectionSchemeFilter = + SurfaceAdjacencyEffectCorrectionSchemeFilterType::New(); + // Four inputs are needed to compute the neighborhood contribution: // \begin{itemize} // \item The radiative terms (stored in the AtmosphericRadiativeTerms container); @@ -611,64 +504,43 @@ int main(int argc, char *argv[]) // \item The neighborhood window radius; // \item The pixel spacing in kilometers. // \end{itemize} - // - // Software Guide : EndLatex - filterSurfaceAdjacencyEffectCorrectionSchemeFilter-> - SetAtmosphericRadiativeTerms(atmosphericRadiativeTerms); - filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetZenithalViewingAngle( - dataAcquisitionCorrectionParameters->GetViewingZenithalAngle()); - filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetWindowRadius(atoi(argv - [17])); - filterSurfaceAdjacencyEffectCorrectionSchemeFilter-> - SetPixelSpacingInKilometers(static_cast<double>(atof(argv[18]))); - -//------------------------------- + filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetAtmosphericRadiativeTerms(atmosphericRadiativeTerms); + filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetZenithalViewingAngle(dataAcquisitionCorrectionParameters->GetViewingZenithalAngle()); + filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetWindowRadius(atoi(argv[17])); + filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetPixelSpacingInKilometers(static_cast<double>(atof(argv[18]))); + + //------------------------------- WriterType::Pointer writer = WriterType::New(); -// Software Guide : BeginLatex -// -// At this step, each filter of the chain is instancied and every one has its -// input parameters set. A name can be given to the output image, each filter -// can be linked to the next one and create the final processing chain. -// -// Software Guide : EndLatex + // At this step, each filter of the chain is instancied and every one has its + // input parameters set. A name can be given to the output image, each filter + // can be linked to the next one and create the final processing chain. - // Software Guide : BeginCodeSnippet writer->SetFileName(argv[2]); filterImageToRadiance->SetInput(reader->GetOutput()); filterRadianceToReflectance->SetInput(filterImageToRadiance->GetOutput()); - filterReflectanceToSurfaceReflectanceImageFilter->SetInput( - filterRadianceToReflectance->GetOutput()); - filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetInput( - filterReflectanceToSurfaceReflectanceImageFilter->GetOutput()); + filterReflectanceToSurfaceReflectanceImageFilter->SetInput(filterRadianceToReflectance->GetOutput()); + filterSurfaceAdjacencyEffectCorrectionSchemeFilter->SetInput(filterReflectanceToSurfaceReflectanceImageFilter->GetOutput()); - writer->SetInput( - filterSurfaceAdjacencyEffectCorrectionSchemeFilter->GetOutput()); -// Software Guide : EndCodeSnippet + writer->SetInput(filterSurfaceAdjacencyEffectCorrectionSchemeFilter->GetOutput()); -// Software Guide : BeginLatex -// -// The invocation of the \code{Update()} method on the writer triggers the -// execution of the pipeline. It is recommended to place this call in a -// \code{try/catch} block in case errors occur and exceptions are thrown. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet + // The invocation of the \code{Update()} method on the writer triggers the + // execution of the pipeline. It is recommended to place this call in a + // \code{try/catch} block in case errors occur and exceptions are thrown. try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx index 6c994f9d5814dd5eea9d3f21485019daac14d0bf..a559e2a50275cc652a48438bbeffee61cc99f9b5 100644 --- a/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx @@ -19,14 +19,16 @@ */ +/* Example usage: +./NDVIRAndNIRVegetationIndexImageFilter Input/NDVI_2.hdr \ + Input/NDVI_3.hdr \ + Output/NDVIRAndNIRVegetationIndex.tif \ + Output/pretty_Red.png \ + Output/pretty_NIR.png \ + Output/pretty_NDVIRAndNIRVegetationIndex.png +*/ -// Software Guide : BeginCommandLineArgs -// INPUTS: {NDVI_2.hdr} , {NDVI_3.hdr} -// OUTPUTS: {NDVIRAndNIRVegetationIndex.tif} , {pretty_Red.png} , {pretty_NIR.png} , {pretty_NDVIRAndNIRVegetationIndex.png} -// Software Guide : EndCommandLineArgs -// Software Guide : BeginLatex -// // \index{otb::RAndNIRIndexImageFilter} // \index{otb::VegetationIndicesFunctor} // \index{otb::VegetationIndicesFunctor!header} @@ -61,11 +63,8 @@ // Let's look at the minimal code required to use this algorithm. First, the following header // defining the \doxygen{otb}{RAndNIRIndexImageFilter} // class must be included. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbRAndNIRIndexImageFilter.h" -// Software Guide : EndCodeSnippet #include "itkMacro.h" #include "otbImage.h" @@ -74,141 +73,89 @@ #include "itkUnaryFunctorImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 6) - { + { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << - " inputImage1 , inputImage2 , outputImage , prettyinputImage1 , prettyinputImage2 , prettyOutput" - << std::endl; + std::cerr << " inputImage1 , inputImage2 , outputImage , prettyinputImage1 , prettyinputImage2 , prettyOutput" << std::endl; return 1; - } + } - // Software Guide : BeginLatex - // // The image types are now defined using pixel types the // dimension. Input and output images are defined as \doxygen{otb}{Image}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef double InputPixelType; typedef float OutputPixelType; typedef otb::Image<InputPixelType, Dimension> InputRImageType; typedef otb::Image<InputPixelType, Dimension> InputNIRImageType; typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - // Software Guide : EndCodeSnippet // We instantiate reader and writer types typedef otb::ImageFileReader<InputRImageType> RReaderType; typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - // Software Guide : BeginLatex - // // The NDVI (Normalized Difference Vegetation Index) is instantiated using // the images pixel type as template parameters. It is // implemented as a functor class which will be passed as a // parameter to an \doxygen{otb}{RAndNIRIndexImageFilter}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Functor::NDVI<InputPixelType, - InputPixelType, - OutputPixelType> FunctorType; - // Software Guide : EndCodeSnippet + typedef otb::Functor::NDVI<InputPixelType, InputPixelType, OutputPixelType> FunctorType; - // Software Guide : BeginLatex - // // The \doxygen{otb}{RAndNIRIndexImageFilter} type is instantiated using the images // types and the NDVI functor as template parameters. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::RAndNIRIndexImageFilter<InputRImageType, - InputNIRImageType, - OutputImageType, - FunctorType> - RAndNIRIndexImageFilterType; - // Software Guide : EndCodeSnippet + typedef otb::RAndNIRIndexImageFilter<InputRImageType, InputNIRImageType, OutputImageType, FunctorType> RAndNIRIndexImageFilterType; // Instantiating object - RAndNIRIndexImageFilterType::Pointer filter = - RAndNIRIndexImageFilterType::New(); - RReaderType::Pointer readerR = RReaderType::New(); - NIRReaderType::Pointer readerNIR = NIRReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + RAndNIRIndexImageFilterType::Pointer filter = RAndNIRIndexImageFilterType::New(); + RReaderType::Pointer readerR = RReaderType::New(); + NIRReaderType::Pointer readerNIR = NIRReaderType::New(); + WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex - // // Now the input images are set and a name is given to the output image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet readerR->SetFileName(argv[1]); readerNIR->SetFileName(argv[2]); writer->SetFileName(argv[3]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We set the processing pipeline: filter inputs are linked to // the reader output and the filter output is linked to the writer // input. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInputR(readerR->GetOutput()); filter->SetInputNIR(readerNIR->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Invocation of the \code{Update()} method on the writer triggers the // execution of the pipeline. It is recommended to place \code{update()} calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet try - { + { writer->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } - // Software Guide : EndCodeSnippet + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } // Pretty image creation for the printing - typedef otb::Image<unsigned char, - Dimension> - OutputPrettyImageType; - typedef otb::ImageFileWriter<OutputPrettyImageType> - WriterPrettyType; - typedef itk::RescaleIntensityImageFilter<OutputImageType, - OutputPrettyImageType> RescalerType; - typedef itk::RescaleIntensityImageFilter<InputRImageType, - OutputPrettyImageType> RescalerRType; - typedef itk::RescaleIntensityImageFilter<InputNIRImageType, - OutputPrettyImageType> - RescalerNIRType; + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter<OutputImageType, OutputPrettyImageType> RescalerType; + typedef itk::RescaleIntensityImageFilter<InputRImageType, OutputPrettyImageType> RescalerRType; + typedef itk::RescaleIntensityImageFilter<InputNIRImageType, OutputPrettyImageType> RescalerNIRType; RescalerType::Pointer rescaler = RescalerType::New(); WriterPrettyType::Pointer prettyWriter = WriterPrettyType::New(); @@ -218,8 +165,8 @@ int main(int argc, char *argv[]) prettyWriter->SetFileName(argv[6]); prettyWriter->SetInput(rescaler->GetOutput()); - RescalerRType::Pointer rescalerR = RescalerRType::New(); - RescalerNIRType::Pointer rescalerNIR = RescalerNIRType::New(); + RescalerRType::Pointer rescalerR = RescalerRType::New(); + RescalerNIRType::Pointer rescalerNIR = RescalerNIRType::New(); WriterPrettyType::Pointer prettyWriterR = WriterPrettyType::New(); WriterPrettyType::Pointer prettyWriterNIR = WriterPrettyType::New(); rescalerR->SetInput(readerR->GetOutput()); @@ -235,24 +182,22 @@ int main(int argc, char *argv[]) prettyWriterNIR->SetInput(rescalerNIR->GetOutput()); try - { + { prettyWriter->Update(); prettyWriterNIR->Update(); prettyWriterR->Update(); - } + } catch (itk::ExceptionObject& excep) - { + { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; - } + } catch (...) - { + { std::cout << "Unknown exception !" << std::endl; return EXIT_FAILURE; - } + } - // Software Guide : BeginLatex - // // Let's now run this example using as input the images // \code{NDVI\_3.hdr} and \code{NDVI\_4.hdr} (images kindly and free of charge given by SISA and CNES) // provided in the directory \code{Examples/Data}. @@ -265,8 +210,6 @@ int main(int argc, char *argv[]) // \itkcaption[ARVI Example]{NDVI input images on the left (Red channel and NIR channel), on the right the result of the algorithm.} // \label{fig:NDVIRAndNIRIndex} // \end{figure} - // - // Software Guide : EndLatex return EXIT_SUCCESS; } diff --git a/Examples/Simulation/LAIAndPROSAILToSensorResponse.cxx b/Examples/Simulation/LAIAndPROSAILToSensorResponse.cxx index f747485a3af4b5de656e02178300364d52456815..7c6f3db7e6673d990531371f50f6db18b7b5e911 100644 --- a/Examples/Simulation/LAIAndPROSAILToSensorResponse.cxx +++ b/Examples/Simulation/LAIAndPROSAILToSensorResponse.cxx @@ -18,26 +18,26 @@ * limitations under the License. */ - - -// Software Guide : BeginCommandLineArgs -// -// INPUTS: {LAIverySmallFSATSW.tif, Simu_label_LAI.png, Simu_mask_LAI_1.png, label-params-SO-2006-Level-2.txt, acqui-params.txt, rep6S.dat} -// OUTPUTS: {siTvLAIAndPROSAILToSensorResponse.tif} -// 5 -// Software Guide : EndCommandLineArgs -// -// Software Guide : BeginLatex -// -// The following code is an example of Sensor spectral response image generated using image of labeled objects image, objects properties (vegetation classes are handled using PROSAIL model, non-vegetation classes -// are characterized using \href{http://speclib.jpl.nasa.gov/}{Aster database} characteristics provided by a text file), acquisition parameters, sensor characteristics, and LAI (Leaf Area Index) image. +/* Example usage: +./LAIAndPROSAILToSensorResponse Input/LAIverySmallFSATSW.tif \ + Input/Simu_label_LAI.png \ + Input/Simu_mask_LAI_1.png \ + Input/label-params-SO-2006-Level-2.txt \ + Input/acqui-params.txt \ + Input/rep6S.dat \ + Output/siTvLAIAndPROSAILToSensorResponse.tif \ + 5 +*/ + +// The following code is an example of Sensor spectral response image generated using image of labeled objects image, objects properties (vegetation classes are +// handled using PROSAIL model, non-vegetation classes are characterized using \href{http://speclib.jpl.nasa.gov/}{Aster database} characteristics provided by a +// text file), acquisition parameters, sensor characteristics, and LAI (Leaf Area Index) image. // -// Sensor RSR is modeled by 6S (Second Simulation of a Satellite Signal in the Solar Spectrum) model \cite{Vermote1997}. Detailed information about 6S can be found \href{http://6s.ltdri.org/6S_code2_thiner_stuff/6S_Manual_Part_1.pdf}{here}. +// Sensor RSR is modeled by 6S (Second Simulation of a Satellite Signal in the Solar Spectrum) model \cite{Vermote1997}. Detailed information about 6S can be +// found \href{http://6s.ltdri.org/6S_code2_thiner_stuff/6S_Manual_Part_1.pdf}{here}. // // Let's look at the minimal code required to use this algorithm. First, the // following headers must be included. -// -// Software Guide : EndLatex #include "otbImageFileWriter.h" #include "otbImageFileReader.h" @@ -47,7 +47,6 @@ #include "otbMultiChannelExtractROI.h" #include "itkOrImageFilter.h" -// Software Guide : BeginCodeSnippet #include "otbLeafParameters.h" #include "otbReduceSpectralResponse.h" #include "otbImageSimulationMethod.h" @@ -56,75 +55,67 @@ #include "itkTernaryFunctorImageFilter.h" #include "otbRAndNIRIndexImageFilter.h" #include "otbVectorDataToLabelMapWithAttributesFilter.h" -// Software Guide : EndCodeSnippet namespace otb { -// Software Guide : BeginLatex -// // \code{ImageUniqueValuesCalculator} class is defined here. Method \code{GetUniqueValues()} returns an array with all values contained in an image. // This class is implemented and used to test if all labels in labeled image are present in label parameter file. -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -template < class TImage > +template <class TImage> class ITK_EXPORT ImageUniqueValuesCalculator : public itk::Object { public: - typedef ImageUniqueValuesCalculator<TImage> Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef ImageUniqueValuesCalculator<TImage> Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; itkNewMacro(Self); itkTypeMacro(ImageUniqueValuesCalculator, itk::Object); - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); + itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension); typedef typename TImage::PixelType PixelType; typedef TImage ImageType; - typedef std::vector<PixelType> ArrayType; + typedef std::vector<PixelType> ArrayType; typedef typename ImageType::Pointer ImagePointer; typedef typename ImageType::ConstPointer ImageConstPointer; - virtual void SetImage( const ImageType * image ) + virtual void SetImage(const ImageType* image) + { + if (m_Image != image) { - if ( m_Image != image ) - { m_Image = image; this->Modified(); - } } + } ArrayType GetUniqueValues() const { ArrayType uniqueValues; - if( !m_Image ) - { + if (!m_Image) + { return uniqueValues; - } + } - itk::ImageRegionConstIterator< ImageType > it( m_Image, - m_Image->GetRequestedRegion() ); + itk::ImageRegionConstIterator<ImageType> it(m_Image, m_Image->GetRequestedRegion()); uniqueValues.push_back(it.Get()); ++it; - while( !it.IsAtEnd() ) + while (!it.IsAtEnd()) + { + if (std::find(uniqueValues.begin(), uniqueValues.end(), it.Get()) == uniqueValues.end()) { - if( std::find(uniqueValues.begin(), - uniqueValues.end(), it.Get()) == uniqueValues.end()) - { uniqueValues.push_back(it.Get()); - } - ++it; } + ++it; + } return uniqueValues; } @@ -132,9 +123,9 @@ public: protected: ImageUniqueValuesCalculator() - { + { m_Image = nullptr; - } + } ~ImageUniqueValuesCalculator() override { } @@ -148,85 +139,59 @@ private: ImageUniqueValuesCalculator(const Self&) = delete; void operator=(const Self&) = delete; - ImageConstPointer m_Image; + ImageConstPointer m_Image; -}; // class ImageUniqueValuesCalculator -// EndCodeSnippet +}; // class ImageUniqueValuesCalculator namespace Functor { -// Software Guide : BeginLatex -// // \code{ProsailSimulatorFunctor} functor is defined here. // -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -template<class TLAI, class TLabel, class TMask, class TOutput, - class TLabelSpectra, class TLabelParameter, - class TAcquistionParameter, class TSatRSR> +template <class TLAI, class TLabel, class TMask, class TOutput, class TLabelSpectra, class TLabelParameter, class TAcquistionParameter, class TSatRSR> class ProsailSimulatorFunctor -// Software Guide : EndCodeSnippet { public: /** Standard class typedefs */ - // Software Guide : BeginLatex - // // \code{ProsailSimulatorFunctor} functor is defined here. // - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef TLAI LAIPixelType; - typedef TLabel LabelPixelType; - typedef TMask MaskPixelType; - typedef TOutput OutputPixelType; - typedef TLabelSpectra LabelSpectraType; - typedef TLabelParameter LabelParameterType; - typedef TAcquistionParameter AcquistionParameterType; - typedef TSatRSR SatRSRType; + + typedef TLAI LAIPixelType; + typedef TLabel LabelPixelType; + typedef TMask MaskPixelType; + typedef TOutput OutputPixelType; + typedef TLabelSpectra LabelSpectraType; + typedef TLabelParameter LabelParameterType; + typedef TAcquistionParameter AcquistionParameterType; + typedef TSatRSR SatRSRType; typedef typename SatRSRType::Pointer SatRSRPointerType; - typedef typename otb::ProspectModel ProspectType; - typedef typename otb::SailModel SailType; - - typedef double PrecisionType; - typedef std::pair<PrecisionType, PrecisionType> PairType; - typedef typename std::vector<PairType> VectorPairType; - typedef otb::SpectralResponse<PrecisionType, PrecisionType> ResponseType; - typedef ResponseType::Pointer ResponsePointerType; - typedef otb::ReduceSpectralResponse - <ResponseType, SatRSRType> ReduceResponseType; - typedef typename ReduceResponseType::Pointer - ReduceResponseTypePointerType; - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + typedef typename otb::ProspectModel ProspectType; + typedef typename otb::SailModel SailType; + + typedef double PrecisionType; + typedef std::pair<PrecisionType, PrecisionType> PairType; + typedef typename std::vector<PairType> VectorPairType; + typedef otb::SpectralResponse<PrecisionType, PrecisionType> ResponseType; + typedef ResponseType::Pointer ResponsePointerType; + typedef otb::ReduceSpectralResponse<ResponseType, SatRSRType> ReduceResponseType; + typedef typename ReduceResponseType::Pointer ReduceResponseTypePointerType; + // In this example spectra are generated form $400$ to $2400nm$. the number of simulated band is set by \code{SimNbBands} value. // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet static const unsigned int SimNbBands = 2000; - // Software Guide : EndCodeSnippet /** Constructor */ ProsailSimulatorFunctor() { - m_SatRSR = SatRSRType::New(); + m_SatRSR = SatRSRType::New(); m_InvertedMask = false; } /** Destructor */ - ~ProsailSimulatorFunctor() - { - } -; + ~ProsailSimulatorFunctor(){}; void SetInvertedMask(bool ivm) { @@ -234,46 +199,36 @@ public: } /** Implementation of the () operator*/ - inline OutputPixelType operator ()(const LAIPixelType &lai, const LabelPixelType& label, const MaskPixelType& mask) + inline OutputPixelType operator()(const LAIPixelType& lai, const LabelPixelType& label, const MaskPixelType& mask) { - // Software Guide : BeginLatex - // // mask value is read to know if the pixel have to be calculated, it is set to 0 otherwise. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet OutputPixelType pix; pix.SetSize(m_SatRSR->GetNbBands()); if ((!mask && !m_InvertedMask) || (mask && m_InvertedMask)) - { + { for (unsigned int i = 0; i < m_SatRSR->GetNbBands(); i++) - pix[i] = static_cast<typename OutputPixelType::ValueType> (0); + pix[i] = static_cast<typename OutputPixelType::ValueType>(0); return pix; - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // - // Object reflectance \code{hxSpectrum} is calculated. If object label correspond to vegetation label then Prosail code is used, aster database is used otherwise. - // - // Software Guide : EndLatex + // Object reflectance \code{hxSpectrum} is calculated. If object label correspond to vegetation label then Prosail code is used, aster database is used + // otherwise. - // Software Guide : BeginCodeSnippet VectorPairType hxSpectrum; for (unsigned int i = 0; i < SimNbBands; i++) - { + { PairType resp; - resp.first = static_cast<PrecisionType> ((400.0 + i) / 1000); + resp.first = static_cast<PrecisionType>((400.0 + i) / 1000); hxSpectrum.push_back(resp); - } + } // either the spectrum has to be simulated by Prospect+Sail if (m_LabelParameters.find(label) != m_LabelParameters.end()) - { + { ProspectType::Pointer prospect = ProspectType::New(); prospect->SetInput(m_LabelParameters[label]); @@ -292,49 +247,31 @@ public: sail->Update(); for (unsigned int i = 0; i < SimNbBands; i++) - { - hxSpectrum[i].second = static_cast<typename OutputPixelType::ValueType> - (sail->GetHemisphericalReflectance()->GetResponse()[i].second); - } - + { + hxSpectrum[i].second = static_cast<typename OutputPixelType::ValueType>(sail->GetHemisphericalReflectance()->GetResponse()[i].second); } + } // or the spectra has been set from outside the functor (ex. bare soil, etc.) + else if (m_LabelSpectra.find(label) != m_LabelSpectra.end()) + { + for (unsigned int i = 0; i < SimNbBands; i++) + hxSpectrum[i].second = static_cast<typename OutputPixelType::ValueType>(m_LabelSpectra[label][i]); + } + // or the class does not exist else - if (m_LabelSpectra.find(label) != m_LabelSpectra.end()) - { - for (unsigned int i = 0; i < SimNbBands; i++) - hxSpectrum[i].second = - static_cast<typename OutputPixelType::ValueType> - (m_LabelSpectra[label][i]); - } - // or the class does not exist - else - { - for (unsigned int i = 0; i < SimNbBands; i++) - hxSpectrum[i].second = - static_cast<typename OutputPixelType::ValueType> (0); - } - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + { + for (unsigned int i = 0; i < SimNbBands; i++) + hxSpectrum[i].second = static_cast<typename OutputPixelType::ValueType>(0); + } // Spectral response \code{aResponse} is set using \code{hxSpectrum}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ResponseType::Pointer aResponse = ResponseType::New(); aResponse->SetResponse(hxSpectrum); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Satellite RSR is initialized and set with \code{aResponse}. Reflectance // mode is used in this case to take into account solar irradiance into // spectral response reduction. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ReduceResponseTypePointerType reduceResponse = ReduceResponseType::New(); reduceResponse->SetInputSatRSR(m_SatRSR); reduceResponse->SetInputSpectralResponse(aResponse); @@ -342,33 +279,22 @@ public: reduceResponse->SetReflectanceMode(true); reduceResponse->CalculateResponse(); - VectorPairType reducedResponse = - reduceResponse->GetReduceResponse()->GetResponse(); - // Software Guide : EndCodeSnippet + VectorPairType reducedResponse = reduceResponse->GetReduceResponse()->GetResponse(); - // Software Guide : BeginLatex - // // \code{pix} value is returned for desired Satellite bands - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet for (unsigned int i = 0; i < m_SatRSR->GetNbBands(); i++) - pix[i] = - static_cast<typename OutputPixelType::ValueType> - (reducedResponse[i].second); + pix[i] = static_cast<typename OutputPixelType::ValueType>(reducedResponse[i].second); return pix; - // Software Guide : EndCodeSnippet - } - bool operator !=(const ProsailSimulatorFunctor& other) const + bool operator!=(const ProsailSimulatorFunctor& other) const { return (m_AcquisitionParameters != other.m_AcquisitionParameters || m_LabelParameters != other.m_LabelParameters); } - bool operator ==(const ProsailSimulatorFunctor& other) const + bool operator==(const ProsailSimulatorFunctor& other) const { return (m_AcquisitionParameters == other.m_AcquisitionParameters && m_LabelParameters == other.m_LabelParameters); } @@ -402,7 +328,6 @@ public: } protected: - /** Spectra associated to labels*/ LabelSpectraType m_LabelSpectra; /** Prospect+sail parameters to labels*/ @@ -414,31 +339,22 @@ protected: /** Simulate pixels with mask != 0 ==> m_InvertedMask = false; */ bool m_InvertedMask; - }; } // namespace Functor -// Software Guide : BeginLatex -// // \code{TernaryFunctorImageFilterWithNBands} class is defined here. // This class inherits form \doxygen{itk}{TernaryFunctorImageFilter} with additional nuber of band parameters. // It's implementation is done to process Label, LAI, and mask image with Simulation functor. -// Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet -template <class TInputImage1, class TInputImage2, class TInputImage3, - class TOutputImage, class TFunctor> -class ITK_EXPORT TernaryFunctorImageFilterWithNBands : - public itk::TernaryFunctorImageFilter< TInputImage1, TInputImage2, - TInputImage3, TOutputImage, TFunctor > + +template <class TInputImage1, class TInputImage2, class TInputImage3, class TOutputImage, class TFunctor> +class ITK_EXPORT TernaryFunctorImageFilterWithNBands : public itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunctor> { public: - typedef TernaryFunctorImageFilterWithNBands Self; - typedef itk::TernaryFunctorImageFilter< TInputImage1, TInputImage2, - TInputImage3, TOutputImage, TFunctor > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef TernaryFunctorImageFilterWithNBands Self; + typedef itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunctor> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; /** Method for creation through the object factory. */ itkNewMacro(Self); @@ -451,137 +367,103 @@ public: itkGetConstMacro(NumberOfOutputBands, unsigned int); protected: - TernaryFunctorImageFilterWithNBands() {} - ~TernaryFunctorImageFilterWithNBands() override {} + TernaryFunctorImageFilterWithNBands() + { + } + ~TernaryFunctorImageFilterWithNBands() override + { + } void GenerateOutputInformation() override { Superclass::GenerateOutputInformation(); - this->GetOutput()->SetNumberOfComponentsPerPixel( m_NumberOfOutputBands ); + this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfOutputBands); } + private: - TernaryFunctorImageFilterWithNBands(const Self &) = delete; - void operator =(const Self&) = delete; + TernaryFunctorImageFilterWithNBands(const Self&) = delete; + void operator=(const Self&) = delete; unsigned int m_NumberOfOutputBands; - - }; -// EndCodeSnippet -} +} // namespace otb -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - char *cmifname = nullptr; + char* cmifname = nullptr; if (argc != 10) - { + { if (argc == 11) // cloud mask filename optional parameter - { + { cmifname = argv[10]; - } + } else - { + { std::cerr << "Wrong Parameters " << std::endl; return EXIT_FAILURE; - } } - char * laiifname = argv[1]; - char * outfname = argv[2]; - char * lifname = argv[3]; - char * mifname = argv[4]; - char * lpfname = argv[5]; - char * apfname = argv[6]; - char * rsfname = argv[7]; - unsigned int nbBands = static_cast<unsigned int> (atoi(argv[8])); - char * rootPath = argv[9]; + } + char* laiifname = argv[1]; + char* outfname = argv[2]; + char* lifname = argv[3]; + char* mifname = argv[4]; + char* lpfname = argv[5]; + char* apfname = argv[6]; + char* rsfname = argv[7]; + unsigned int nbBands = static_cast<unsigned int>(atoi(argv[8])); + char* rootPath = argv[9]; // Read the label parameter file. It is assumed to have the form // label 1 Cab Car CBrown Cw Cm N --> for vegetation classes // label 0 /path/to/spectra/file --> for other classes - // Software Guide : BeginLatex - // // input images typedef are presented below. This example uses \code{double} LAI image, \code{binary} mask and // cloud mask, and \code{integer} label image // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef double LAIPixelType; + typedef double LAIPixelType; typedef unsigned short LabelType; typedef unsigned short MaskPixelType; - typedef float OutputPixelType; + typedef float OutputPixelType; // Image typedef - typedef otb::Image<LAIPixelType, 2> LAIImageType; - typedef otb::Image<LabelType, 2> LabelImageType; - typedef otb::Image<MaskPixelType, 2> MaskImageType; + typedef otb::Image<LAIPixelType, 2> LAIImageType; + typedef otb::Image<LabelType, 2> LabelImageType; + typedef otb::Image<MaskPixelType, 2> MaskImageType; typedef otb::VectorImage<OutputPixelType, 2> SimulatedImageType; - // Software Guide : EndCodeSnippet // reader typedef - typedef otb::ImageFileReader<LAIImageType> LAIReaderType; + typedef otb::ImageFileReader<LAIImageType> LAIReaderType; typedef otb::ImageFileReader<LabelImageType> LabelReaderType; - typedef otb::ImageFileReader<MaskImageType> MaskReaderType; + typedef otb::ImageFileReader<MaskImageType> MaskReaderType; - // Software Guide : BeginCodeSnippet - // Software Guide : BeginLatex - // // Leaf parameters typedef is defined. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::LeafParameters LeafParametersType; - typedef LeafParametersType::Pointer LeafParametersPointerType; + typedef otb::LeafParameters LeafParametersType; + typedef LeafParametersType::Pointer LeafParametersPointerType; typedef std::map<LabelType, LeafParametersPointerType> LabelParameterMapType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Sensor spectral response typedef is defined - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef double PrecisionType; - typedef std::vector<PrecisionType> SpectraType; + typedef double PrecisionType; + typedef std::vector<PrecisionType> SpectraType; typedef std::map<LabelType, SpectraType> SpectraParameterType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Acquisition response typedef is defined - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef std::map<std::string, double> AcquistionParsType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Satellite typedef is defined - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::SatelliteRSR<PrecisionType, PrecisionType> SatRSRType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Filter type is the specific \code{TernaryFunctorImageFilterWithNBands} defined below with specific functor. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::Functor::ProsailSimulatorFunctor - <LAIPixelType, LabelType, MaskPixelType, SimulatedImageType::PixelType, - SpectraParameterType, LabelParameterMapType, AcquistionParsType, SatRSRType> - SimuFunctorType; - typedef otb::TernaryFunctorImageFilterWithNBands - <LAIImageType, LabelImageType, MaskImageType, SimulatedImageType, - SimuFunctorType> SimulatorType; - // Software Guide : EndCodeSnippet + + typedef otb::Functor::ProsailSimulatorFunctor<LAIPixelType, LabelType, MaskPixelType, SimulatedImageType::PixelType, SpectraParameterType, + LabelParameterMapType, AcquistionParsType, SatRSRType> + SimuFunctorType; + typedef otb::TernaryFunctorImageFilterWithNBands<LAIImageType, LabelImageType, MaskImageType, SimulatedImageType, SimuFunctorType> SimulatorType; // Read the acquisition parameter file which is like // Angl val @@ -592,91 +474,80 @@ int main(int argc, char *argv[]) // TTO val // PSI val - // Software Guide : BeginLatex - // // Acquisition parameters are loaded using text file. A detailed definition of acquisition parameters can // be found in class \doxygen{otb}{SailModel}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet AcquistionParsType acquistionPars; - acquistionPars[std::string("Angl")] = 0.0; + acquistionPars[std::string("Angl")] = 0.0; acquistionPars[std::string("PSoil")] = 0.0; - acquistionPars[std::string("Skyl")] = 0.0; + acquistionPars[std::string("Skyl")] = 0.0; acquistionPars[std::string("HSpot")] = 0.0; - acquistionPars[std::string("TTS")] = 0.0; - acquistionPars[std::string("TTO")] = 0.0; - acquistionPars[std::string("PSI")] = 0.0; + acquistionPars[std::string("TTS")] = 0.0; + acquistionPars[std::string("TTO")] = 0.0; + acquistionPars[std::string("PSI")] = 0.0; std::ifstream acquistionParsFile; try - { + { acquistionParsFile.open(apfname); - } + } catch (...) - { + { std::cerr << "Could not open file " << apfname << std::endl; return EXIT_FAILURE; - } + } - //unsigned int acPar = 0; + // unsigned int acPar = 0; while (acquistionParsFile.good()) - { + { std::string line; std::getline(acquistionParsFile, line); std::stringstream ss(line); - std::string parName; + std::string parName; ss >> parName; double parValue; ss >> parValue; acquistionPars[parName] = parValue; - - } + } acquistionParsFile.close(); - //Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Label parameters are loaded using text file. // Two type of object characteristic can be found. If label corresponds to vegetation class, // then leaf parameters are loaded. // A detailed definition of leaf parameters can be found in class \doxygen{otb}{LeafParameters} class. // Otherwise object reflectance is generated from $400$ to $2400nm$ using \href{http://speclib.jpl.nasa.gov/}{Aster database}. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LabelParameterMapType labelParameters; - std::ifstream labelParsFile; + std::ifstream labelParsFile; SpectraParameterType spectraParameters; try - { + { labelParsFile.open(lpfname, std::ifstream::in); - } + } catch (...) - { + { std::cerr << "Could not open file " << lpfname << std::endl; return EXIT_FAILURE; - } + } while (labelParsFile.good()) - { + { char fileLine[256]; labelParsFile.getline(fileLine, 256); if (fileLine[0] != '#') - { + { std::stringstream ss(fileLine); - unsigned short label; + unsigned short label; ss >> label; unsigned short paramsOrSpectra; ss >> paramsOrSpectra; if (paramsOrSpectra == 1) - { + { double Cab; ss >> Cab; double Car; @@ -700,52 +571,42 @@ int main(int argc, char *argv[]) leafParams->SetN(N); labelParameters[label] = leafParams; - } + } else - { + { std::string spectraFilename = rootPath; ss >> spectraFilename; spectraFilename = rootPath + spectraFilename; typedef otb::SpectralResponse<PrecisionType, PrecisionType> ResponseType; - ResponseType::Pointer resp = ResponseType::New(); + ResponseType::Pointer resp = ResponseType::New(); // Coefficient 100 since Aster database is given in % reflectance resp->Load(spectraFilename, 100.0); SpectraType spec; for (unsigned int i = 0; i < SimuFunctorType::SimNbBands; i++) - //Prosail starts at 400 and lambda in Aster DB is in micrometers - spec.push_back - (static_cast<PrecisionType> ((*resp)((i + 400.0) / 1000.0))); + // Prosail starts at 400 and lambda in Aster DB is in micrometers + spec.push_back(static_cast<PrecisionType>((*resp)((i + 400.0) / 1000.0))); spectraParameters[label] = spec; - } } } + } labelParsFile.close(); - //Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // LAI image is read. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LAIReaderType::Pointer laiReader = LAIReaderType::New(); laiReader->SetFileName(laiifname); laiReader->Update(); LAIImageType::Pointer laiImage = laiReader->GetOutput(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // Label image is then read. Label image is processed using \code{ImageUniqueValuesCalculator} in order to check if all the labels are present in the labelParameters file. - // Software Guide : EndLatex + // Label image is then read. Label image is processed using \code{ImageUniqueValuesCalculator} in order to check if all the labels are present in the + // labelParameters file. - // Software Guide : BeginCodeSnippet LabelReaderType::Pointer labelReader = LabelReaderType::New(); labelReader->SetFileName(lifname); labelReader->Update(); @@ -758,157 +619,113 @@ int main(int argc, char *argv[]) uniqueCalculator->SetImage(labelImage); - UniqueCalculatorType::ArrayType uniqueVals = - uniqueCalculator->GetUniqueValues(); + UniqueCalculatorType::ArrayType uniqueVals = uniqueCalculator->GetUniqueValues(); if (uniqueVals.empty()) - { - std::cerr << "No label value found!"<< std::endl; + { + std::cerr << "No label value found!" << std::endl; return EXIT_FAILURE; - } + } std::cout << "Labels are " << std::endl; UniqueCalculatorType::ArrayType::const_iterator uvIt = uniqueVals.begin(); while (uvIt != uniqueVals.end()) - { + { std::cout << (*uvIt) << ", "; ++uvIt; - } + } std::cout << std::endl; uvIt = uniqueVals.begin(); while (uvIt != uniqueVals.end()) + { + if (labelParameters.find(static_cast<LabelType>(*uvIt)) == labelParameters.end() && + spectraParameters.find(static_cast<LabelType>(*uvIt)) == spectraParameters.end() && static_cast<LabelType>(*uvIt) != 0) { - if (labelParameters.find(static_cast<LabelType> - (*uvIt)) == labelParameters.end() && - spectraParameters.find(static_cast<LabelType> (*uvIt)) == - spectraParameters.end() && - static_cast<LabelType> (*uvIt) != 0) - { - std::cout << "label " << (*uvIt) << " not found in " << - lpfname << std::endl; + std::cout << "label " << (*uvIt) << " not found in " << lpfname << std::endl; return EXIT_FAILURE; - } - ++uvIt; } - // Software Guide : EndCodeSnippet + ++uvIt; + } - // Software Guide : BeginLatex - // // Mask image is read. If cloud mask is filename is given, a new mask image is generated with masks concatenation. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet MaskReaderType::Pointer miReader = MaskReaderType::New(); miReader->SetFileName(mifname); miReader->UpdateOutputInformation(); MaskImageType::Pointer maskImage = miReader->GetOutput(); if (cmifname != nullptr) - { + { MaskReaderType::Pointer cmiReader = MaskReaderType::New(); cmiReader->SetFileName(cmifname); cmiReader->UpdateOutputInformation(); - typedef itk::OrImageFilter - <MaskImageType, MaskImageType, MaskImageType> OrType; - OrType::Pointer orfilter = OrType::New(); + typedef itk::OrImageFilter<MaskImageType, MaskImageType, MaskImageType> OrType; + OrType::Pointer orfilter = OrType::New(); orfilter->SetInput1(miReader->GetOutput()); orfilter->SetInput2(cmiReader->GetOutput()); orfilter->Update(); maskImage = orfilter->GetOutput(); - - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // A test is done. All images must have the same size. - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - if (laiImage->GetLargestPossibleRegion().GetSize()[0] != - labelImage->GetLargestPossibleRegion().GetSize()[0] || - laiImage->GetLargestPossibleRegion().GetSize()[1] != - labelImage->GetLargestPossibleRegion().GetSize()[1] || - laiImage->GetLargestPossibleRegion().GetSize()[0] != - maskImage->GetLargestPossibleRegion().GetSize()[0] || - laiImage->GetLargestPossibleRegion().GetSize()[1] != - maskImage->GetLargestPossibleRegion().GetSize()[1]) - { - std::cerr << "Image of labels, mask and LAI image must have the same size" - << std::endl; + + if (laiImage->GetLargestPossibleRegion().GetSize()[0] != labelImage->GetLargestPossibleRegion().GetSize()[0] || + laiImage->GetLargestPossibleRegion().GetSize()[1] != labelImage->GetLargestPossibleRegion().GetSize()[1] || + laiImage->GetLargestPossibleRegion().GetSize()[0] != maskImage->GetLargestPossibleRegion().GetSize()[0] || + laiImage->GetLargestPossibleRegion().GetSize()[1] != maskImage->GetLargestPossibleRegion().GetSize()[1]) + { + std::cerr << "Image of labels, mask and LAI image must have the same size" << std::endl; return EXIT_FAILURE; - } - // Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // Satellite RSR (Reduced Spectral Response) is defined using filename and band number given by command line arguments. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SatRSRType::Pointer satRSR = SatRSRType::New(); satRSR->SetNbBands(nbBands); satRSR->SetSortBands(false); satRSR->Load(rsfname); for (unsigned int i = 0; i < nbBands; ++i) - std::cout << i << " " << (satRSR->GetRSR())[i]->GetInterval().first << " " - << (satRSR->GetRSR())[i]->GetInterval().second << std::endl; - // Software Guide : EndCodeSnippet + std::cout << i << " " << (satRSR->GetRSR())[i]->GetInterval().first << " " << (satRSR->GetRSR())[i]->GetInterval().second << std::endl; - // Software Guide : BeginLatex - // // At this step all initialization have been done. The next step is to implement and initialize simulation functor \code{ProsailSimulatorFunctor}. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SimuFunctorType simuFunctor; simuFunctor.SetLabelParameters(labelParameters); simuFunctor.SetLabelSpectra(spectraParameters); simuFunctor.SetAcquisitionParameters(acquistionPars); simuFunctor.SetRSR(satRSR); simuFunctor.SetInvertedMask(true); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Inputs and Functor are plugged to simulator filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet SimulatorType::Pointer simulator = SimulatorType::New(); simulator->SetInput1(laiImage); simulator->SetInput2(labelImage); simulator->SetInput3(maskImage); simulator->SetFunctor(simuFunctor); simulator->SetNumberOfOutputBands(nbBands); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The invocation of the \code{Update()} method triggers the // execution of the pipeline. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet simulator->Update(); - // Software Guide : EndCodeSnippet // Write output image to disk typedef otb::ImageFileWriter<SimulatedImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outfname); writer->SetInput(simulator->GetOutput()); @@ -919,5 +736,4 @@ int main(int argc, char *argv[]) writer->Update(); return EXIT_SUCCESS; - } diff --git a/Examples/Simulation/LAIFromNDVIImageTransform.cxx b/Examples/Simulation/LAIFromNDVIImageTransform.cxx index e5f583f45b4c5b760aebb41d4fb04d3c707d045d..d3bfd542ff2566459eb73ca1514b113c244a3bd0 100644 --- a/Examples/Simulation/LAIFromNDVIImageTransform.cxx +++ b/Examples/Simulation/LAIFromNDVIImageTransform.cxx @@ -19,26 +19,23 @@ */ -// Software Guide : BeginCommandLineArgs -// -// INPUTS: {verySmallFSATSW.tif} -// OUTPUTS: {siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW.tif}, {verySmallFSATSW_visu.png}, {siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW_visu.png} -// 1 4 -// Software Guide : EndCommandLineArgs -// -// Software Guide : BeginLatex +/* Example usage: +./LAIFromNDVIImageTransform Input/verySmallFSATSW.tif \ + Output/siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW.tif \ + Output/verySmallFSATSW_visu.png \ + Output/siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW_visu.png \ + 1 \ + 4 +*/ + // // This example presents a way to generate LAI (Leaf Area Index) image using formula dedicated to Formosat2. // LAI Image is used as an input in Image Simulation process. // // Let's look at the minimal code required to use this algorithm. First, the // following headers must be included. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbMultiChannelRAndNIRIndexImageFilter.h" -// Software Guide : EndCodeSnippet #include "otbImage.h" #include "otbImageFileWriter.h" @@ -50,145 +47,107 @@ #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 7) - { + { std::cerr << "Wrong Parameters " << std::endl; return EXIT_FAILURE; - } + } - const unsigned int Dimension = 2; - typedef otb::VectorImage<double, Dimension> InputImageType; - typedef otb::Image<double, Dimension> OutputImageType; - typedef otb::Image<unsigned char, Dimension> ImageVisuType; - typedef otb::ImageFileReader<InputImageType> ReaderType; + const unsigned int Dimension = 2; + typedef otb::VectorImage<double, Dimension> InputImageType; + typedef otb::Image<double, Dimension> OutputImageType; + typedef otb::Image<unsigned char, Dimension> ImageVisuType; + typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::ImageFileWriter<OutputImageType> WriterType; - typedef otb::ImageFileWriter<ImageVisuType> VisuWriterType; - typedef otb::ImageFileWriter<InputImageType> InWriterType; - // Software Guide : BeginLatex - // + typedef otb::ImageFileWriter<ImageVisuType> VisuWriterType; + typedef otb::ImageFileWriter<InputImageType> InWriterType; // Filter type is a generic \doxygen{otb}{MultiChannelRAndNIRIndexImageFilter} using Formosat2 specific LAI // \doxygen{otb}{LAIFromNDVIFormosat2Functor}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Functor::LAIFromNDVIFormosat2Functor - <InputImageType::InternalPixelType, - InputImageType::InternalPixelType, OutputImageType::PixelType> FunctorType; - typedef otb::MultiChannelRAndNIRIndexImageFilter - <InputImageType, OutputImageType, FunctorType> - MultiChannelRAndNIRIndexImageFilterType; - // Software Guide : EndCodeSnippet + typedef otb::Functor::LAIFromNDVIFormosat2Functor<InputImageType::InternalPixelType, InputImageType::InternalPixelType, OutputImageType::PixelType> + FunctorType; + typedef otb::MultiChannelRAndNIRIndexImageFilter<InputImageType, OutputImageType, FunctorType> MultiChannelRAndNIRIndexImageFilterType; // Instantiating object - // Software Guide : BeginLatex - // // Next the filter is created by invoking the \code{New()}~method and // assigning the result to a \doxygen{itk}{SmartPointer}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - MultiChannelRAndNIRIndexImageFilterType::Pointer filter - = MultiChannelRAndNIRIndexImageFilterType::New(); - // Software Guide : EndCodeSnippet + MultiChannelRAndNIRIndexImageFilterType::Pointer filter = MultiChannelRAndNIRIndexImageFilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - InWriterType::Pointer inWriter = InWriterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + InWriterType::Pointer inWriter = InWriterType::New(); VisuWriterType::Pointer visuWriter = VisuWriterType::New(); - char * InputName = argv[1]; - char * OutputName1 = argv[2]; - char * OutputName2 = argv[3]; - char * OutputName3 = argv[4]; + char* InputName = argv[1]; + char* OutputName1 = argv[2]; + char* OutputName2 = argv[3]; + char* OutputName3 = argv[4]; reader->SetFileName(InputName); - // Software Guide : BeginLatex - // // filter input is set with input image // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // then red and nir channels index are set using \code{SetRedIndex()} and \code{SetNIRIndex()} // - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - unsigned int redChannel = static_cast<unsigned int> (atoi(argv[5])); - unsigned int nirChannel = static_cast<unsigned int> (atoi(argv[6])); + unsigned int redChannel = static_cast<unsigned int>(atoi(argv[5])); + unsigned int nirChannel = static_cast<unsigned int>(atoi(argv[6])); filter->SetRedIndex(redChannel); filter->SetNIRIndex(nirChannel); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The invocation of the \code{Update()} method triggers the // execution of the pipeline. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->Update(); - // Software Guide : EndCodeSnippet writer->SetFileName(OutputName1); writer->SetInput(filter->GetOutput()); writer->Update(); - //rescale data + // rescale data inWriter->SetFileName(OutputName2); - //typedef itk::RescaleIntensityImageFilter<InputImageType, + // typedef itk::RescaleIntensityImageFilter<InputImageType, // OutputImageType> RescalerType; - //RescalerType::Pointer rescaler = RescalerType::New(); - //rescaler->SetInput(reader->GetOutput()); - //rescaler->SetOutputMinimum(0); - //rescaler->SetOutputMaximum(255); + // RescalerType::Pointer rescaler = RescalerType::New(); + // rescaler->SetInput(reader->GetOutput()); + // rescaler->SetOutputMinimum(0); + // rescaler->SetOutputMaximum(255); inWriter->SetInput(reader->GetOutput()); inWriter->Update(); visuWriter->SetFileName(OutputName3); - typedef itk::RescaleIntensityImageFilter<OutputImageType, - ImageVisuType> RescalerTypeOut; + typedef itk::RescaleIntensityImageFilter<OutputImageType, ImageVisuType> RescalerTypeOut; - RescalerTypeOut::Pointer rescaler = RescalerTypeOut::New(); - rescaler->SetInput(filter->GetOutput()); - rescaler->SetOutputMinimum(0); - rescaler->SetOutputMaximum(255); + RescalerTypeOut::Pointer rescaler = RescalerTypeOut::New(); + rescaler->SetInput(filter->GetOutput()); + rescaler->SetOutputMinimum(0); + rescaler->SetOutputMaximum(255); visuWriter->SetInput(rescaler->GetOutput()); visuWriter->Update(); - // Software Guide : BeginLatex - // \begin{figure} - // \center - // \includegraphics[width=0.44\textwidth]{verySmallFSATSW_visu.eps} - // \includegraphics[width=0.44\textwidth]{siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW_visu.eps} - // \itkcaption[LAIFromNDVIImageTransform Filter]{LAI generation \emph{(right)} from NDVI applied on Formosat 2 Image \emph{(left)} .} - // \label{fig:LAIFromNDVIImageTransform} - // \end{figure} - // - // Figure \ref{fig:LAIFromNDVIImageTransform} illustrates the LAI generation using Formosat 2 data. - // - // - // Software Guide : EndLatex + // \begin{figure} + // \center + // \includegraphics[width=0.44\textwidth]{verySmallFSATSW_visu.eps} + // \includegraphics[width=0.44\textwidth]{siTvLAIFromNDVIImageTransformExampleTest_verySmallFSATSW_visu.eps} + // \itkcaption[LAIFromNDVIImageTransform Filter]{LAI generation \emph{(right)} from NDVI applied on Formosat 2 Image \emph{(left)} .} + // \label{fig:LAIFromNDVIImageTransform} + // \end{figure} + // + // Figure \ref{fig:LAIFromNDVIImageTransform} illustrates the LAI generation using Formosat 2 data. + // return EXIT_SUCCESS; } - - diff --git a/Examples/Simulation/ProsailModel.cxx b/Examples/Simulation/ProsailModel.cxx index bebb1ba80a5a3aa20bbb0d74c9b6511c9691b9f4..8dedca835fc8edf293add51bf30fdb3d31a619e6 100644 --- a/Examples/Simulation/ProsailModel.cxx +++ b/Examples/Simulation/ProsailModel.cxx @@ -20,13 +20,10 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: -// 30.0 10.0 0.0 0.015 0.009 1.2 2 50 1 70 0.2 30 0 0 -// OUTPUTS: SailReflTest.txt -// Software Guide : EndCommandLineArgs -// -// Software Guide : BeginLatex +/* Example usage: +./ProsailModel 30.0 10.0 0.0 0.015 0.009 1.2 2 50 1 70 0.2 30 0 0 +*/ + // // This example presents how to use PROSAIL (Prospect + Sail) model to generate // viewing reflectance from leaf parameters, vegetation, and viewing parameters. @@ -34,52 +31,34 @@ // // Let's look at the minimal code required to use this algorithm. First, the // following headers must be included. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbSailModel.h" #include "otbProspectModel.h" -// Software Guide : EndCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc < 16) - { + { std::cerr << "Missing Parameters " << std::endl; return EXIT_FAILURE; - } + } - char * OutputName = argv[15]; - // Software Guide : BeginLatex - // + char* OutputName = argv[15]; // We now define leaf parameters, which characterize vegetation composition. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::LeafParameters LeafParametersType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Next the parameters variable is created by invoking the \code{New()}~method and // assigning the result to a \doxygen{itk}{SmartPointer}. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet LeafParametersType::Pointer leafParams = LeafParametersType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Leaf characteristics is then set. // Input parameters are : // \begin{itemize} @@ -90,16 +69,13 @@ int main(int argc, char *argv[]) // \item Dry matter content LMA (Cm) in $g/cm^2$. // \item Leaf structure parameter (N). // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - double Cab = static_cast<double> (atof(argv[1])); - double Car = static_cast<double> (atof(argv[2])); - double CBrown = static_cast<double> (atof(argv[3])); - double Cw = static_cast<double> (atof(argv[4])); - double Cm = static_cast<double> (atof(argv[5])); - double N = static_cast<double> (atof(argv[6])); + double Cab = static_cast<double>(atof(argv[1])); + double Car = static_cast<double>(atof(argv[2])); + double CBrown = static_cast<double>(atof(argv[3])); + double Cw = static_cast<double>(atof(argv[4])); + double Cm = static_cast<double>(atof(argv[5])); + double N = static_cast<double>(atof(argv[6])); leafParams->SetCab(Cab); leafParams->SetCar(Car); @@ -107,32 +83,19 @@ int main(int argc, char *argv[]) leafParams->SetCw(Cw); leafParams->SetCm(Cm); leafParams->SetN(N); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Leaf parameters are used as prospect input - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ProspectModel ProspectType; - ProspectType::Pointer prospect = ProspectType::New(); + ProspectType::Pointer prospect = ProspectType::New(); prospect->SetInput(leafParams); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now we use SAIL model to generate transmitance and reflectance spectrum. SAIL model is created by invoking // the \code{New()} method and // assigning the result to a \doxygen{itk}{SmartPointer}. - // - // Software Guide : EndLatex - // Software Guide : BeginLatex - // // sail input parameters are : // \begin{itemize} // \item leaf area index (LAI). @@ -144,19 +107,16 @@ int main(int argc, char *argv[]) // \item observer zenith angle (TTO) in $\deg$. // \item azimuth (PSI) in $\deg$. // \end{itemize} - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - double LAI = static_cast<double> (atof(argv[7])); - double Angle = static_cast<double> (atof(argv[8])); - double PSoil = static_cast<double> (atof(argv[9])); - double Skyl = static_cast<double> (atof(argv[10])); - double HSpot = static_cast<double> (atof(argv[11])); - double TTS = static_cast<double> (atof(argv[12])); - double TTO = static_cast<double> (atof(argv[13])); - double PSI = static_cast<double> (atof(argv[14])); + double LAI = static_cast<double>(atof(argv[7])); + double Angle = static_cast<double>(atof(argv[8])); + double PSoil = static_cast<double>(atof(argv[9])); + double Skyl = static_cast<double>(atof(argv[10])); + double HSpot = static_cast<double>(atof(argv[11])); + double TTS = static_cast<double>(atof(argv[12])); + double TTO = static_cast<double>(atof(argv[13])); + double PSI = static_cast<double>(atof(argv[14])); typedef otb::SailModel SailType; @@ -170,38 +130,27 @@ int main(int argc, char *argv[]) sail->SetTTS(TTS); sail->SetTTO(TTO); sail->SetPSI(PSI); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Reflectance and Transmittance are set with prospect output. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet sail->SetReflectance(prospect->GetReflectance()); sail->SetTransmittance(prospect->GetTransmittance()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // The invocation of the \code{Update()} method triggers the // execution of the pipeline. - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet sail->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // \emph{GetViewingReflectance} method provides viewing reflectance vector (size $Nx2$, where $N$ is the number of sampled wavelength values, columns corresponds respectively to wavelength and viewing reflectance) by calling \emph{GetResponse}. - // \emph{GetHemisphericalReflectance} method provides hemispherical reflectance vector (size $Nx2$, where $N$ is the number ofsampled wavelength values, columns corresponds to wavelength and hemispherical reflectance) by calling \emph{GetResponse}. + // \emph{GetViewingReflectance} method provides viewing reflectance vector (size $Nx2$, where $N$ is the number of sampled wavelength values, columns + // corresponds respectively to wavelength and viewing reflectance) by calling \emph{GetResponse}. \emph{GetHemisphericalReflectance} method provides + // hemispherical reflectance vector (size $Nx2$, where $N$ is the number ofsampled wavelength values, columns corresponds to wavelength and hemispherical + // reflectance) by calling \emph{GetResponse}. // // Note that PROSAIL simulation are done for 2100 samples starting from 400nm up to 2500nm - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet for (unsigned int i = 0; i < sail->GetViewingReflectance()->Size(); ++i) - { + { std::cout << "wavelength : "; std::cout << sail->GetViewingReflectance()->GetResponse()[i].first; std::cout << ". Viewing reflectance "; @@ -209,18 +158,15 @@ int main(int argc, char *argv[]) std::cout << ". Hemispherical reflectance "; std::cout << sail->GetHemisphericalReflectance()->GetResponse()[i].second; std::cout << std::endl; - } - // Software Guide : EndCodeSnippet + } std::ofstream outputFile(OutputName, std::ios::out); for (unsigned int i = 0; i < sail->GetHemisphericalReflectance()->Size(); ++i) - { + { outputFile << sail->GetViewingReflectance()->GetResponse()[i].second << " "; - outputFile << sail->GetHemisphericalReflectance()->GetResponse()[i].second<< std::endl; - } + outputFile << sail->GetHemisphericalReflectance()->GetResponse()[i].second << std::endl; + } - // Software Guide : BeginLatex - // // here you can found example parameters : // \begin{itemize} // \item Cab 30.0 @@ -239,8 +185,8 @@ int main(int argc, char *argv[]) // \item PSI 0 // \end{itemize} // - // More information and data about leaf properties can be found at \emph{St\'{e}phane Jacquemoud} \href{http://teledetection.ipgp.jussieu.fr/opticleaf/}{OPTICLEAF} website. - // Software Guide : EndLatex + // More information and data about leaf properties can be found at \emph{St\'{e}phane Jacquemoud} + // \href{http://teledetection.ipgp.jussieu.fr/opticleaf/}{OPTICLEAF} website. return EXIT_SUCCESS; } diff --git a/Examples/Tutorials/FilteringPipeline.cxx b/Examples/Tutorials/FilteringPipeline.cxx index 0a72a549c7b68bcb7bc990a46f8eb47889554b53..cfe2abc76e3855c4949176419546a407af98fb22 100644 --- a/Examples/Tutorials/FilteringPipeline.cxx +++ b/Examples/Tutorials/FilteringPipeline.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {TutorialsFilteringPipelineOutput.png} -// Software Guide : EndCommandLineArgs +/* Example usage: +./FilteringPipeline Input/QB_Suburb.png Output/TutorialsFilteringPipelineOutput.png +*/ + -// Software Guide : BeginLatex -// // // We are going to use the \doxygen{itk}{GradientMagnitudeImageFilter} // to compute the gradient of the image. The beginning of the file is @@ -33,82 +31,50 @@ // // We include the required headers, without forgetting to add the header // for the \doxygen{itk}{GradientMagnitudeImageFilter}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "itkGradientMagnitudeImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { - std::cerr << "Usage: " - << argv[0] - << " <input_filename> <output_filename>" - << std::endl; - } -// Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + { + std::cerr << "Usage: " << argv[0] << " <input_filename> <output_filename>" << std::endl; + } + // We declare the image type, the reader and the writer as // before: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<unsigned char, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); typedef otb::ImageFileWriter<ImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now we have to declare the filter. It is templated with the // input image type and the output image type like many filters // in OTB. Here we are using the same type for the input and the // output images: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::GradientMagnitudeImageFilter - <ImageType, ImageType> FilterType; - FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet + typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> FilterType; + FilterType::Pointer filter = FilterType::New(); - // Software Guide : BeginLatex - // // Let's plug the pipeline: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And finally, we trigger the pipeline execution calling the \code{Update()} // method on the writer - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet diff --git a/Examples/Tutorials/HelloWorldOTB.cxx b/Examples/Tutorials/HelloWorldOTB.cxx index bd83773f49f509ad267c37e450b113f4ee8f23bd..1979df092d92c09fcb207ccdee262f63c90b7980 100644 --- a/Examples/Tutorials/HelloWorldOTB.cxx +++ b/Examples/Tutorials/HelloWorldOTB.cxx @@ -19,19 +19,14 @@ */ -// Software Guide : BeginLatex -// // The following code is an implementation of a small OTB // program. It tests including header files and linking with OTB // libraries. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include <iostream> -int main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) +int main(int itkNotUsed(argc), char* itkNotUsed(argv)[]) { typedef otb::Image<unsigned short, 2> ImageType; @@ -41,15 +36,10 @@ int main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // This code instantiates an image whose pixels are represented with // type \code{unsigned short}. The image is then created and assigned to a // \doxygen{itk}{SmartPointer}. Later in the text we will discuss // \code{SmartPointer}s in detail, for now think of it as a handle on an // instance of an object (see section \ref{sec:SmartPointers} for more // information). -// -// Software Guide : EndLatex diff --git a/Examples/Tutorials/Multispectral.cxx b/Examples/Tutorials/Multispectral.cxx index b9de1a959e93c6f9a259cecab117adf271502365..3c5272d45feb4778b045d4c1c745da6280e47c02 100644 --- a/Examples/Tutorials/Multispectral.cxx +++ b/Examples/Tutorials/Multispectral.cxx @@ -19,80 +19,50 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {qb_RoadExtract.tif} -// OUTPUTS: {qb_blue.tif}, {qb_shiftscale.tif} -// Software Guide : EndCommandLineArgs +/* Example usage: +./Multispectral Input/qb_RoadExtract.tif Output/qb_blue.tif Output/qb_shiftscale.tif +*/ + -// Software Guide : BeginLatex -// // First, we are going to use \doxygen{otb}{VectorImage} instead of the now // traditional \doxygen{otb}{Image}. So we include the required header: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet -// Software Guide : EndCodeSnippet -// Software Guide : BeginLatex -// // We also include some other header which will be useful later. Note that we // are still using the \doxygen{otb}{Image} in this example for some of the // output. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbMultiToMonoChannelExtractROI.h" #include "itkShiftScaleImageFilter.h" #include "otbPerBandVectorImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 4) - { - std::cerr << "Usage: " - << argv[0] - << " <input_filename> <output_extract> <output_shifted_scaled>" - << std::endl; - } - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + { + std::cerr << "Usage: " << argv[0] << " <input_filename> <output_extract> <output_shifted_scaled>" << std::endl; + } + // We want to read a multispectral image so we declare the image type and the // reader. As we have done in the previous example we get the filename from // the command line. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef unsigned short int PixelType; typedef otb::VectorImage<PixelType, 2> VectorImageType; typedef otb::ImageFileReader<VectorImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Sometime, you need to process only one spectral band of the image. To get // only one of the spectral band we use the // \doxygen{otb}{MultiToMonoChannelExtractROI}. The declaration is as usual: - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> - ExtractChannelType; - ExtractChannelType::Pointer extractChannel = ExtractChannelType::New(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // + + typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> ExtractChannelType; + ExtractChannelType::Pointer extractChannel = ExtractChannelType::New(); // We need to pass the parameters to the filter for the extraction. This // filter also allow extracting only a spatial subset of the image. However, // we will extract the whole channel in this case. @@ -105,48 +75,29 @@ int main(int argc, char * argv[]) // \code{UpdateOutputInformation()} on the reader's output. The difference with the // \code{Update()} is that the pixel array is not allocated (yet !) and reduce // the memory usage. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->UpdateOutputInformation(); - extractChannel->SetExtractionRegion( - reader->GetOutput()->GetLargestPossibleRegion()); - // Software Guide : EndCodeSnippet + extractChannel->SetExtractionRegion(reader->GetOutput()->GetLargestPossibleRegion()); - // Software Guide : BeginLatex - // // We chose the channel number to extract (starting from 1) and we plug the // pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet extractChannel->SetChannel(3); extractChannel->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To output this image, we need a writer. As the output of the // \doxygen{otb}{MultiToMonoChannelExtractROI} is a \doxygen{otb}{Image}, we // need to template the writer with this type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::Image<PixelType, 2> ImageType; + typedef otb::Image<PixelType, 2> ImageType; typedef otb::ImageFileWriter<ImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); writer->SetInput(extractChannel->GetOutput()); writer->Update(); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // After this, we have a one band image that we can process with most OTB // filters. // @@ -170,46 +121,30 @@ int main(int argc, char * argv[]) // \doxygen{itk}{ShiftScaleImageFilter} to each of the spectral band. We start // by declaring the filter on a normal \doxygen{otb}{Image}. Note that we // don't need to specify any input for this filter. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef itk::ShiftScaleImageFilter<ImageType, ImageType> ShiftScaleType; - ShiftScaleType::Pointer shiftScale = ShiftScaleType::New(); + ShiftScaleType::Pointer shiftScale = ShiftScaleType::New(); shiftScale->SetScale(0.5); shiftScale->SetShift(10); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare the \doxygen{otb}{PerBandVectorImageFilter} which has three // template: the input image type, the output image type and the filter type // to apply to each band. // // The filter is selected using the \code{SetFilter()} method and the input // by the usual \code{SetInput()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::PerBandVectorImageFilter - <VectorImageType, VectorImageType, ShiftScaleType> VectorFilterType; - VectorFilterType::Pointer vectorFilter = VectorFilterType::New(); + typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, ShiftScaleType> VectorFilterType; + VectorFilterType::Pointer vectorFilter = VectorFilterType::New(); vectorFilter->SetFilter(shiftScale); vectorFilter->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now, we just have to save the image using a writer templated over an // \doxygen{otb}{VectorImage}: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<VectorImageType> VectorWriterType; - VectorWriterType::Pointer writerVector = VectorWriterType::New(); + VectorWriterType::Pointer writerVector = VectorWriterType::New(); writerVector->SetFileName(argv[3]); writerVector->SetInput(vectorFilter->GetOutput()); @@ -218,4 +153,3 @@ int main(int argc, char * argv[]) return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet diff --git a/Examples/Tutorials/OrthoFusion.cxx b/Examples/Tutorials/OrthoFusion.cxx index 64d0b6cd3911ecab0354d9c39f65c4131c895a34..d543fbfb3ac2e338d155042d5e42cd4618a8a638 100644 --- a/Examples/Tutorials/OrthoFusion.cxx +++ b/Examples/Tutorials/OrthoFusion.cxx @@ -19,18 +19,12 @@ */ - -// Software Guide : BeginLatex -// // Start by including some necessary headers and with the // usual \code{main} declaration. Apart from the classical header related to // image input and output. We need the headers related to the fusion and the // orthorectification. One header is also required to be able to process // vector images (the XS one) with the orthorectification. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -42,10 +36,7 @@ int main(int argc, char* argv[]) { -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We initialize ossim which is required for the orthorectification and we // check that all parameters are provided. Basically, we need: // \begin{itemize} @@ -59,76 +50,54 @@ int main(int argc, char* argv[]) // \end{itemize} // // We check that all those parameters are provided. - // -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet if (argc != 12) - { + { std::cout << argv[0] << " <input_pan_filename> <input_xs_filename> "; std::cout << "<output_filename> <utm zone> <hemisphere N/S> "; std::cout << "<x_ground_upper_left_corner> <y_ground_upper_left_corner> "; std::cout << "<x_Size> <y_Size> "; std::cout << "<x_groundSamplingDistance> "; std::cout << "<y_groundSamplingDistance " - << "(negative since origin is upper left)>" - << std::endl; + << "(negative since origin is upper left)>" << std::endl; return EXIT_FAILURE; - } -// Software Guide : EndCodeSnippet + } - // Software Guide : BeginLatex - // // We declare the different images, readers and writer: - // - // Software Guide : EndLatex - -// Software Guide : BeginCodeSnippet - typedef otb::Image<unsigned int, 2> ImageType; - typedef otb::VectorImage<unsigned int, 2> VectorImageType; - typedef otb::Image<double, 2> DoubleImageType; - typedef otb::VectorImage<double, 2> DoubleVectorImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileReader<VectorImageType> VectorReaderType; + + typedef otb::Image<unsigned int, 2> ImageType; + typedef otb::VectorImage<unsigned int, 2> VectorImageType; + typedef otb::Image<double, 2> DoubleImageType; + typedef otb::VectorImage<double, 2> DoubleVectorImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileReader<VectorImageType> VectorReaderType; typedef otb::ImageFileWriter<VectorImageType> WriterType; ReaderType::Pointer readerPAN = ReaderType::New(); - VectorReaderType::Pointer readerXS = VectorReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + VectorReaderType::Pointer readerXS = VectorReaderType::New(); + WriterType::Pointer writer = WriterType::New(); readerPAN->SetFileName(argv[1]); readerXS->SetFileName(argv[2]); writer->SetFileName(argv[3]); -// Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare the projection (here we chose the UTM projection, other choices // are possible) and retrieve the parameters from the command line: // \begin{itemize} // \item the UTM zone // \item the hemisphere // \end{itemize} - // - // Software Guide : EndLatex -// Software Guide : BeginCodeSnippet typedef otb::GenericMapProjection<otb::TransformDirection::INVERSE> InverseProjectionType; - InverseProjectionType::Pointer utmMapProjection = InverseProjectionType::New(); + InverseProjectionType::Pointer utmMapProjection = InverseProjectionType::New(); utmMapProjection->SetWkt("Utm"); utmMapProjection->SetParameter("Zone", argv[4]); utmMapProjection->SetParameter("Hemisphere", argv[5]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We will need to pass several parameters to the orthorectification // concerning the desired output region: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet ImageType::IndexType start; start[0] = 0; start[1] = 0; @@ -144,22 +113,13 @@ int main(int argc, char* argv[]) ImageType::PointType origin; origin[0] = strtod(argv[6], nullptr); origin[1] = strtod(argv[7], nullptr); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare the orthorectification filter. And provide the different // parameters: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::OrthoRectificationFilter<ImageType, DoubleImageType, - InverseProjectionType> - OrthoRectifFilterType; + typedef otb::OrthoRectificationFilter<ImageType, DoubleImageType, InverseProjectionType> OrthoRectifFilterType; - OrthoRectifFilterType::Pointer orthoRectifPAN = - OrthoRectifFilterType::New(); + OrthoRectifFilterType::Pointer orthoRectifPAN = OrthoRectifFilterType::New(); orthoRectifPAN->SetMapProjection(utmMapProjection); orthoRectifPAN->SetInput(readerPAN->GetOutput()); @@ -168,22 +128,14 @@ int main(int argc, char* argv[]) orthoRectifPAN->SetOutputSize(size); orthoRectifPAN->SetOutputSpacing(spacing); orthoRectifPAN->SetOutputOrigin(origin); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex // Now we are able to have the orthorectified area from the PAN image. We just // have to follow a similar process for the XS image. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::OrthoRectificationFilter<VectorImageType, - DoubleVectorImageType, InverseProjectionType> - VectorOrthoRectifFilterType; + typedef otb::OrthoRectificationFilter<VectorImageType, DoubleVectorImageType, InverseProjectionType> VectorOrthoRectifFilterType; - VectorOrthoRectifFilterType::Pointer orthoRectifXS = - VectorOrthoRectifFilterType::New(); + VectorOrthoRectifFilterType::Pointer orthoRectifXS = VectorOrthoRectifFilterType::New(); orthoRectifXS->SetMapProjection(utmMapProjection); @@ -193,31 +145,18 @@ int main(int argc, char* argv[]) orthoRectifXS->SetOutputSize(size); orthoRectifXS->SetOutputSpacing(spacing); orthoRectifXS->SetOutputOrigin(origin); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // It's time to declare the fusion filter and set its inputs: - // - // Software Guide : EndLatex -// Software Guide : BeginCodeSnippet - typedef otb::SimpleRcsPanSharpeningFusionImageFilter - <DoubleImageType, DoubleVectorImageType, VectorImageType> FusionFilterType; - FusionFilterType::Pointer fusion = FusionFilterType::New(); + typedef otb::SimpleRcsPanSharpeningFusionImageFilter<DoubleImageType, DoubleVectorImageType, VectorImageType> FusionFilterType; + FusionFilterType::Pointer fusion = FusionFilterType::New(); fusion->SetPanInput(orthoRectifPAN->GetOutput()); fusion->SetXsInput(orthoRectifXS->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And we can plug it to the writer. To be able to process the images by // tiles, we use the \code{SetAutomaticTiledStreaming()} method of the writer. // We trigger the pipeline execution with the \code{Update()} method. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetInput(fusion->GetOutput()); writer->SetAutomaticTiledStreaming(); @@ -227,6 +166,4 @@ int main(int argc, char* argv[]) writer->Update(); return EXIT_SUCCESS; - } -// Software Guide : EndCodeSnippet diff --git a/Examples/Tutorials/Pipeline.cxx b/Examples/Tutorials/Pipeline.cxx index 879b7c0692d160e243b73c7864d20a0a15e8460e..1b92caec2f33c50bddf678f36e652e41c9395e05 100644 --- a/Examples/Tutorials/Pipeline.cxx +++ b/Examples/Tutorials/Pipeline.cxx @@ -19,104 +19,59 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {TutorialsPipelineOutput.png} -// Software Guide : EndCommandLineArgs +/* Example usage: +./Pipeline Input/QB_Suburb.png Output/TutorialsPipelineOutput.png +*/ + -// Software Guide : BeginLatex -// // Start by including some necessary headers and with the // usual \code{main} declaration: -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { - std::cerr << "Usage: " - << argv[0] - << " <input_filename> <output_filename>" - << std::endl; - } -// Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + { + std::cerr << "Usage: " << argv[0] << " <input_filename> <output_filename>" << std::endl; + } + // Declare the image as an \doxygen{otb}{Image}, the pixel type // is declared as an unsigned char (one byte) and the image is specified as // having two dimensions. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::Image<unsigned char, 2> ImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // To read the image, we need an \doxygen{otb}{ImageFileReader} // which is templated with the image type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - // Software Guide : EndCodeSnippet + ReaderType::Pointer reader = ReaderType::New(); - // Software Guide : BeginLatex - // // Then, we need an \doxygen{otb}{ImageFileWriter} // also templated with the image type. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileWriter<ImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); - // Software Guide : EndCodeSnippet + WriterType::Pointer writer = WriterType::New(); - // Software Guide : BeginLatex - // // The filenames are passed as arguments to the program. We keep it // simple for now and we don't check their validity. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now that we have all the elements, we connect the pipeline, // pluging the output of the reader to the input of the writer. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->SetInput(reader->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And finally, we trigger the pipeline execution calling the Update() // method on the last element of the pipeline. The last element will make // sure to update all previous elements in the pipeline. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet diff --git a/Examples/Tutorials/ScalingPipeline.cxx b/Examples/Tutorials/ScalingPipeline.cxx index 31cce8259bd624011914f4ce7d06a8fcd9f8d432..25053b87b9bb745d0d9f9920b2df72c5635aac72 100644 --- a/Examples/Tutorials/ScalingPipeline.cxx +++ b/Examples/Tutorials/ScalingPipeline.cxx @@ -19,13 +19,11 @@ */ -// Software Guide : BeginCommandLineArgs -// INPUTS: {QB_Suburb.png} -// OUTPUTS: {TutorialsScalingPipelineOutput.png} -// Software Guide : EndCommandLineArgs +/* Example usage: +./ScalingPipeline Input/QB_Suburb.png Output/TutorialsScalingPipelineOutput.png +*/ + -// Software Guide : BeginLatex -// // This example illustrates the use of the // \doxygen{itk}{RescaleIntensityImageFilter} to convert // the result for proper display. @@ -33,10 +31,7 @@ // We include the required header including the header // for the \doxygen{itk}{CannyEdgeDetectionImageFilter} and the // \doxygen{itk}{RescaleIntensityImageFilter}. -// -// Software Guide : EndLatex -// Software Guide : BeginCodeSnippet #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" @@ -44,34 +39,22 @@ #include "itkCannyEdgeDetectionImageFilter.h" #include "itkRescaleIntensityImageFilter.h" -int main(int argc, char * argv[]) +int main(int argc, char* argv[]) { if (argc != 3) - { - std::cerr << "Usage: " - << argv[0] - << " <input_filename> <output_filename>" - << std::endl; - } -// Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // + { + std::cerr << "Usage: " << argv[0] << " <input_filename> <output_filename>" << std::endl; + } + // We need to declare two different image types, one for the internal // processing and one to output the results: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef double PixelType; typedef otb::Image<PixelType, 2> ImageType; typedef unsigned char OutputPixelType; typedef otb::Image<OutputPixelType, 2> OutputImageType; - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // We declare the reader with the image template using the pixel type // double. It is worth noticing that this instantiation does not imply // anything about the type of the input image. The original image can be @@ -79,35 +62,22 @@ int main(int argc, char * argv[]) // // The writer is templated with the unsigned char image to be able to save // the result on one byte images (like png for example). - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet typedef otb::ImageFileReader<ImageType> ReaderType; - ReaderType::Pointer reader = ReaderType::New(); + ReaderType::Pointer reader = ReaderType::New(); typedef otb::ImageFileWriter<OutputImageType> WriterType; - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer writer = WriterType::New(); reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Now we are declaring the edge detection filter which is going to work with // double input and output. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::CannyEdgeDetectionImageFilter - <ImageType, ImageType> FilterType; - FilterType::Pointer filter = FilterType::New(); - // Software Guide : EndCodeSnippet + typedef itk::CannyEdgeDetectionImageFilter<ImageType, ImageType> FilterType; + FilterType::Pointer filter = FilterType::New(); - // Software Guide : BeginLatex - // // Here comes the interesting part: we declare the // \doxygen{itk}{RescaleIntensityImageFilter}. The input // image type is the output type of the edge detection @@ -120,40 +90,23 @@ int main(int argc, char * argv[]) // // This filter will actually rescale all the pixels of // the image but also cast the type of these pixels. - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef itk::RescaleIntensityImageFilter - <ImageType, OutputImageType> RescalerType; - RescalerType::Pointer rescaler = RescalerType::New(); + typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; + RescalerType::Pointer rescaler = RescalerType::New(); rescaler->SetOutputMinimum(0); rescaler->SetOutputMaximum(255); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // Let's plug the pipeline: - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet filter->SetInput(reader->GetOutput()); rescaler->SetInput(filter->GetOutput()); writer->SetInput(rescaler->GetOutput()); - // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // // And finally, we trigger the pipeline execution calling the Update() // method on the writer - // - // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet writer->Update(); return EXIT_SUCCESS; } -// Software Guide : EndCodeSnippet