Dilation and erosion in Android

14,078

Solution 1

Android has mostly the same functions has the documented C++/Python, so all you need to do is find which class they belong to, in this case, Imgproc:

Imgproc.erode(mInput, mInput, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2,2)));        

Imgproc.dilate(mInput, mInput, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));

Solution 2

You do have erosion and dilation in OpenCV. What you are looking for to "brige the gap" is probably what is called a closure, i.e. a dilatation followed by an erosion. It can be done using a single call to morphologyEx function. It could be an "opening", depending if you want to erode the white or black parts.

Share:
14,078
Hua Er Lim
Author by

Hua Er Lim

Updated on August 04, 2022

Comments

  • Hua Er Lim
    Hua Er Lim over 1 year

    According to my research,dilation and erosion can be used to bridge the gap for a image after binarize the image.

    I not sure if cvSmooth needs to be used or not.

    • CTZStef
      CTZStef over 11 years
      I don't know anything about OpenCV on Android, but I know that smoothing has nothing to do with morphological operations such as dilation and erosion. You will probably have first to obtain your binary image using cvTresh though (or the equivalent on Android).
    • Hua Er Lim
      Hua Er Lim over 11 years
      CTZStef,can i know how to use cvTresh to obtain the binary image?Before this,i use my own method to obtain the binary image and the effect is not good.
    • CTZStef
      CTZStef over 11 years
      I guess you will find everything you need (e.g. documentation) here : code.opencv.org/projects/opencv/wiki/OpenCV4Android
  • Hua Er Lim
    Hua Er Lim over 11 years
    remi,i think you are right,i want to use dilation followed by erosion.Because i am new to android,can you give an example on how to code it for android?Thanks.
  • Hua Er Lim
    Hua Er Lim over 11 years
    remi,and can you tell me how to control wan erode the white or block parts?Thanks in advanced.
  • remi
    remi over 11 years
    erode the black = dilate the white. You have to do a simple test, you cannot change that, I dont remember what is decided in OpenCV implementation. As for Android samples, I only use C++/python bindings, but it should be straightforward, shouldn't it?