1

I am facing an exciting task, and I am stuck. So I have images that contain high and low-intensity objects that have to be separated from the background. I provided an example image below so you can have some idea.

Example image

Most of the segmentation methods I have seen in OpenCV start with a thresholding step like Otsu's Thresholding. However, this is not applicable in my case because it would filter out all the low-intensity objects. Is there any obvious way to tackle this kind of problem?

We can assume that an object never touches the image boundary, and it will always have high contrast with the background and have colours close to black and white.

Pixels in an object have very similar colour but they are not identical.

qake4
  • 11
  • 2

1 Answers1

0

If the object is black and you know it's value won't be greater than, say, 5(on 0..255 scale), you may use this value as a threshold

black_obj_mask = image < 5

Same to the white object. If white objects pixel values are always greater then 250, you may use it

white_obj_mask = image > 250 

Edited If all the pixels of an object are the same color, you can use something like this. The code sample is from here

import numpy as np
from scipy import stats

a = np.array([[1, 3, 4, 2, 2, 7],
              [5, 2, 2, 1, 4, 1],
              [3, 3, 2, 2, 1, 1]])

m = stats.mode(a.flatten())[0]
mask = a==m

bottledmind
  • 603
  • 3
  • 10
  • I get the idea, but in my dataset, those values might rather be 20 and 230. However, such a filter would also mark some dark areas behind the apple as an object. – qake4 Jan 10 '22 at 15:52
  • @qake4 I've edited the answer. Hope it is helpful – bottledmind Jan 10 '22 at 16:22
  • Yes, so it might seem from my mock example that the all the pixels in an object is the same colour it is not the case with my real dataset. In fact, I would say all the pixels in an object has very similar colour but not exactly the same. Sorry, I will update my question accordingly. – qake4 Jan 10 '22 at 18:17