How can I convert images from scikit-image to opencv2 and other libraries?

I tried to find the path with the python cv2 library in a skeletonized image created using scikit-image, and I got this error:

contours, hierarchy = cv2.findContours(skel,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) TypeError: <unknown> data type = 0 is not supported 

My question is: what do I need to do to convert to cv2 and vice versa?

I know that opencv uses the numpy.uint8 type to represent binary images instead of scikit-image numpy.float64

I also used mahotas (numpy.bool) and pymorph libraries. How can I convert from scikit images to these libraries and vice versa?

+6
source share
1 answer

scikit-image provides conversion procedures between different data types that also preserve scaling correctly:

 from skimage import img_as_ubyte cv_image = img_as_ubyte(any_skimage_image) 

Update: scikit-image user manual now contains a more detailed section: http://scikit-image.org/docs/stable/user_guide/data_types.html#working-with-opencv

+11
source

All Articles