Ask Your Question

sequence of morphological operators

asked 2016-10-18 11:22:49 -0600

Rok gravatar image

updated 2016-10-18 11:23:48 -0600

Hi, I'm facing and old code review, and trying to optimize and better understand it. I have this function:

cv::Mat morphology(cv::Mat frame)
    cv::Mat process1, process2, process3, process4;
    int size_slider = 3;
    cv::Mat st_elem = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(size_slider, size_slider));
    cv::dilate(frame, process1, 3);
    cv::erode(process1, process2, st_elem);
    cv::erode(process2, process3, st_elem);
    cv::dilate(process3, process4, 2);
    return process4;

Do I get the same result substituting the double erode function call with only one, doubling the structuring element? How to choose the structuring element shape? I've always tried to understand this part, but only found empirical solution on the web, (like this one). I'd like to have a logical approach to morphological operators. Any hints about this code will be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-18 11:50:18 -0600

Tetragramm gravatar image

updated 2016-10-18 11:50:35 -0600

Well, the dilate functions as you have there are doing nothing at all. So you're just eroding twice. It's the same as changing iterations to 2 instead of the default 1. Note that doubling the size is not the same, you can test that yourself.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-10-18 11:22:49 -0600

Seen: 243 times

Last updated: Oct 18 '16