资源简介
python OpenCV将图像进行 二值化(黑白化),然后返回黑白图像。
代码片段和文件信息
import cv2
import numpy as np
import math
import copy
def produceThresholds(crop_img):
crop = copy.deepcopy(crop_img)
thresholds = []
threshold0 = Wolf(crop 3 18 18 0.05 + (0 * 0.35) 128)
threshold0 = cv2.bitwise_not(threshold0)
thresholds.append(threshold0)
threshold1 = Wolf(crop 3 22 22 0.05 + (1 * 0.35) 128)
threshold1 = cv2.bitwise_not(threshold1)
thresholds.append(threshold1)
threshold2 = Wolf(crop 2 12 12 0.18 128)
threshold2 = cv2.bitwise_not(threshold2)
thresholds.append(threshold2)
return thresholds
def calcLocalStats(im map_m map_s winx winy):
rows cols = im.shape
im_sum im_sum_sq = cv2.integral2(im sqdepth=cv2.CV_64F)
wxh = winx / 2
wyh = winy / 2
x_firstth = wxh
y_lastth = rows - wyh - 1
y_firstth = wyh
winarea = float(winx * winy)
max_s = 0
j = y_firstth
for j in range(y_firstth y_lastth + 1):
sum = 0.0
sum_sq = 0.0
sum = im_sum.item(j - wyh + winy winx) - im_sum.item(j - wyh winx) - \
im_sum.item(j - wyh + winy 0) + im_sum.item(j - wyh 0)
sum_sq = im_sum_sq.item(j - wyh + winy winx) - im_sum_sq.item(
j - wyh winx) - im_sum_sq.item(j - wyh + winy 0) + im_sum_sq.item(j - wyh 0)
m = sum / winarea
s = math.sqrt((sum_sq - m * sum) / winarea)
if s > max_s:
max_s = s
map_m.itemset((j x_firstth) m)
map_s.itemset((j x_firstth) s)
maxrange = cols - winx + 1
for i in range(1 maxrange):
sum -= im_sum.item(j - wyh + winy i) - im_sum.item(j - wyh i) - im_sum.item(j - wyh + winy i - 1) \
+ im_sum.item(j - wyh i - 1)
sum += im_sum.item(j - wyh + winy i + winx) - im_sum.item(j - wyh i + winx) - \
im_sum.item(j - wyh + winy i + winx - 1) + \
im_sum.item(j - wyh i + winx - 1)
sum_sq -= im_sum_sq.item(j - wyh + winy i) - im_sum_sq.item(
j - wyh i) - im_sum_sq.item(j - wyh + winy i - 1) + im_sum_sq.item(j - wyh i - 1)
sum_sq += im_sum_sq.item(j - wyh + winy i + winx) - im_sum_sq.item(j - wyh i + winx) - \
im_sum_sq.item(j - wyh + winy i + winx - 1) + \
im_sum_sq.item(j - wyh i + winx - 1)
m = sum / winarea
s = math.sqrt(abs(sum_sq - m * sum) / winarea)
if s > max_s:
max_s = s
map_m.itemset((j i + wxh) m)
map_s.itemset((j i + wxh) s)
return max_s map_m map_s im
def Wolf(image version winx winy k dR):
img = copy.deepcopy(image)
m = 0.0
max_s = 0.0
th = 0
wxh = winx / 2
wyh = winy / 2
x_firstth = wxh
x_lastth = img.shape[1] - wxh - 1
y_lastth = im
- 上一篇:PythonTCP编程
- 下一篇:FaceClustering.zip
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论