Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:22:45+00:00 2026-06-14T21:22:45+00:00

I am trying to perform image erosion with OpenCV. I want to do it

  • 0

I am trying to perform image erosion with OpenCV. I want to do it like this: Suppose I have four different elements

S1 = [ 0 1 0, 0 1 0, 0 1 0 ]
S2 = [ 0 0 0, 1 1 1, 0 0 0 ]
S3 = [ 0 0 1, 0 1 0, 1 0 0 ]
S4 = [ 0 1 0, 1 1 1, 0 1 0 ]

And I want to perform four different erosions with these elements on original image:

E1 = I & S1 
E2 = I & S2 
E3 = I & S3
E4 = I & S4

where “I” is the original image, and I used “&” to denote erosion for simplicity. Then I want to obtain the final erosion with the addition of these four:

E = E1 + E2 + E3 + E4

But when implementing these with opencv, I’ve encountered difficulties in early stages. I declared the elements like this:

int S1[3][3] = { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 } };
int S2[3][3] = { { 0, 0, 0 }, { 1, 1, 1 }, { 0, 0, 0 } };
int S3[3][3] = { { 0, 0, 1 }, { 0, 1, 0 }, { 1, 0, 0 } }; 
int S4[3][3] = { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 1, 0 } };

Then for using “cv::erode” I have difficulties with these elements since they are not the acceptable type. How can I use these elements to obtain my desired erosion mentioned above? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:22:47+00:00Added an answer on June 14, 2026 at 9:22 pm

    You’ll probably need to create a cv::Mat from your desired kernel shapes, these are known as Structuring elements, and OpenCV provides the getStructuringElement function to create a few common shapes.

    Alternatively, you can form your own by creating a new matrix from your data directly using something like:

    cv::Mat S1 = (cv::Mat_<uchar>(3,3) << 0, 1, 0, 0, 1, 0, 0, 1, 0);
    

    You can confirm whether this is correct by displaying it in the terminal:

    std::cout << S1 << std::endl;
    

    Once you’ve found your matrices, they can also be easily combined by simple arithmetic operations such as:

    cv::Mat E = E1 + E2 + E3 + E4;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to perform a skew on an image, like one shown here (source:
I'm trying to perform a DISTINCT clause on a query like this SELECT DISTINCT
I am trying to perform an erosion of a JPEG image after converting the
I'm trying to perform an RGB Color mixing operation in opencv. I have the
I am trying to perform a dilation on my image and want to use
I am trying to perform facial recogntion using opencv. For this the training and
I am trying to perform a JNDI-lookup from within the GWT devmode. I have
I'm trying to perform a simple animation using Cocoa. One button causes an image
I'm trying to get some code that will perform a perspective transformation (in this
I'm trying to look for shapes in an image using OpenCV. I know the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.