资源简介
python3写的,亲测可用,欢迎下载
代码片段和文件信息
1import numpy as np
import cv2
from matplotlib import pyplot as plt
#设定阈值
def thresholded(center pixels):
out = []
for a in pixels:
if a >= center:
out.append(1)
else:
out.append(0)
return out
def get_pixel_else_0(l idx idy default=0):
try:
return l[idxidy]
except IndexError:
return default
img = cv2.imread(‘C:/Users/qgl/Desktop/test1.jpg‘ 0)
transformed_img = cv2.imread(‘C:/Users/qgl/Desktop/test1.jpg‘ 0)
for x in range(0 len(img)):
for y in range(0 len(img[0])):
center = img[xy]
top_left = get_pixel_else_0(img x-1 y-1)
top_up = get_pixel_else_0(img x y-1)
top_right = get_pixel_else_0(img x+1 y-1)
right = get_pixel_else_0(img x+1 y )
left = get_pixel_else_0(img x-1 y )
bottom_left = get_pixel_else
- 上一篇:python小项目--外星人入侵
- 下一篇:必应壁纸天天换python小程序.zip
评论
共有 条评论