python实现ROA算子边缘检测算法


Posted in Python onApril 05, 2021

python实现ROA算子边缘检测算法的具体代码,供大家参考,具体内容如下

代码

import numpy as np
import cv2 as cv


def ROA(image_path, save_path, threshold):
 img = cv.imread(image_path)
 image = cv.cvtColor(img, cv.COLOR_RGB2GRAY)
 new = np.zeros((512, 512), dtype=np.float64) # 开辟存储空间
 width = img.shape[0]
 heigh = img.shape[1]
 for i in range(width):
 for j in range(heigh):
  if i == 0 or j == 0 or i == width - 1 or j == heigh - 1:
  new[i, j] = image[i, j]
  continue
  print(image[i, j])
  if image[i, j] < 60:
  continue
  num_sum = 0.0
  u1 = (image[i - 1, j - 1] + image[i, j - 1] + image[i + 1, j - 1]) / 3
  u2 = (image[i - 1, j + 1] + image[i, j + 1] + image[i + 1, j + 1]) / 3
  r12 = 1.0
  if float(u2) - 0.0 > 1e6:
  r12 = float(u1) / float(u2)
  if float(u1) - 0.0 > 1e6:
  r12 = float(u2) / float(u1)
  num_sum += r12

  u1 = (image[i - 1, j - 1] + image[i, j - 1] + image[i - 1, j]) / 3
  u2 = (image[i + 1, j] + image[i + 1, j + 1] + image[i, j + 1]) / 3
  r12 = 1.0
  if float(u2) - 0.0 > 1e6:
  r12 = float(u1) / float(u2)
  if float(u1) - 0.0 > 1e6:
  r12 = float(u2) / float(u1)
  num_sum += r12

  u1 = (image[i - 1, j - 1] + image[i - 1, j] + image[i - 1, j + 1]) / 3
  u2 = (image[i + 1, j - 1] + image[i + 1, j] + image[i + 1, j + 1]) / 3
  r12 = 1.0
  if float(u2) - 0.0 > 1e6:
  r12 = float(u1) / float(u2)
  if float(u1) - 0.0 > 1e6:
  r12 = float(u2) / float(u1)
  num_sum += r12

  u1 = (image[i - 1, j] + image[i - 1, j + 1] + image[i, j + 1]) / 3
  u2 = (image[i, j - 1] + image[i + 1, j - 1] + image[i + 1, j]) / 3
  r12 = 1.0
  if float(u2) - 0.0 > 1e6:
  r12 = float(u1) / float(u2)
  if float(u1) - 0.0 > 1e6:
  r12 = float(u2) / float(u1)
  num_sum += r12
  new[i, j] = num_sum / 4.0
  if new[i, j] > threshold:
  new[i, j] = 100
  print(new[i, j])

 print(new)

 cv.imwrite(save_path, new)


if __name__ == "__main__":
 image_path = r""
 save_path = r""
 threshold = 
 ROA(image_path, save_path, threshold)

运算结果

运算前

python实现ROA算子边缘检测算法

运算后

python实现ROA算子边缘检测算法

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
haskell实现多线程服务器实例代码
Nov 26 Python
Python内置函数Type()函数一个有趣的用法
Feb 18 Python
python自然语言编码转换模块codecs介绍
Apr 08 Python
python for 循环获取index索引的方法
Feb 01 Python
计算机二级python学习教程(1) 教大家如何学习python
May 16 Python
树莓派采用socket方式文件传输(python)
Jun 22 Python
PyQT5 QTableView显示绑定数据的实例详解
Jun 25 Python
如何使用Python 打印各种三角形
Jun 28 Python
Python+numpy实现矩阵的行列扩展方式
Nov 29 Python
django 读取图片到页面实例
Mar 27 Python
Python绘图之柱形图绘制详解
Jul 28 Python
Django如何实现防止XSS攻击
Oct 13 Python
python实现批量移动文件
Python list去重且保持原顺序不变的方法
Apr 03 #Python
python自动统计zabbix系统监控覆盖率的示例代码
Apr 03 #Python
2021年pycharm的最新安装教程及基本使用图文详解
PyCharm配置KBEngine快速处理代码提示冲突、配置命令问题
python 统计代码耗时的几种方法分享
python 遍历磁盘目录的三种方法
Apr 02 #Python
You might like
星际实力自我测试
2020/03/04 星际争霸
PHP获取栏目的所有子级和孙级栏目的ID号示例
2014/04/01 PHP
PHP简单判断手机设备的方法
2016/08/23 PHP
再谈IE中Flash控件的自动激活 ObjectWrap
2007/03/09 Javascript
Jquery实战_读书笔记1—选择jQuery
2010/01/22 Javascript
js 数组克隆方法 小结
2010/03/20 Javascript
一起来写段JS drag拖动代码
2010/12/09 Javascript
javascript中获取下个月一号,是星期几
2012/06/01 Javascript
使用js解决由border属性引起的div宽度问题
2013/11/26 Javascript
JavaScript中的console.log()函数详细介绍
2014/12/29 Javascript
jQuery实现跨域iframe接口方法调用
2015/03/14 Javascript
JS作为值的函数用法示例
2016/06/20 Javascript
jQuery点击弹出层弹出模态框点击模态框消失代码分享
2017/01/21 Javascript
js转换对象为xml
2017/02/17 Javascript
详解koa2学习中使用 async 、await、promise解决异步的问题
2018/11/13 Javascript
JavaScript实现旋转木马轮播图
2020/03/16 Javascript
微信小程序保持session会话的方法
2020/03/20 Javascript
[04:22]DOTA2上海特级锦标赛主赛事第四日TOP10
2016/03/06 DOTA
python正则表达式re模块详解
2014/06/25 Python
更改Python命令行交互提示符的方法
2015/01/14 Python
python获取指定网页上所有超链接的方法
2015/04/04 Python
Python中exit、return、sys.exit()等使用实例和区别
2015/05/28 Python
python异常和文件处理机制详解
2016/07/19 Python
Win8.1下安装Python3.6提示0x80240017错误的解决方法
2018/07/31 Python
浅谈python写入大量文件的问题
2018/11/09 Python
Python实现的各种常见分布算法示例
2018/12/13 Python
PyQt5实现五子棋游戏(人机对弈)
2020/03/24 Python
PyCharm+Pipenv虚拟环境开发和依赖管理的教程详解
2020/04/16 Python
jupyter notebook 恢复误删单元格或者历史代码的实现
2020/04/17 Python
浅谈tensorflow 中的图片读取和裁剪方式
2020/06/30 Python
如何用Python和JS实现的Web SSH工具
2021/02/23 Python
神话般的珠宝:Ross-Simons
2020/07/13 全球购物
会计出纳员的自我评价
2014/01/15 职场文书
幼儿园老师新年寄语
2015/08/17 职场文书
vue2实现provide inject传递响应式
2021/05/21 Vue.js
Python集合的基础操作
2021/11/01 Python