Morphology Transformations

void morphologyEx(InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() )

 Parameters:
  • src – Source image. The number of channels can be arbitrary. The depth should be one of CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  • dst – Destination image of the same size and type as src .
  • op – Type of a morphological operation that can be one of the following:
    • MORPH_OPEN (2) - an opening operation
    • MORPH_CLOSE (3) - a closing operation
    • MORPH_GRADIENT (4) - a morphological gradient
    • MORPH_TOPHAT (5) - “top hat”
    • MORPH_BLACKHAT (6) - “black hat”
  • kernel – Structuring element.
  • iterations – Number of times erosion and dilation are applied.
  • borderType – Pixel extrapolation method. See borderInterpolate() for details.
  • borderValue – Border value in case of a constant border. The default value has a special meaning. See createMorphologyFilter() for details.
Brief description and an implementation is available in OpenCV documentation.

Steps:

  1. Load image and convert to gray-scale.
  2. Create a structuring element (getStructuringElement)
  3.  Apply morphological operation (morphologyEx)
  4. Show the result

Functions:


Example: 

------------

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat src = imread("lena.jpg", 0);

    // Create a structuring element (SE)
    int morph_size = 2;
    Mat element = getStructuringElement( MORPH_RECT, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
    cout<<element;

    Mat dst; // result matrix
    // Apply the specified morphology operation
    for (int i=1;i<10;i++)
    {   
    morphologyEx( src, dst, MORPH_TOPHAT, element, Point(-1,-1), i );   
    //morphologyEx( src, dst, MORPH_TOPHAT, element ); // here iteration=1
    imshow("source", src);
    imshow("result", dst);
    waitKey(1000);
    }   
    return 0;
}

------------




6 comments:

  1. أساليب تنظيف المكيفات السبليت


    كثيراً ما يتساءل العديد من الناس عن طريقة تنظيف الوحدة الخارجية للمكيف دون أن تتسبب عملية التنظيف في تلف الجهاز، سواءً كانت المكيفات الكلاسيكية القديمة التي تأتي بفتحة نافذة في جدارالغرفة أو من تلك الحديثة أو على شكل وحدات متحركة في جوانب. عليك عزيزي القارئ أن تدرك أهمية أن تقوم بتنظيف جهاز التكييف الخاص بك باستمرار (خصوصاً الوحدة الخارجية)؛ وتلك الأهمية هي تجنب تراكم الأوساخ والغبار والأتربة ويصبح من الصعب التخلّص منها لاحقاً وتؤثر على كفاءة المكيف كما يخرج منه هواء مشبع بالأتربة ضار بالصحة.
    أساليب تنظيف المكيفات السبليت

    ReplyDelete
  2. I think this post is very informative and helpful. I have to add this to my collection. You did a great job! Very good story. Based on your previous post How to get good at butterfly clicking, I also wrote an in-depth article. You may be interested in reading this article butterfly clicking. Thanks for visiting.

    ReplyDelete
  3. I sincerely appreciate you starting such a wonderful blog. If you're one of the people in need of help, you may talk to experts who have degrees in academic writing. They could be able to assist students who are having issues and need someone to do my assignment. Consult specialists to find a solution to your problem.

    ReplyDelete
  4. This post is very informative. I enjoyed reading it. Keep positing such informative articles.Instant Assignment Help

    ReplyDelete