You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在输入图像上标记数组中代表模糊区域的0值位置

问题解决:在输入图像上标记模糊区域

常见问题原因及修正方案

你的代码未得到预期结果,通常是以下几个问题导致的:

  • 数据类型不匹配:若输入图像是uint8类型(像素值范围0-255),将绿色通道设为1会因颜色过淡无法识别,应改为255;若图像是浮点型(0-1范围),则设为1是合理的,但需确认类型。
  • 尺寸不一致:需确保entropy_image_array与input_image_array的宽高完全相同,否则索引会错位。
  • 未输出结果:修改数组后未通过可视化工具显示或保存图像,导致看不到标记效果。

修正后的填充标记代码

import numpy as np
from skimage import io
import matplotlib.pyplot as plt

# 加载输入图像(替换为你的图像路径)
input_image_array = io.imread("input_image.jpg")
# 假设已得到entropy_image_array(熵图数组)
zero_indices = np.where(entropy_image_array == 0)

# 统一图像数据类型为uint8(适配多数图像格式)
if input_image_array.dtype != np.uint8:
    input_image_array = (input_image_array * 255).astype(np.uint8)

# 将模糊区域的绿色通道设为255(鲜艳绿色,易识别)
input_image_array[zero_indices[0], zero_indices[1], 1] = 255

# 显示标记后的图像
plt.imshow(input_image_array)
plt.axis('off')
plt.show()

# 保存结果
io.imsave("marked_blurry_regions.jpg", input_image_array)

可选:绘制模糊区域轮廓

若不想填充区域,而是标记轮廓,可使用以下代码:

from skimage.measure import find_contours
import matplotlib.patches as patches

fig, ax = plt.subplots()
ax.imshow(input_image_array)

# 提取模糊区域的轮廓
contours = find_contours(entropy_image_array, level=0)
for contour in contours:
    # 绘制红色轮廓线,线宽2
    ax.plot(contour[:, 1], contour[:, 0], linewidth=2, color='red')

ax.axis('off')
plt.show()

内容的提问来源于stack exchange,提问作者Caesar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 23:01:03