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

目录

效果不理想

代码: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()
相关推荐
冬奇Lab7 小时前
Workflow 系列(04):Multi-Agent 协调——编排器边界、并发控制与上下文隔离
人工智能·工作流引擎
冬奇Lab7 小时前
每日一个开源项目(第147篇):HyperGraphRAG - 用超图表示 N 元关系,RAG 的第三代范式
人工智能·开源·graphql
甲维斯7 小时前
Github + 阿里云oss实现类似codex的自动更新!
人工智能
阿里云大数据AI技术9 小时前
光轮智能 × 阿里云:共建 Physical AI 云上数据、评测与持续学习基础设施
人工智能·机器学习
机器之心9 小时前
实锤了:Claude Code偷查用户,时区、中国AI实验室全是关键词
人工智能·openai
网易云信9 小时前
Cursor点燃个人开发者,企业级AI为何频频受挫?Agent工厂从提效工具到AI员工的跃迁
人工智能·开源
网易云信9 小时前
解锁触手可及的温暖:网易智企 x Wander Puffs AI 云游泡芙
人工智能
转转技术团队10 小时前
从 PRD 到可验证代码:AI 需求开发闭环实践
人工智能