0

I have an image for which I have the green border as the segmentation mask's outline. I'm looking to refine this outline based on contours found on the original image, to get a mask like the in 2nd image - where the edges of the hair are more refined.

segmentation mask outline enter image description here

I've tried combinations of dilation & erosion of the segmentation mask, but it didn't feel like a generic solution - since it involves manually tuning the kernel size.

Are there better approaches?

n00b
  • 1,549
  • 2
  • 14
  • 33
  • Did you find a solution to this? So after you obtain the mask from image segmentation (machine learning model) refine the mask? – DanielZanchi Apr 24 '22 at 09:25

1 Answers1

1

There is no generic solution. Parameter tuning is always required to get the desired output. For getting more refined fine edges of the hairs, you can apply thresholding as below:

import cv2 as cv
from matplotlib import pyplot as plt

im = cv2.imread("model.jpg",0)
plt.imshow(im)
thresh = cv2.adaptiveThreshold(im,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
            cv2.THRESH_BINARY_INV,31,3)
plt.imshow(thresh)

input: enter image description here

output: enter image description here

Note: The color changes are due to 'matplotlib'.

SKG
  • 145
  • 1
  • 8