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

目录

效果不理想

代码: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()
相关推荐
7177777 小时前
国内 AI 研发效能工具怎么选:2026 年基于公开信息的选型框架与 Gitee 实践
人工智能·gitee
Csvn7 小时前
换供应商要改一遍代码?把模型接入收进一层网关(C04)
人工智能·aigc·agent
孟健8 小时前
开源AutoClip切直播:1小时48分出19段,整月API只花0.08元
人工智能·开源·aigc
翰墨之道8 小时前
AI日报:豆包工作ARR超20亿,GPT-6.2跑分与实测割裂
人工智能·gpt·数据挖掘
Maynor9969 小时前
Trymodel 使用介绍:一个平台同时用 Claude、GPT、Gemini 和 Grok
人工智能·gpt·ai·程序员·教程·claude·语音
字节跳动视频云技术团队9 小时前
接大模型别再自己配 Key、搭代理了,火山引擎 IGA Pages 一步搞定
人工智能
阿里云大数据AI技术10 小时前
EMR Serverless StarRocks 产品介绍:从统一 OLAP 走向多模态分析与检索
人工智能
Forget the Dream11 小时前
Spring AI 2.0 系列(二):第一个 ChatClient——从注入到一次完整调用
java·人工智能·spring boot·ai·springai
郝学胜-神的一滴11 小时前
Effective Python 条款35:用类封装替代生成器异常注入
开发语言·人工智能·python·金融·pandas·scikit-learn·matplotlib
火山引擎开发者社区11 小时前
豆包工作,3 个月,800 万,20 亿
人工智能