I have the following code:
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from skimage import data
from skimage import filter
from skimage.filter import threshold_otsu
matplotlib.rcParams['font.size'] = 9
nomeimg = 'frame1_depth.png'
i = cv2.imread(nomeimg, -1)
#conversione da 16 a 32 uint
img = np.array(i, dtype=np.uint32)
img *= 65536
print img.dtype
#thresholding con il metodo Otsu
thresh = threshold_otsu(img)
binary = img > thresh
print thresh
plt.figure(1)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
ax1.imshow(img)
ax1.set_title('Original')
ax1.axis('off')
ax2.hist(img)
ax2.set_title('Histogram')
ax2.axvline(x=thresh, color='r', linestyle='dashed', linewidth=2)
ax3.imshow(binary, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')
plt.figure(2)
f, ax = plt.subplots(figsize=(8, 2.5))
ax.imshow(binary, cmap=plt.cm.gray)
ax.set_title('Thresholded')
ax.axis('off')
plt.show()
I have a set of depth images from the XBOX kinect, and so after a data type conversion so that I can use some opencv
functions which work only with 8 or 32 bit images, I've thresholded the image with the Otsu algorithm and showed the results.
I have obtained a subplot in which I have my original image, the histogram and the thresholded black and white image. Now I want to work only on this black and white image and I want to save it and compute contours, the convex hull and others geometrical features. However, it's just thresholded, but with otsu
.
How can I compute this?