Home > database >  Convert Coordinates to a Binary Mask [python]
Convert Coordinates to a Binary Mask [python]

Time:01-31

I am trying to convert image annotations given in a json file to a proper binary mask for further analysis.

I was trying to utilize CV2's polygon features. However, it was not able to obtain it.

Is there a simple way to get a binary mask? - using either simple numpy of scikitimage

consider this simple example:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(1)

x = np.random.uniform(0, 100, 4)
y = np.random.uniform(0, 100, 4)

plt.scatter(x, y)
plt.fill(x, y)

when plotting with plt.fill it is able to create a proper polygon. What I essentially want is to have the results of plt.fill as a full numpy array of size roughly - 35, 75 containing only 0 and 1.

CodePudding user response:

You can use plot result

Do note that this is a slightly pathological case because part of the polygon is so thin that it results in a discontinuous object.

  •  Tags:  
  • Related