Monday 16 September 2013

Morphological operations and openCV2--01 : close and open

    Closing(3) and opening(4) are very similar to dilation(1) and erosion(2), but they are less destructive compare to dilation and erosion.From the view of mathematics, opening is erosion followed by a dilation with the same structuring element;Closing is dilation followed by a erosion with the same structuring element.


graph_00(Original image)
    Apply opening or closing in openCV2 is very easy

Close

cv::Mat const structure_elem = cv::getStructuringElement(
                     cv::MORPH_RECT, cv::Size(5, 5));
cv::Mat close_result;
cv::morphologyEx(input, close_result, 
            cv::MORPH_CLOSE, structure_elem);
graph_01(dilate)

graph_02(close)
Open
cv::Mat const structure_elem = cv::getStructuringElement(
                 cv::MORPH_RECT, cv::Size(5, 5));
cv::Mat open_result;
cv::morphologyEx(input, open_result, 
             cv::MORPH_OPEN, structure_elem); 
graph_03(erosion)
graph_04(open)
  Do remember that open and close are idempotent operation, that means the results would be the same if you apply open or close on the same image more than one time.

As usual, the codes can download from github

No comments:

Post a Comment