【问题标题】:Finding coordinates of brightest pixel in an image and entering them into an array查找图像中最亮像素的坐标并将它们输入到数组中
【发布时间】:2011-11-08 20:17:30
【问题描述】:

我被要求编写一个程序来查找图像中的“星星”,方法是将图像文件转换为 numpy 数组并生成图像中高于指定阈值的最亮像素的坐标数组(表示背景干扰)。 一旦我找到了图像中最亮的像素,我必须记录它的 x,y 坐标,并将该像素和周围 10X10 像素区域的值设置为零,从而有效地从图像中移除星星。 我已经有一个将图像转换为数组的帮助代码,并试图解决以下问题;

我已经定义了一个变量

    Max = array.max()

并使用了一个while循环;

    while Max >= threshold
        coordinates = numpy.where(array == Max) # find the maximum value

但是我希望它循环遍历整个数组的所有坐标,而不仅仅是找到第一个最大值,并且在找到时删除每个最大值并将周围的 10X10 区域设置为零。我曾考虑过使用 for 循环来执行此操作,但由于我是 Python 新手,我不确定应该如何使用它。

如果有任何建议,我将不胜感激, 谢谢

【问题讨论】:

标签: python numpy


【解决方案1】:

仅使用 numpy 等有多种不同的方法。

有“蛮力”方式:

import Image
import numpy as np

im = Image.open('test.bmp')
data = np.array(im)
threshold = 200
window = 5 # This is the "half" window...
ni, nj = data.shape 
new_value = 0

for i, j in zip(*np.where(data > threshold)):
    istart, istop = max(0, i-window), min(ni, i+window+1)
    jstart, jstop = max(0, j-window), min(nj, j+window+1)
    data[istart:istop, jstart:jstop] = new_value

或者更快的方法...

import Image
import numpy as np
import scipy.ndimage

im = Image.open('test.bmp')
data = np.array(im)
threshold = 200
window = 10 # This is the "full" window...
new_value = 0

mask = data > threshold
mask = scipy.ndimage.uniform_filter(mask.astype(np.float), size=window)
mask = mask > 0
data[mask] = new_value

【讨论】:

    【解决方案2】:

    Astronomy.net 会为你做这件事:

    如果您使用天体坐标对天空进行天文成像 您不知道或不信任,那么 Astrometry.net 适合您。输入 一张图片,我们会给你回天体测量校准元数据, 加上视野范围内的已知物体列表。

    我们已经建立了这个天体测量校准服务来创建正确的、 每个有用的符合标准的天体测量元数据 过去和未来,在任何状态下拍摄的天文图像 档案混乱。我们希望这将有助于组织、注释和制作 可搜索世界上所有的天文信息。

    您甚至不必将图片上传到他们的网站。您可以下载source。它在 GPL 下获得许可并使用 NumPy,因此您可以根据需要随意使用它。

    请注意,您需要先将位图转换为以下格式之一:JPEG、GIF、PNG 或 FITS 图像。

    【讨论】:

    • 很抱歉破坏了您的 9,001 名代表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    相关资源
    最近更新 更多