Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I tried to find contour with cv2 python library in a skeletonized image created with 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 i have to do to convert to cv2 and viceversa?

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

I used also mahotas (numpy.bool) and pymorph libraries. How can i convert from scikit-image to these libraries and viceversa?

like image 287
improc Avatar asked Apr 22 '13 21:04

improc


People also ask

Is scikit-image and Skimage same?

scikit-image (a.k.a. skimage ) is a collection of algorithms for image processing and computer vision.

How do I convert an image to grayscale in Skimage?

colour images can be transformed to grayscale using skimage. color. rgb2gray() or be read as grayscale directly by passing the argument as_gray=True to skimage. io.

What is scikit-image used for?

scikit-image (formerly scikits. image) is an open-source image processing library for the Python programming language. It includes algorithms for segmentation, geometric transformations, color space manipulation, analysis, filtering, morphology, feature detection, and more.


1 Answers

scikit-image provides conversion routines between the different data-types that also correctly preserves scaling:

from skimage import img_as_ubyte

cv_image = img_as_ubyte(any_skimage_image)

Update: the scikit-image user guide now has a more detailed section on this: http://scikit-image.org/docs/stable/user_guide/data_types.html#working-with-opencv

like image 195
Stefan van der Walt Avatar answered Oct 24 '22 15:10

Stefan van der Walt