Contour extension in OpenCv

I have several outlines that consist of several black areas in my image. Directly adjacent to these black regions are some brighter areas that do not belong to my contours. I want to add these bright areas to my black region and therefore expand my outline in OpenCv.
Is there a convenient way to expand the contour? I thought about looking at the change in intensity from my gradient image created with cv::Sobel and stretching until the gradient changes again, which means that the pixel intensity returns to neither black nor bright areas Images.

Thanks!

Here are sample images. The first image shows the raw image, the second shows the extracted outline using Canny and findContours, the last shows the Sobel-Gradient intensity image of the same area. I want to include bright borders in the first image in the outline.

enter image description hereenter image description hereenter image description here

Update: now I used some morphological operations on Sobelgradients and added a contour around them (see image below). The next step may be to find an adjacent pair of purple and red outlines, but it looks like a waste of procession time to actually look for straight adjacent outlines. Any better ideas?

enter image description here

Update 2: My solution for now is to look for the morphed (red) gradient outlines in the bounding box around my (purple) outlines and choose the one that has the correct orientation and size. This works for gradient contours, where the morphological operation closes the gradient areas of β€œrise” and β€œfall”, as in Figure 3. But this is still a poor solution for cases where the illuminated area is wider than in the image above. Any idea is still very much appreciated, thanks!

+4
source share
1 answer

What you are trying to do is find two different functions and combine them. It is not difficult, but you need to use several copies of the image for this to happen.

  • Make one copy and set it for the dark part
  • Make another copy and install it for the easy part
  • Merge both generated images into a new image
  • Apply a morphological operation, such as opening or closing (depending on how you set the threshold). This will connect the nearest components.
  • Find the contours in the resulting image
  • Use these outlines in the original image. This will work as all images are the same size and everything is based on the original.
+3
source

Source: https://habr.com/ru/post/1444306/


All Articles