【发布时间】:2020-09-05 15:57:57
【问题描述】:
我目前正在尝试从特定 PNG 文件中提取数据点的想法。作为参考,PNG 文件如下所示: Picture of PNG
我用来提取数据的当前代码如下所示,我正在使用 Python 图像库来识别图像的点:
def imageProcess(filename) :
#Declaring data object
data = []
#Loading image for modification
with Image.open(filename) as im:
px = im.load()
#Grabbing values
width,height = im.size
print(width , height)
#For loop
for x in range(width) :
for y in range(height) :
#Removes white space from the image
if px[x,y] != (255,255,255,0) :
data.append({"x" : x*5, "y" : y*5,"color" : px [ x , y ]})
print(type(data))
return data
虽然这段代码运行良好,但我正在尝试丢弃代表 PNG 文件中的一行的数据点,我只希望角落是特定的。为了更好地了解我想要什么:
而不是:
{'x': 518, 'y': 741, 'color': (226, 226, 226, 17)}
# All of the data below is a waste, I don't need it
{'x': 518, 'y': 742, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 743, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 744, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 745, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 746, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 747, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 748, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 749, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 750, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 751, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 752, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 753, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 754, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 755, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 756, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 757, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 758, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 759, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 760, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 761, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 762, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 763, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 764, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 765, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 766, 'color': (226, 226, 226, 17)}
# The point below represents the corner
{'x': 518, 'y': 767, 'color': (244, 244, 244, 2)}
我只想要第一个和最后一个值,因为它代表角:
#This is what I want to achieve
{'x': 518, 'y': 741, 'color': (226, 226, 226, 17)}
{'x': 518, 'y': 767, 'color': (244, 244, 244, 2)}
如果需要解决这个问题,我欢迎使用除 PIL 之外的不同 python 库。非常感谢。
编辑:这是一个(抱歉低分辨率)picture 解释我需要获取哪些数据点以及需要丢弃所有数据点。我已经用红点标出了我需要获得的分数。谢谢。
【问题讨论】:
-
也许您可以添加第二张标记图像,用红色或圆圈标识您要查找的点?
-
@MarkSetchell 我正在尝试识别角落,例如i.stack.imgur.com/mfpdz.png。我为低分辨率道歉。我只需要此 PNG 图像中一行的起点和终点。谢谢。
-
您的实际图像有那么差(低分辨率)吗?您能否看到您正在寻找的许多角点实际上并不存在 - 在这些点图像中存在间隙。
标签: python image-processing python-imaging-library png