Skip to content

Commit

Permalink
ENH: Enable specification of target Size for image resampling (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
aylward authored Apr 19, 2022
1 parent c33ba00 commit 549e2c5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/tubeResampleImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class ResampleImage:
/** Set Output Index */
tubeWrapForceSetMacro( Index, std::vector<int>, Filter );

/** Set Output Index */
tubeWrapForceSetMacro( Size, std::vector<int>, Filter );

/** Set Output Resample Factor */
tubeWrapForceSetMacro( ResampleFactor, std::vector<double>, Filter );

Expand Down
4 changes: 4 additions & 0 deletions src/Filtering/itktubeReResampleImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class ReResampleImageFilter
/** Set Output Index */
void SetIndex( std::vector<int> i );

/** Set Output Size */
void SetSize( std::vector<int> i );

/** Set Output Resample Factor */
void SetResampleFactor( std::vector<double> rf );

Expand Down Expand Up @@ -127,6 +130,7 @@ class ReResampleImageFilter
std::vector<double> m_Spacing;
std::vector<double> m_Origin;
std::vector<int> m_Index;
std::vector<int> m_Size;
std::vector<double> m_ResampleFactor;
bool m_MakeIsotropic;
bool m_MakeHighResIso;
Expand Down
21 changes: 20 additions & 1 deletion src/Filtering/itktubeReResampleImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ReResampleImageFilter( void )
m_Spacing.clear();
m_Origin.clear();
m_Index.clear();
m_Size.clear();
m_ResampleFactor.clear();
m_MakeIsotropic = false;
m_MakeHighResIso = false;
Expand Down Expand Up @@ -85,13 +86,15 @@ Update( void )
}
outDirection = inDirection;

bool updateSize = true;
if( m_MatchImage )
{
outSpacing = m_MatchImage->GetSpacing();
outOrigin = m_MatchImage->GetOrigin();
outDirection = m_MatchImage->GetDirection();
outSize = m_MatchImage->GetLargestPossibleRegion().GetSize();
outIndex = m_MatchImage->GetLargestPossibleRegion().GetIndex();
updateSize = false;
}

if( m_Origin.size() > 0 )
Expand All @@ -108,6 +111,14 @@ Update( void )
outIndex[i] = m_Index[i];
}
}
if( m_Size.size() > 0 )
{
for( unsigned int i = 0; i < VDimension; i++ )
{
outSize[i] = m_Size[i];
}
updateSize = false;
}
if( m_Spacing.size() > 0 )
{
for( unsigned int i = 0; i < VDimension; i++ )
Expand Down Expand Up @@ -163,7 +174,7 @@ Update( void )
}
}

if( !m_MatchImage )
if( updateSize )
{
std::vector< double > outResampleFactor;
outResampleFactor.resize( VDimension );
Expand Down Expand Up @@ -253,6 +264,14 @@ SetIndex( std::vector<int> i )
m_Index = i;
}

template< class TPixel, unsigned int VDimension >
void
ReResampleImageFilter< TPixel, VDimension >::
SetSize( std::vector<int> i )
{
m_Size = i;
}

template< class TPixel, unsigned int VDimension >
void
ReResampleImageFilter< TPixel, VDimension >::
Expand Down

0 comments on commit 549e2c5

Please sign in to comment.