[Python] Get coordinates of local maxima in 2D array above certain value

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    from PIL import Image
    import numpy as np
    from scipy.ndimage.filters import maximum_filter
    import pylab

    # the picture (256 * 256 pixels) contains bright spots of which I wanna get positions
    # problem: data has high background around value 900 - 1000

    im = Image.open('slice0000.png')
    data = np.array(im)

    # as far as I understand, data == maximum_filter gives True-value for pixels
    # being the brightest in their neighborhood (here 10 * 10 pixels)

    maxima = (data == maximum_filter(data,10))
    # How can I get only maxima, outstanding the background a certain value, let's say 500 ?


    I'm afraid I don't really understand the scipy.ndimage.filters.maximum_filter() function. Is there a way to obtain pixel-coordinates only within the spots and not within the background?

    https://i.sstatic.net/RImHW.png (16-bit grayscale picture, 256*256 pixels)

    Continue reading...

Compartilhe esta Página