Write c++ code for a function that takes an Image struct (see code reference on
ID: 3733850 • Letter: W
Question
Write c++ code for a function that takes an Image struct (see code reference on last page) and returns a new image with the mirror reflection. (Chart is criteria)
Original: New: Image horizontalReflect (const Image&source;) make Image newlmage as local variable loop over loop over every col (call this j) calculate/use counter to get flipped column .5 .5 .5 .5 every roW -get correct value. For col j, partner should be: (IMG WIDTH-j-1) copy red, green, blue values from source to newlmage return newlmage .5Explanation / Answer
/*
The National Library of Medicine Insight Segmentation and Registration Toolkit (ITK) is open-source software system developed by medical image processing interest in two, three and more dimensions.
this itk library is useful becuase It is a common task in image analysis to require to compare how similar two image might be. This comparison may be limited to a particular region of each image. Image Similarity Metrics are methods that produce a quantitative evaluation of the similarity between two image or two image regions.
This techniques are used as a base for registration methods because they provide the information that indicates when the registration process is going in the right direction.
A large number of Image Similarity Metrics have been proposed in the medical image and computer vision community. There is no a right image similarity metric but a set of metrics that are appropiated for particular applications. Metrics fit very well the notions of tools in a toolkit. You need a set of them because none is able to perform the same job as the other.
The following table presents a comparison between image similarity metrics. This is by no means an exhaustive comparison but will at least provide some guidance as to what metric can be appropiated for particular problems.
*/
/*
itk::FlipImageFilter this class used to flip. lipImageFilter reflects an image about the specified axes. The reflection axes are set via method SetFlipAxes( array ) where the input is a FixedArray<bool,ImageDimension>. The image is reflected across axes for which array[i] is true.
*/
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkFlipImageFilter.h"
//required imports fot itk
int main(int argc, char* argv[])
{
if( argc != 4 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " <InputFileName> <OutputFileName> <AxisToFlip>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
constexpr unsigned Dimension = 2;
using PixelType = unsigned char;
using ImageType = itk::Image< PixelType, Dimension >;
using ReaderType = itk::ImageFileReader< ImageType >;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
using FlipImageFilterType = itk::FlipImageFilter< ImageType >;
FlipImageFilterType::Pointer flipFilter
= FlipImageFilterType::New ();
flipFilter->SetInput( reader->GetOutput() );
FlipImageFilterType::FlipAxesArrayType flipAxes;
if( atoi( argv[3] ) == 0 )
{
flipAxes[0] = true;
flipAxes[1] = false;
}
else
{
flipAxes[0] = false;
flipAxes[1] = true;
}
flipFilter->SetFlipAxes( flipAxes );
using WriterType = itk::ImageFileWriter< ImageType >;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput( flipFilter->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & error )
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.