62 typename imOutT::Scalar value
65 int nRows = imIn.rows() + 2 * padSz;
66 int nCols = imIn.cols() + 2 * padSz;
68 imOut = imOutT::Constant( nRows, nCols, value );
70 imOut.block( padSz, padSz, imIn.rows(), imIn.cols() ) = imIn;
89 typename imOutT::Scalar value
92 int nRows = imIn.rows() + 2 * padSz;
93 int nCols = imIn.cols() + 2 * padSz;
95 imOut = imOutT::Constant( nRows, nCols, value );
97 imOut.block( padSz, padSz, imIn.rows(), imIn.cols() ) = imIn;
119 int dim1 = imIn.rows();
120 int dim2 = imIn.cols();
122 imOut.resize( dim1 + 2 * padSz, dim2 + 2 * padSz );
124 imOut.block( padSz, padSz, dim1, dim2 ) = imIn;
127 for(
int i = 0; i < padSz; ++i )
129 for(
int j = 0; j < imOut.cols(); ++j )
133 imOut( i, j ) = imIn( 0, 0 );
134 imOut( imOut.rows() - 1 - i, j ) = imIn( dim1 - 1, 0 );
136 else if( j >= dim2 + padSz )
138 imOut( i, j ) = imIn( 0, dim2 - 1 );
139 imOut( imOut.rows() - 1 - i, j ) = imIn( dim1 - 1, dim2 - 1 );
143 imOut( i, j ) = imOut( padSz, j );
144 imOut( imOut.rows() - padSz + i, j ) = imOut( padSz + dim1 - 1, j );
150 for(
int i = padSz; i < dim1 + padSz; ++i )
152 for(
int j = 0; j < padSz; ++j )
154 imOut( i, j ) = imOut( i, padSz );
155 imOut( i, imOut.cols() - 1 - j ) = imOut( i, imOut.cols() - 1 - padSz );
183 typedef imInT imMaskT;
185 int dim1 = imMask.rows();
186 int dim2 = imMask.cols();
188 imOut.resize( dim1, dim2 );
190 int stR = 0.5 * ( dim1 - imIn.rows() );
191 int stC = 0.5 * ( dim2 - imIn.cols() );
195 mxError(
"padImage", MXE_INVALIDARG,
"imMask must have at least as many rows as imIn." );
200 mxError(
"padImage", MXE_INVALIDARG,
"imMask must have at least as many columns as imIn." );
204 imOut.block( stR, stC, imIn.rows(), imIn.cols() ) = imIn;
208 imMaskT tMask = imMask;
210 std::vector<int> nmi, nmj;
212 for(
unsigned int n = 0; n < padSz; ++n )
216 for(
int ii = 0; ii < dim1; ++ii )
218 for(
int jj = 0; jj < dim2; ++jj )
220 if( tMask( ii, jj ) == 1 )
223 typename imOutT::Scalar mv = 0;
228 for(
int i = -1; i <= 1; ++i )
230 for(
int j = -1; j <= 1; ++j )
232 if( i == 0 && j == 0 )
234 if( ii + i < 0 || ii + i >= dim1 )
236 if( jj + j < 0 || jj + j >= dim2 )
239 if( tMask( ii + i, jj + j ) == 1 )
241 mv += imOut( ii + i, jj + j );
250 imOut( ii, jj ) = mv / nv;
257 for(
size_t i = 0; i < nmi.size(); ++i )
259 tMask( nmi[i], nmj[i] ) = 1;
281 if( 2 * padSz > imIn.rows() )
283 mxError(
"cutPaddedImage", MXE_INVALIDARG,
"padSz too large, must be < imIn.rows()/2" );
287 if( 2 * padSz > imIn.cols() )
289 mxError(
"cutPaddedImage", MXE_INVALIDARG,
"padSz too large, must be < imIn.cols()/2" );
293 int nRows = imIn.rows() - 2 * padSz;
294 int nCols = imIn.cols() - 2 * padSz;
296 imOut = imIn.block( padSz, padSz, nRows, nCols );
int padImageRef(imOutT imOut, imInT imIn, unsigned int padSz, typename imOutT::Scalar value)
Pad an image with a constant value for reference types.
int padImage(imOutT &imOut, imInT &imIn, unsigned int padSz, typename imOutT::Scalar value)
Pad an image with a constant value.