图像拼接 边缘色差, 轮廓平均值修复

目录

效果不理想

代码:lunkuo_mohu.py


效果不理想

代码:lunkuo_mohu.py

python 复制代码
import cv2
import numpy as np

img_mask = cv2.imread(r'F:\project\ronghe\Poisson-Blending-main\mask_new.jpg', 0)
img_path = r'F:\project\ronghe\Poisson-Blending-main\res2.jpg'
image = cv2.imread(img_path)

edges = cv2.Canny(img_mask, threshold1=100, threshold2=200)

if 0:#轮廓膨胀
    kernel = np.ones((5, 5), np.uint8)

    # 向外扩展(膨胀)
    dilated = cv2.dilate(edges, kernel, iterations=2)

    # 向内扩展(腐蚀)
    eroded = cv2.erode(edges, kernel, iterations=2)

    # 合并膨胀和腐蚀后的结果(实现同时向内和向外扩展)
    edges = cv2.bitwise_or(dilated, eroded)
# 获取图像的高度和宽度
height, width = edges.shape

# 创建一个输出图像,初始时与原图像相同
output_image = image.copy()

# 遍历所有边缘像素
for y in range(1, height - 1):
    for x in range(1, width - 1):
        if edges[y, x] != 0:  # 检查是否是边缘像素
            # 获取该像素周围8个邻域像素(3x3邻域内的其他8个像素)
            region = image[y - 1:y + 2, x - 1:x + 2]

            # 计算邻域像素的平均颜色(忽略中心点)
            neighbors = region[region != region[1, 1]]  # 不包括中心点
            avg_color = np.mean(image[neighbors], axis=(0, 1))  # 计算平均颜色

            # 将该边缘像素的颜色设置为平均颜色
            output_image[y, x] = avg_color.astype(np.uint8)

# 显示结果
cv2.imshow('edges', edges)
cv2.imshow('Edges Colored by Neighbors Average', output_image)

cv2.waitKey(0)
cv2.destroyAllWindows()
相关推荐
CareyWYR6 分钟前
每周AI论文速递(251013-251017)
人工智能
后端小肥肠8 分钟前
放弃漫画内卷!育儿赛道才是黑马,用 Coze 智能体做10w+育儿漫画,成品直接发
人工智能·agent·coze
whaosoft-14311 分钟前
51c~Pytorch~合集6
人工智能
后端小张13 分钟前
[AI 学习日记] 深入解析MCP —— 从基础配置到高级应用指南
人工智能·python·ai·开源协议·mcp·智能化转型·通用协议
天青色等烟雨..15 分钟前
AI+Python驱动的无人机生态三维建模与碳储/生物量/LULC估算全流程实战技术
人工智能·python·无人机
渡我白衣19 分钟前
深度学习进阶(七)——智能体的进化:从 LLM 到 AutoGPT 与 OpenDevin
人工智能·深度学习
乌恩大侠36 分钟前
【USRP】AI-RAN Sionna 5G NR 开发者套件
人工智能·5g
孤狼灬笑38 分钟前
机器学习十大经典算法解析与对比
人工智能·算法·机器学习
聚梦小课堂40 分钟前
ComfyUI Blog: ImagenWorld 发布:面向图像生成与编辑的真实世界基准测试数据集
人工智能·深度学习·图像生成·benchmark·imagenworld
星际棋手44 分钟前
【AI】一文说清楚神经网络、机器学习、专家系统
人工智能·神经网络·机器学习