python - 合并图像块并显示图像编号
问题描述
嗨,我已经开始使用许多图像进行图像处理。对于每张图片,我都使用 canny 找到了边缘。每个图像的尺寸相同,为 500x500。现在我必须将这些图像分成块并找到每个块中像素的平均值。然后比较图像的每个块以找到所有图像中的最大值。最后,我想用所有图像中的块生成最终图像,并具有悬停在块上的功能。将鼠标悬停在特定块上的最终图像上时,它应该显示图像编号和该块中信息的强度。我设法找到了边缘,然后我读取了那些边缘检测到的图像,将它们分成块。我想知道如何使用这些具有悬停功能的块构建新图像。
def auto_canny(image, sigma=0.33):
# Compute the median of the single channel pixel intensities
v = np.median(image)
# Apply automatic Canny edge detection using the computed median
lower = int(max(0, (1.0 - sigma) * v))
upper = int(min(255, (1.0 + sigma) * v))
return cv2.Canny(image, lower, upper)
# Read in each image and convert to grayscale
images = [cv2.imread(file,0) for file in glob.glob("images/*.jpg")]
# Iterate through each image, perform edge detection, and save image
number = 0
for image in images:
canny = auto_canny(image)
cv2.imwrite('edges_canny/canny_{}.jpg'.format(number), canny)
number += 1
num = 0
for image_file_name in os.listdir('edges_canny/'):
im = Image.open('edges_canny/'+image_file_name)
new_width = 500
new_height = 500
im = im.resize((new_width, new_height), Image.ANTIALIAS)
im.save('downsize/canny_{}'.format(num) + '.jpg')
num +=1
img = [cv2.imread(file,0) for file in glob.glob("downsize/*.jpg")]
Block=[]
for im in img:
arr = np.asarray(im)
arr = np.split(arr, 50)
arr = np.array([np.split(x, 50, 1) for x in arr])
block= [arr[i][j].median() for i in range(50) for j in range(50)]
Block.append(block)
max_X = list(zip(*Block))
result = [max(i) for i in max_X]
print(result)
现在我被困住了。我可以使用几篇文章中的代码构建这么多。现在有人可以帮我在最终图像上生成带有图像编号的图像。
解决方案
推荐阅读
- sql-server - 如何将sql查询中的行与两个内连接结合起来?
- neo4j - 为空值创建节点
- node.js - 更新到节点 10 后 Firebase 函数错误
- ruby-on-rails - 如何从发现页面中排除当前用户已经关注的用户?
- java - 在存储过程中拥有大部分逻辑时,我应该使用 JDBC 还是 Hibernate?
- apache-spark - 是否可以在开发人员之间共享/访问 hdfs?
- .net - 如何在 Windows 10 上的 Visual Studio 2017 中卸载 .NET Framework 4.8?
- c - libx11 无法在 Fedora OS C 上截屏
- firebase - 云函数中的批量写入或事务?
- laravel - 如何使用 post 方法在 ionViewWillEnter 中显示离子数据?