opencv打卡64: Hilditch 细化算法

编程入门 行业动态 更新时间:2024-10-21 20:38:18

opencv打卡64: Hilditch 细化<a href=https://www.elefans.com/category/jswz/34/1770096.html style=算法"/>

opencv打卡64: Hilditch 细化算法

1、介绍

2、代码

import cv2
import numpy as np
import matplotlib.pyplot as plt# hilditch thining
def hilditch(img):# get shapeH, W, C = img.shape# prepare out imageout = np.zeros((H, W), dtype=np.int)out[img[..., 0] > 0] = 1# inverse pixel valuetmp = out.copy()_tmp = 1 - tmpcount = 1while count > 0:count = 0tmp = out.copy()_tmp = 1 - tmptmp2 = out.copy()_tmp2 = 1 - tmp2# each pixelfor y in range(H):for x in range(W):# skip black pixelif out[y, x] < 1:continuejudge = 0## condition 1if (tmp[y, min(x+1, W-1)] * tmp[max(y-1,0 ), x] * tmp[y, max(x-1, 0)] * tmp[min(y+1, H-1), x]) == 0:judge += 1## condition 2c = 0c += (_tmp[y, min(x+1, W-1)] - _tmp[y, min(x+1, W-1)] * _tmp[max(y-1, 0), min(x+1, W-1)] * _tmp[max(y-1, 0), x])c += (_tmp[max(y-1, 0), x] - _tmp[max(y-1, 0), x] * _tmp[max(y-1, 0), max(x-1, 0)] * _tmp[y, max(x-1, 0)])c += (_tmp[y, max(x-1, 0)] - _tmp[y, max(x-1, 0)] * _tmp[min(y+1, H-1), max(x-1, 0)] * _tmp[min(y+1, H-1), x])c += (_tmp[min(y+1, H-1), x] - _tmp[min(y+1, H-1), x] * _tmp[min(y+1, H-1), min(x+1, W-1)] 

更多推荐

opencv打卡64: Hilditch 细化算法

本文发布于:2024-03-08 18:56:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1721921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   opencv   Hilditch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!