简体   繁体   English

识别二进制图像中的曲线

[英]Identify curve in binary image

I have a few screenshots from experiments which display curves, and I want to extract that curve into an array to analyze the data. 我有一些显示曲线的实验的屏幕截图,我想将该曲线提取到数组中以分析数据。

The first part of my method is to transform the image into a binary one with a well chosen threshold that only leaves the curve. 我的方法的第一部分是将图像转换为具有精心选择的阈值(仅保留曲线)的二进制图像。 This works fine, but the second part consisting in extracting an array from the curve doesn't. 这可以正常工作,但是第二部分不能从曲线中提取数组。 I tried the "naive" method of going through the picture and identifying the white pixels, but the results are nowhere near what's expected. 我尝试了“天真”的方法来浏览图片并识别白色像素,但结果远不及预期。

Does someone have a solution? 有人有解决方案吗?

屏幕截图示例

import numpy as np
import matplotlib.pyplot as plt
import PIL.Image as img

gray = img.open('0100k.jpg').convert('L')
bw = gray.point(lambda x: 0 if x<240 else 255, '1')
bw = bw.convert('1')
bw.show()
pix = np.array(bw)
(n,m) = pix.shape
curve = np.zeros(n)
for i in range(n):
    for j in range(m):
        if pix[i,j] == 1:
        curve[i] = j
plt.plot(curve)
plt.show()

Thanks guys, the method now works, the solution was in the correct assignation of i and j to their respective dimensions. 谢谢大家,该方法现在可以使用了,解决方案是正确地将i和j分配给它们各自的尺寸。 Thanks to @Matt Cremens for pointing it out. 感谢@Matt Cremens指出来。
But the plot thickens, it detects some non-existing pixels, like the ones visibles in the left side of the picture : http://s31.postimg.org/i0conbbxn/figure_1.png 但是该图变厚了,它检测到一些不存在的像素,例如图片左侧的可见像素: http : //s31.postimg.org/i0conbbxn/figure_1.png

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

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