Thanks to everyone for answering this question. I found my mistake. I am going to describe it briefly below. Hope this helps others facing this issue.
1) I executed the C and C ++ commands for the ROI image. Obviously, the OpenCV 'C' and 'C ++' methods handle ROI in different ways.
2) In "C", the ROI is considered as a completely different image. Therefore, when you perform functions such as cvSmooth, cvDlate, etc., Where you need to mention the methods of extrapolating pixels at the border, the "C" API does not refer to the original image for pixels that go beyond the left / right / top / bottom most pixels. In fact, it interpolates the pixel values according to the method you mentioned.
3) But in 'C ++', I found that it always refers to the original image for the pixels behind the left / right / top / bottom most pixels. Therefore, the mentioned method of extrapolating boundary pixels does not affect your output if there are pixels around your area of interest in the original image.
I think that it applies the method of extrapolating order pixels to the original image instead of ROI, unlike API C. I do not know if this is an error; I have not fully read the OpenCV 2.4.2 C ++ API documentation. (Please correct me if I am wrong)
To get support, I posted the I / O images below:
Output for API C and C ++:
ENTRANCE:
& lt; --- input
OpenCV 'C' API :
IplImage *src = cvLoadImage("input.png", 0); cvSetImageROI( src, cvRect(33,19,250,110)); cvSaveImage( "before_gauss.png", src ); cvSmooth( src, src, CV_GAUSSIAN ); cvSaveImage("after_gauss.png", src); IplConvKernel *element = cvCreateStructuringElementEx(3,3,1,1,CV_SHAPE_RECT); cvCanny( src, src, 140, 40 ); cvSaveImage("after_canny.png", src); cvDilate( src, src, element, 5); cvSaveImage("dilate.png", src);
CONCLUSION:
& lt; - before_gauss
& lt; --- after_gauss
& lt; --- after_canny
& lt; --- expand
OpenCV C ++ API :
cv::Mat src = cv::imread("input.png", 0); cv::Mat src_ROI = src( cv::Rect(33,19,250,110)); cv::imwrite( "before_gauss.png", src_ROI ); cv::GaussianBlur( src_ROI, src_ROI, cv::Size(3,3),0 ); cv::imwrite( "after_gauss.png", src_ROI ); cv::Mat element = cv::getStructuringElement( cv::MORPH_RECT, cv::Size(3, 3), cv::Point(1,1)); cv::Canny( src_ROI, src_ROI, 140, 40); cv::imwrite( "after_canny.png", src_ROI ); cv::dilate( src_ROI, src_ROI, element, cv::Point(1,1), 5); cv::imwrite( "dilate.png", src_ROI );
CONCLUSION:
& lt; - before_gauss

^^^^^ after_gauss (NOTE: the borders are no longer completely black, they are grayish)

^^^^^ after_canny

^^^^^ expand
DECISION:
Create a separate copy of the ROI and use it for further analysis;
src_ROI.copyTo( new_src_ROI );
Use new_src_ROI for further analysis. If anyone has a better solution, please write below