
如何以以下形式獲取影像像素的坐標:
array([[x1 , y1],
[ x2, y2],
...,])
我需要這種特殊形式的它們作為另一個工具(tda-mapper)的輸入。
到目前為止,我已經想到我需要從影像中采樣,但我還沒有設法做到。我真的很感激任何建議!
PS 這只是一個用于測驗的玩具示例。
uj5u.com熱心網友回復:
您可以使用此處提到的解決方案之一將影像讀入 numpy 陣列:將 PNG 檔案匯入 Numpy?
然后您可以使用該numpy.argwhere函式numpy.argwhere(image_array > treshold)回傳灰度值大于某個閾值的索引
import matplotlib.pyplot as plt
import numpy as np
im = plt.imread('3zu5i.png')
#https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140])
grey = rgb2gray(im)
coordinates = np.argwhere(grey < 0.99)
那應該回傳一個包含灰度值大于某個閾值的陣列索引的陣列
array([[ 41, 280],
[ 41, 281],
[ 41, 282],
...,
[372, 299],
[372, 300],
[372, 301]])
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355040.html
