ITK/Examples/SimpleOperations/WidthHeight: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==WidthHeight.cxx==
{{warning|1=The media wiki content on this page is no longer maintained.  The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releases.   In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
<source lang="cpp">
}}
#include "itkImage.h"
#include "itkImageFileReader.h"


int main(int argc, char *argv[])
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
{
  // Verify command line arguments
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
    }
 
  typedef itk::Image<float, 2>            ImageType;
  typedef itk::ImageFileReader<ImageType> ReaderType;
 
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->Update();
 
  std::cout << reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] << " "
            << reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] << std::endl;
 
  // An example image had w = 200 and h = 100 (it is wider than it is tall). The above output
  // 200 100
  // so w = GetSize()[0]
  // and h = GetSize()[1]
 
  // A pixel inside the region
  itk::Index<2> indexInside;
  indexInside[0] = 150;
  indexInside[1] = 50;
  std::cout << reader->GetOutput()->GetLargestPossibleRegion().IsInside(indexInside) << std::endl;
 
  // A pixel outside the region
  itk::Index<2> indexOutside;
  indexOutside[0] = 50;
  indexOutside[1] = 150;
  std::cout << reader->GetOutput()->GetLargestPossibleRegion().IsInside(indexOutside) << std::endl;
 
  // This means that the [0] component of the index is referencing the left to right (x) value
  // and the [1] component of Index is referencing the top to bottom (y) value
 
  return EXIT_SUCCESS;
}
</source>
 
{{ITKCMakeLists|WidthHeight}}

Latest revision as of 21:17, 3 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.

[ITK Sphinx Examples]