Updated by Anna Kogan over 12 years ago
It looks like cv::dilate doesn't respect image boundaries with shallow copy images.
Attached is an example function that creates a black one channel parent image with a 2px line at the bottom, a sub image without the line, and a clone of the sub image. Both the sub image and its clone are dilated twice with an erosion rect, and then shown along with the absolute difference. In an optimal world the absolute difference image would be all zeros.
Opencv version 2.4.2 VC10 x86
<pre>
void cvDilateBugExample( void )
{
cv::Mat image = cv::Mat::zeros( cv::Size( 640, 482 ), CV_8UC1 );
cv::Mat( image, cv::Rect( 0, 480, 640, 2 ) ).setTo( cv::Scalar( 255 ) );
cv::Mat subImage( image, cv::Rect( 0, 0, 640, 480 ) );
cv::Mat subImageClone = subImage.clone();
const int erosionWidth = 10;
const cv::Size erosionSize( 2*erosionWidth + 1, 2*erosionWidth +1 );
cv::Mat element = getStructuringElement( cv::MORPH_RECT, erosionSize, cv::Point( erosionWidth, erosionWidth ) );
dilate( subImage, subImage, element );
dilate( subImage, subImage, element );
dilate( subImageClone, subImageClone, element );
dilate( subImageClone, subImageClone, element );
cv::Mat diff;
cv::absdiff( subImage, subImageClone, diff );
cv::imshow( "DilateBug", diff );
cv::imshow( "subImage", subImage );
cv::imshow( "subImageClone", subImageClone );
cv::waitKey( -1 );
cv::destroyAllWindows();
}
</pre>
Attached is an example function that creates a black one channel parent image with a 2px line at the bottom, a sub image without the line, and a clone of the sub image. Both the sub image and its clone are dilated twice with an erosion rect, and then shown along with the absolute difference. In an optimal world the absolute difference image would be all zeros.
Opencv version 2.4.2 VC10 x86
<pre>
void cvDilateBugExample( void )
{
cv::Mat image = cv::Mat::zeros( cv::Size( 640, 482 ), CV_8UC1 );
cv::Mat( image, cv::Rect( 0, 480, 640, 2 ) ).setTo( cv::Scalar( 255 ) );
cv::Mat subImage( image, cv::Rect( 0, 0, 640, 480 ) );
cv::Mat subImageClone = subImage.clone();
const int erosionWidth = 10;
const cv::Size erosionSize( 2*erosionWidth + 1, 2*erosionWidth +1 );
cv::Mat element = getStructuringElement( cv::MORPH_RECT, erosionSize, cv::Point( erosionWidth, erosionWidth ) );
dilate( subImage, subImage, element );
dilate( subImage, subImage, element );
dilate( subImageClone, subImageClone, element );
dilate( subImageClone, subImageClone, element );
cv::Mat diff;
cv::absdiff( subImage, subImageClone, diff );
cv::imshow( "DilateBug", diff );
cv::imshow( "subImage", subImage );
cv::imshow( "subImageClone", subImageClone );
cv::waitKey( -1 );
cv::destroyAllWindows();
}
</pre>