2017-12-05 13 views
0

내 이미지에 scikit 이미지의 적응 임계 값을 사용하려고합니다. 나는 HERE이미지에 Skimage 적응성 임계 값 사용 및 출력 얻기

import matplotlib.pyplot as plt 

from skimage import data 
from skimage.filters import threshold_otsu, threshold_adaptive 


image = data.page() 

global_thresh = threshold_otsu(image) 
binary_global = image > global_thresh 

block_size = 35 
binary_adaptive = threshold_adaptive(image, block_size, offset=10) 

fig, axes = plt.subplots(nrows=3, figsize=(7, 8)) 
ax0, ax1, ax2 = axes 
plt.gray() 

ax0.imshow(image) 
ax0.set_title('Image') 

ax1.imshow(binary_global) 
ax1.set_title('Global thresholding') 

ax2.imshow(binary_adaptive) 
ax2.set_title('Adaptive thresholding') 

for ax in axes: 
    ax.axis('off') 

plt.show() 

코드는, 샘플 이미지에서 소요를 임계 값과 PLT를 사용하여 보여줍니다에서 자신의 샘플 코드를 테스트했다. 그러나, 나는 thresholded 이미지의 numpy 배열을 검색하려고합니다. 변수 binary_globalcv2.imwrite을 사용하려고 시도했지만 작동하지 않습니다. binary_global을 인쇄 할 때 실제로는 숫자가 아닌 거짓과 참 값으로 구성된 배열입니다. plt가 어떻게 그것을 사용하고 이미지를 만들 수 있는지 잘 모르겠습니다. 그럼에도 불구하고 어떻게 이미지를 임계 값으로 설정하고 RGB 값으로 새 임계 값 이미지의 배열을 검색 할 수 있습니까?

답변

0

cv2.imwrite()을 사용하려면 먼저 scikit 이미지를 opencv로 변환해야합니다.

는이 또한 http://scikit-image.org/docs/dev/user_guide/data_types.html을

from skimage import img_as_ubyte 
import matplotlib.pyplot as plt 
from skimage import data 
from skimage.filters import threshold_otsu, threshold_adaptive 
import cv2 


image = data.page() 

global_thresh = threshold_otsu(image) 
binary_global = image > global_thresh 

block_size = 35 
binary_adaptive = threshold_adaptive(image, block_size, offset=10) 

fig, axes = plt.subplots(nrows=3, figsize=(7, 8)) 
ax0, ax1, ax2 = axes 
plt.gray() 

ax0.imshow(image) 
ax0.set_title('Image') 

ax1.imshow(binary_global) 
ax1.set_title('Global thresholding') 

ax2.imshow(binary_adaptive) 
ax2.set_title('Adaptive thresholding') 

for ax in axes: 
    ax.axis('off') 

plt.show() 
img = img_as_ubyte(binary_global) 
cv2.imshow("image", img) 
cv2.waitKey(0) 

당신은 다음 등

+0

을 작성하기위한 img를 사용할 수있는 변경 사항 - 참조 다음 추가 # working-with-opencv –

+0

이것은 완벽하게 작동했습니다. – Jess