ostu阈值分割python实现_Otsu阈值OpenCV Python

我正在使用图像比率和Otsu阈值法在两个图像之间执行变化检测。

代码的最后一行给出了错误。在import cv2

import numpy as np

image1 = cv2.imread( 'E:\\alada.jpg', 0 )

image2 = cv2.imread( 'E:\\alada2.jpg', 0 )

dest = 'E:\\Ratio\\'

print image1.shape

image1 = cv2.resize( image1, ( 300, 200 ) )

image2 = cv2.resize( image2, ( 300, 200 ) )

img1 = image1.ravel()

img2 = image2.ravel()

sd1 = np.std( img1 )

sd2 = np.std( img2 )

img2 = ( ( img2 - np.mean( img2 ) ) * sd1 / sd2 ) + np.mean( img1 )

ratio = img1 / img2

ratio = np.arctan( ratio ) - np.pi / 4

ratio = np.reshape( ratio, ( image1.shape[0], image1.shape[1] ) )

print ratio.shape

thresh, th2 = cv2.threshold( ratio, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU )

error: ..\..\..\..\opencv\modules\imgproc\src\thresh.cpp:718: error: (-215)

src.type() == CV_8UC1 in function cv::threshold

有什么帮助吗?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值