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

目录

效果不理想

代码: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()
相关推荐
可乐奶茶sky1 分钟前
AI Agent 学习
人工智能·学习
TsingtaoAI1 分钟前
3D高斯泼溅技术发展及其在具身智能领域的应用综述
人工智能·算法·ai·具身智能·高斯泼溅
神奇小汤圆9 分钟前
面试官:Agent意图识别怎么做?95%的人一句话就把自己送走了
人工智能
兜客互动25 分钟前
2026年AI关键词拓展挖掘软件,高效助力内容创作精准获流
人工智能·python
AI的探索之旅29 分钟前
AI辅助原理图评审:电源去耦、BOOT引脚、VCAP——19项逐一核查,遗漏?不存在的
人工智能·vscode·嵌入式硬件
武子康36 分钟前
Kimi K3 2.8T:开放权重不等于本地可跑 超稀疏 MoE、百万上下文与真实部署边界
人工智能
老刘说AI1 小时前
AI服务核心: 高并发原理与性能监控调优
人工智能·神经网络·langchain·llama·持续部署
GeekArch1 小时前
第24讲:Vibe模式代码风格控制——适配Keil/STM32工程规范
人工智能·stm32·单片机·嵌入式硬件·mcu·决策树·ai编程
二川bro1 小时前
从提示工程→Loop循环→Graph图架构,2026AI开发者终极演进路线
人工智能