If it is not able to detect the whole rectangle and is like in separate patches then just round off whole area to make a white rectangle.