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 相关文章推荐
python实现连接mongodb的方法
May 08 Python
Python工程师面试题 与Python Web相关
Jan 14 Python
Python编程把二叉树打印成多行代码
Jan 04 Python
Flask框架各种常见装饰器示例
Jul 17 Python
Python3利用print输出带颜色的彩色字体示例代码
Apr 08 Python
在Python中os.fork()产生子进程的例子
Aug 08 Python
pandas中遍历dataframe的每一个元素的实现
Oct 23 Python
python使用ctypes调用扩展模块的实例方法
Jan 28 Python
Anaconda+vscode+pytorch环境搭建过程详解
May 25 Python
Python调用.net动态库实现过程解析
Jun 05 Python
Django配置跨域并开发测试接口
Nov 04 Python
python实现简易自习室座位预约系统
Jun 30 Python
python实现批量移动文件
Python list去重且保持原顺序不变的方法
Apr 03 #Python
python自动统计zabbix系统监控覆盖率的示例代码
Apr 03 #Python
2021年pycharm的最新安装教程及基本使用图文详解
PyCharm配置KBEngine快速处理代码提示冲突、配置命令问题
python 统计代码耗时的几种方法分享
python 遍历磁盘目录的三种方法
Apr 02 #Python
You might like
让PHP支持页面回退的两种方法
2008/01/10 PHP
php时间戳转换的示例
2014/03/31 PHP
PHP动态生成javascript文件的2个例子
2014/04/11 PHP
ThinkPHP关于session的操作方法汇总
2014/07/18 PHP
Yii分页用法实例详解
2014/12/04 PHP
apycom出品的jQuery精美菜单破解方法
2011/02/18 Javascript
当jQuery遭遇CoffeeScript的时候 使用分享
2011/09/17 Javascript
8款非常棒的响应式jQuery 幻灯片插件推荐
2012/02/02 Javascript
Js冒泡事件详解及阻止示例
2014/03/21 Javascript
jquery做的一个简单的屏幕锁定提示框
2014/03/26 Javascript
JavaScript插件化开发教程(五)
2015/02/01 Javascript
理解javascript正则表达式
2016/03/08 Javascript
简单实现js间歇或无缝滚动效果
2016/06/29 Javascript
JavaScript中的事件委托及好处
2016/07/12 Javascript
JS HTML图片显示Canvas 压缩功能
2017/07/21 Javascript
JS自定义对象创建与简单使用方法示例
2020/01/15 Javascript
js+canvas实现图片格式webp/png/jpeg在线转换
2020/08/22 Javascript
Nuxt pages下不同的页面对应layout下的页面布局操作
2020/11/05 Javascript
Python ORM框架SQLAlchemy学习笔记之数据添加和事务回滚介绍
2014/06/10 Python
python判断字符串是否纯数字的方法
2014/11/19 Python
浅谈Python peewee 使用经验
2017/10/20 Python
pygame游戏之旅 载入小车图片、更新窗口
2018/11/20 Python
python 实现UTC时间加减的方法
2018/12/31 Python
Windows下pycharm创建Django 项目(虚拟环境)过程解析
2019/09/16 Python
pygame实现俄罗斯方块游戏(基础篇2)
2019/10/29 Python
Python库skimage绘制二值图像代码实例
2020/04/10 Python
Python中如何引入第三方模块
2020/05/27 Python
python中sys模块是做什么用的
2020/08/16 Python
python批量修改文件名的示例
2020/09/27 Python
使用CSS3制作版头动画效果
2020/12/24 HTML / CSS
Clarks鞋法国官方网站:英国其乐鞋品牌
2018/02/11 全球购物
旅游管理毕业生自荐信
2013/11/05 职场文书
本科毕业生专业自荐书范文
2014/02/05 职场文书
《大江保卫战》教学反思
2014/04/11 职场文书
MySQL 使用事件(Events)完成计划任务
2021/05/24 MySQL
vue的项目如何打包上线
2022/04/13 Vue.js