I need to create a mask to retrieve an object (foreground object) based on two related images.
Image 1:
[![enter image description here]
Image 2:
[![enter image description here]
The images contain a foreground object and a background with texture. The two images are mostly the same except that in image2, the foreground object may have changed a little bit (it could have been rotated, translated or/and scaled).
Using OpenCV, I did the followings:
- perform image alignment (using
findTransformECC
with paramcv::MOTION_AFFINE
) to get transformation of foreground; - do transformation to image1 (using
cv::warpAffine
with paramcv::INTER_LINEAR
+cv::WARP_INVERSE_MAP
) based on the transform matrix above; - do absolute diff (
cv::absdiff
&cv::threshold
with paramcv::THRESH_BINARY_INV
) between image2 and already transformed image1.
I think I am close to my goal but I still can not get clean mask of foreground object due to remaining noises on the background area.
What is the solution to remove all noise on the image_absdiff_invert.png (above) in order to create a clean mask of the foreground object ?