[Python] How can I seperate the fringes that have been calculated with findpeaks

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to seperate the fringes (the red curved lines) that I have calculated with scipy findpeaks how can I achive it. I would like to seperate them and store in the text file.

    [​IMG]

    import numpy as np
    from scipy.signal import find_peaks
    import matplotlib.pyplot as plt


    X = np.load('X.npy')
    Y = np.load('Y.npy')
    P_new = np.load('P_new.npy')

    # Example data: Replace with your actual data
    T = np.real(P_new) # Simulating a 2D matrix

    # Plot the original image
    plt.figure()
    plt.imshow(T, cmap='jet', aspect='auto')
    plt.colorbar()
    plt.title('Original Image')
    plt.show()

    # Peak detection parameters
    min_peak_dist = 3 # Minimum distance between peaks
    min_peak_h = 3e-5 # Minimum peak height

    x_coords = []
    y_coords = []

    # Process all rows from top to bottom
    for k in range(T.shape[0]):
    tex = T[k, :]
    peaks, _ = find_peaks(tex, distance=min_peak_dist, height=min_peak_h)

    if peaks.size > 0:
    x_coords.extend(X[k, peaks])
    y_coords.extend(Y[k, peaks])

    # Plot detected peaks
    plt.figure()
    plt.scatter(x_coords, y_coords, color='r', s=2) # 's' controls marker size
    plt.xlabel('X Coordinate')
    plt.ylabel('Y Coordinate')
    plt.title('Detected Fringes in Real-World Coordinates')
    plt.colorbar()
    plt.show()


    data for plotting is here

    Want I want see is just seperate fringes like here: [​IMG]

    previously I could do it with cv2 method contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) but this is from finding the edges which is not very rigorous for my case as with finding peaks of the actual data.

    Can someone help with this? Thanks

    Continue reading...

Compartilhe esta Página