From 2a58c00b2a38482efa4be63d60c61febfb2467ca Mon Sep 17 00:00:00 2001 From: remi cresson <remi.cresson@teledetection.fr> Date: Tue, 6 Nov 2018 14:07:04 +0100 Subject: [PATCH] WIP --- .../otbTensorflowMultisourceModelFilter.hxx | 66 +------------------ 1 file changed, 3 insertions(+), 63 deletions(-) diff --git a/include/otbTensorflowMultisourceModelFilter.hxx b/include/otbTensorflowMultisourceModelFilter.hxx index 7769341..18a55e0 100644 --- a/include/otbTensorflowMultisourceModelFilter.hxx +++ b/include/otbTensorflowMultisourceModelFilter.hxx @@ -40,7 +40,6 @@ void TensorflowMultisourceModelFilter<TInputImage, TOutputImage> ::SmartPad(RegionType& region, const SizeType &patchSize) { - std::cout << "SMARTPAD: patchSize=" << patchSize << std::endl; for(unsigned int dim = 0; dim<OutputImageType::ImageDimension; ++dim) { const SizeValueType psz = patchSize[dim]; @@ -127,27 +126,13 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> ::ImageToExtent(ImageType* image, PointType &extentInf, PointType &extentSup, const SizeType &receptiveField, const PointType &refExtInf, const SpacingType &refSpacing) { - std::cout << "ImageToExtent() " << std::endl; // First, compute the image extent (Here, pixel = area) - std::cout << "ComputeImageExtent() " << std::endl; ComputeImageExtent(image, extentInf, extentSup, receptiveField); - std::cout << "extentInf " << extentInf << std::endl; - std::cout << "extentSup " << extentSup << std::endl; - std::cout << "refExtInf " << refExtInf << std::endl; - std::cout << "refSpacing " << refSpacing << std::endl; - // Then, clip this physical extent to the reference image grid - std::cout << "AlignExtentToReferenceGrid() " << std::endl; AlignExtentToReferenceGrid(extentInf, extentSup, refExtInf, refSpacing); - std::cout << "extentInf " << extentInf << std::endl; - std::cout << "extentSup " << extentSup << std::endl; - std::cout << "refExtInf " << refExtInf << std::endl; - std::cout << "refSpacing " << refSpacing << std::endl; - std::cout << "ImageToExtent() ok" << std::endl; - } /** @@ -160,22 +145,14 @@ bool TensorflowMultisourceModelFilter<TInputImage, TOutputImage> ::OutputRegionToInputRegion(const RegionType &outputRegion, RegionType &inputRegion, ImageType* &inputImage) { - - std::cout << "OutputRegionToInputRegion()" << std::endl; - std::cout << "OutputRegionToInputRegion(): outputRegion=" << outputRegion << std::endl; - // Mosaic Region Start & End (mosaic image index) const IndexType outIndexStart = outputRegion.GetIndex(); const IndexType outIndexEnd = outputRegion.GetUpperIndex(); - std::cout << "OutputRegionToInputRegion(): outIndexStart=" << outIndexStart << std::endl; - std::cout << "OutputRegionToInputRegion(): outIndexEnd=" << outIndexEnd << std::endl; // Mosaic Region Start & End (geo) PointType outPointStart, outPointEnd; this->GetOutput()->TransformIndexToPhysicalPoint(outIndexStart, outPointStart); this->GetOutput()->TransformIndexToPhysicalPoint(outIndexEnd , outPointEnd ); - std::cout << "OutputRegionToInputRegion(): outPointStart=" << outPointStart << std::endl; - std::cout << "OutputRegionToInputRegion(): outPointEnd=" << outPointEnd << std::endl; // Add the half-width pixel size of the input image // and remove the half-width pixel size of the output image @@ -185,7 +162,6 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> for(unsigned int dim = 0; dim<OutputImageType::ImageDimension; ++dim) { const SpacingValueType border = 0.5 * (inputSpc[dim] - outputSpc[dim]); - std::cout << "SpacingValueType=" << border << std::endl; if (outPointStart[dim] < outPointEnd[dim]) { outPointStart[dim] += border; @@ -197,17 +173,12 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> outPointEnd [dim] += border; } } - std::cout << "OutputRegionToInputRegion(): outPointStart=" << outPointStart << std::endl; - std::cout << "OutputRegionToInputRegion(): outPointEnd=" << outPointEnd << std::endl; // Mosaic Region Start & End (input image index) IndexType defIndexStart, defIndexEnd; inputImage->TransformPhysicalPointToIndex(outPointStart, defIndexStart); inputImage->TransformPhysicalPointToIndex(outPointEnd , defIndexEnd); - std::cout << "OutputRegionToInputRegion(): defIndexStart=" << defIndexStart << std::endl; - std::cout << "OutputRegionToInputRegion(): defIndexEnd=" << defIndexEnd << std::endl; - // Compute input image region for(unsigned int dim = 0; dim<OutputImageType::ImageDimension; ++dim) { @@ -215,16 +186,8 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> inputRegion.SetSize(dim, vnl_math_max(defIndexStart[dim], defIndexEnd[dim]) - inputRegion.GetIndex(dim) + 1); } - std::cout << "OutputRegionToInputRegion(): inputRegion=" << inputRegion << std::endl; - - // crop the input requested region at the input's largest possible region - std::cout << "OutputRegionToInputRegion() ok" << std::endl; - bool ret = inputRegion.Crop( inputImage->GetLargestPossibleRegion() ); - std::cout << "OutputRegionToInputRegion() returns " << ret << std::endl; - std::cout << "OutputRegionToInputRegion() returns " << inputRegion << std::endl; - - return ret; + return inputRegion.Crop( inputImage->GetLargestPossibleRegion() ); } @@ -266,7 +229,6 @@ void TensorflowMultisourceModelFilter<TInputImage, TOutputImage> ::GenerateOutputInformation() { -std::cout << "GenerateOutputInformation()" << std::endl; Superclass::GenerateOutputInformation(); ////////////////////////////////////////////////////////////////////////////////////////// @@ -277,17 +239,12 @@ std::cout << "GenerateOutputInformation()" << std::endl; m_OutputSpacing = this->GetInput(m_ReferenceGridImage)->GetSignedSpacing(); m_OutputSpacing[0] *= m_OutputSpacingScale; m_OutputSpacing[1] *= m_OutputSpacingScale; -std::cout << "Compute the spacing from the scale factor and the reference grid" << std::endl; // Compute the extent of the reference image PointType refExtInf, refExtSup; ImageType * refImage = static_cast<ImageType *>( Superclass::ProcessObject::GetInput(m_ReferenceGridImage) ); ComputeImageExtent(refImage, refExtInf, refExtSup, this->GetInputReceptiveFields().at(m_ReferenceGridImage)); -std::cout << "Compute the extent of the reference image" << std::endl; -std::cout << "GenerateOutputInformation() refExtInf=" << refExtInf << std::endl; -std::cout << "GenerateOutputInformation() refExtSup=" << refExtSup << std::endl; - // Compute the extent (pixel area) of each input images and update the global extent PointType extentInf, extentSup; extentSup.Fill(itk::NumericTraits<double>::max()); @@ -300,8 +257,6 @@ std::cout << "GenerateOutputInformation() refExtSup=" << refExtSup << std::endl; PointType currentInputImageExtentInf, currentInputImageExtentSup; ImageToExtent(currentImage, currentInputImageExtentInf, currentInputImageExtentSup, this->GetInputReceptiveFields()[imageIndex], refExtInf, m_OutputSpacing); - std::cout << "GenerateOutputInformation() currentInputImageExtentInf=" << currentInputImageExtentInf << std::endl; - std::cout << "GenerateOutputInformation() currentInputImageExtentSup=" << currentInputImageExtentSup << std::endl; for(unsigned int dim = 0; dim<ImageType::ImageDimension; ++dim) { @@ -314,10 +269,7 @@ std::cout << "GenerateOutputInformation() refExtSup=" << refExtSup << std::endl; for(unsigned int dim = 0; dim<ImageType::ImageDimension; ++dim) m_OutputSize[dim] = std::floor( (extentSup[dim] - extentInf[dim]) / vcl_abs(m_OutputSpacing[dim]) ) ; m_OutputOrigin[0] = extentInf[0] + 0.5 * m_OutputSpacing[0]; - m_OutputOrigin[1] = extentSup[1] + 0.5 * m_OutputSpacing[0]; - - std::cout << "m_OutputOrigin=" << m_OutputOrigin << std::endl; - std::cout << "Input Origin=" << this->GetInput(0)->GetOrigin() << std::endl; + m_OutputOrigin[1] = extentSup[1] - 0.5 * m_OutputSpacing[0]; // Set output grid size if (!m_ForceOutputGridSize) @@ -381,8 +333,6 @@ std::cout << "GenerateOutputInformation() refExtSup=" << refExtSup << std::endl; itk::EncapsulateMetaData(outputPtr->GetMetaDataDictionary(), MetaDataKey::TileHintX, m_OutputGridSize[0]); itk::EncapsulateMetaData(outputPtr->GetMetaDataDictionary(), MetaDataKey::TileHintY, m_OutputGridSize[1]); - std::cout << "largestPossibleRegion is " << largestPossibleRegion << std::endl; - std::cout << "GenerateOutputInformation() ok" << std::endl; } @@ -391,20 +341,15 @@ void TensorflowMultisourceModelFilter<TInputImage, TOutputImage> ::GenerateInputRequestedRegion() { - std::cout << "GenerateInputRequestedRegion()" << std::endl; Superclass::GenerateInputRequestedRegion(); // Output requested region RegionType requestedRegion = this->GetOutput()->GetRequestedRegion(); - std::cout << "Req output region (nefore aligment) : " << requestedRegion << std::endl; - // First, align the output region EnlargeToAlignedRegion(requestedRegion); - std::cout << "Req output region (after aligment) : " << requestedRegion << std::endl; - // For each image, get the requested region for(unsigned int i = 0; i < this->GetNumberOfInputs(); ++i) { @@ -415,7 +360,7 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> if (!OutputRegionToInputRegion(requestedRegion, inRegion, inputImage) ) { // Image does not overlap requested region: set requested region to null - std::cout << "Image #" << i << " :\n" << inRegion << " is outside the requested region" << std::endl; + itkExceptionMacro("Image #" << i << " :\n" << inRegion << " is outside the requested region" << std::endl); inRegion.GetModifiableIndex().Fill(0); inRegion.GetModifiableSize().Fill(0); } @@ -426,9 +371,7 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> toPad[1] -= 1 + (this->GetOutputExpressionFields().at(0)[1] - 1) * m_OutputSpacingScale; // Pad with radius - std::cout << "Before smartpad image " << i << " req region is " << inRegion << std::endl; SmartPad(inRegion, toPad); - std::cout << "After smartpad image " << i << " req region is " << inRegion << std::endl; // We need to avoid some extrapolation when mode is patch-based. // The reason is that, when some input have a lower spacing than the @@ -445,10 +388,7 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage> // Update the requested region inputImage->SetRequestedRegion(inRegion); - std::cout << "image " << i << " req region is " << inRegion << std::endl; - } // next image - std::cout << "GenerateInputRequestedRegion() ok" << std::endl; } -- GitLab