how to change back the labeled image to a form that cv2 can read

Viewed 33

I have an image which is originally imported by cv2 as showed below:

img= cv2.imread("...\\vJSEM400xSD_69.tif",0)
median=cv2.medianBlur(img,13)
ret, th = cv2.threshold(median, 0 , 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
kernel=np.ones((3,15),np.uint8)
closing1 = cv2.morphologyEx(th, cv2.MORPH_CLOSE, kernel, iterations=2)
kernel=np.ones((1,31),np.uint8)
closing2 = cv2.morphologyEx(closing1, cv2.MORPH_CLOSE, kernel)
  
kernel=np.ones((1,13),np.uint8)
opening1= cv2.morphologyEx(closing2, cv2.MORPH_OPEN, kernel,  iterations=2)
 
label_image=measure.label(opening1, connectivity=opening1.ndim)

now I selected the 2 top big area of the labeled image

slc=label_image
rps=regionprops(slc)
areas=[r.area for r in rps]
id=np.argsort(props["area"])[::-1]
new_slc=np.zeros_like(slc)
for i in id[:2]:
    new_slc[tuple(rps[i].coords.T)]=i+1

the result looks like this

enter image description here

Now I am wondering how I can change the result image (new_slc) back to a formate that cv2 can read?

right now, when I use this command:

cv2.imshow("slc", new_slc)
cv2.waitKey()

it gives me this error:

error: OpenCV(4.6.0) D:/a/opencv-python/opencv-python/opencv/modules/highgui/src/precomp.hpp:155: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
0 Answers
Related