繁体   English   中英

用圆圈标记图像中的选定像素

[英]Mark selected pixels in an image with circle

我有一张图像,我必须用圆圈标记强度值小于阈值的像素。 你是怎么做到的,Scatter plot 不起作用,因为我们需要两个输入。 感谢您提供这方面的帮助。

matrix = np.matrix([row1,row2,row3,row4,row5,row6,row7,row8,row9,row10,row11,row12])
matrix_s = matrix<=1 # array containing pixels with value less than threshold
#plotting
plt.imshow(matrix)
plt.colorbar()
plt.plot(matrix_s, marker='o') # this won't work as it will join points with line and is not properly scaled with image 
plt.show()

您可以使用 matplotlib 中的Circle补丁 function(请参阅此处的文档)。

这是一个受您提供的代码启发的示例:

import numpy as np
import matplotlib.pyplot as plt

matrix = np.random.choice(80,size=(10,10))/20

fig,ax=plt.subplots()
im=ax.imshow(matrix,aspect='equal',interpolation=None,origin='lower')
for i in range(matrix.shape[0]):
  for j in range(matrix.shape[1]):
    if matrix[i,j]<=1:
      ax.add_patch(plt.Circle([j,i], radius=0.5, edgecolor='r',lw=3, fill=False))
cbar=plt.colorbar(im)

output 给出:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM