You must use the fact that the red component of each square is 255 and fulfills the threshold. Here is what I did:
code:
Mat src = imread("input.png"), red; extractChannel(src, red, 2); threshold(red, red, 254, 255, THRESH_BINARY); Mat element = getStructuringElement(MORPH_RECT, Size( 2, 2 ), Point( 1, 1 )); dilate(red, red, element);
source share