0

I'm reimplementing SLIC for Image Segmentation just for fun. But I'm lazy and I do not want to write a function to make all cluster connected so I decide to use _enforce_label_connectivity_cython() from skimage but I get an error of Buffer dtype mismatch and I don't now how to solve it

enter image description here.

Karots96
  • 57
  • 6
  • What is `boundaries`? Can you provide a complete code sample? It's important to know what the input array types are. – Juan Apr 24 '20 at 06:21

1 Answers1

0

The data type of np.expand_dims(boundaries, axis=0), that is, the type of the elements inside the array, is not what the Cython function expects. It expects Py_ssize_t which is a type that depends on your platform, but it is getting an array of type long which means np.int64. To get the right type, I think you can do:

labels = _enforce_label_connectivity_cython(
    np.expand_dims(boundaries, axis=0).astype(np.intp),
    min_size,
    max_size,
)

If that doesn't work, try .astype(np.int32). Again, the exact answer depends on your OS and Python version, but if I remember correctly, np.intp should be the correct type to match Py_ssize_t.

Juan
  • 5,433
  • 21
  • 23
  • Thanks `.astype(np.intp)` solve the error. I was focused on min_size & max_size and I have not considered that the error was on by the first parameter – Karots96 Apr 24 '20 at 10:09