I have a part of image and I want to shift it down say by 25 pixels like shown in the picture.
I have mask of the region I want to shift down. The total image size should not change. So, the operation is cut and paste. The region where I cut can be filled with 0 or 255.
Platform is C++
解决方案
Create two sub-images: the first sub1 around the pattern you want to move and the second sub2, same size than sub1, around the destination. Copy sub1 into sub2 then fill sub1 with black or white color. You need obviously to use the mask cropped at the same size than the two sub-images.
This is pseudo-code, to illustrate the idea:
cv::Mat YourImage;
cv::Mat YourMask;
std::vector<:point> YourPatternContour;
cv::Rect sub1ROI = cv::boundingRect(YourPatternContour);
cv::Mat sub1 = YourImage(sub1ROI);
cv::Mat mask = YourMask(sub1ROI);
cv::Rect sub2ROI = sub1ROI + cv::Point(25,25);
cv::Mat sub2 = YourImage(sub2ROI);
sub1.copyTo(sub2, mask);
sub1.set(0, mask);