import numpy as np

def compute_noise_mask(spectrogram):
    print("noise_mask is undefined")

def compute_structure_mask(spectrogram):
    print("structure_mask is undefined")

def extract_signal(mask, spectrogram):
    print("extract_signal is undefined")

@@ -16,243 +16,2481 @@
  np%0A
-%0Adef compute_noise_mask(spectrogram):%0A    print(%22noise_mask is undefined%22)%0A%0Adef compute_structure_mask(spectrogram):%0A    print(%22structure_mask is undefined%22)%0A%0Adef extract_signal(mask, spectrogram):%0A    print(%22extract_signal is undefined%22)
+import utils%0Afrom skimage import morphology%0A%0Adef compute_noise_mask(spectrogram):%0A    norm_spectrogram = normalize(spectrogram)%0A    binary_structure = mark_cells_times_larger_than_median(norm_spectrogram, 2.5)%0A%0A    n_hood = np.ones((4, 4))%0A    binary_structure = morphology.binary_erosion(binary_structure, n_hood)%0A    binary_structure = morphology.binary_dilation(binary_structure, n_hood)%0A%0A    utils.plot_matrix(binary_structure)%0A%0A    indicator_vector = np.array(%5Bset_one_if_column_contains_one(col) for col in np.transpose(binary_structure)%5D)%0A    indicator_vector = smooth_indicator_vector(indicator_vector)%0A%0A    # flip 0s with 1s and vice versa%0A    return 1-indicator_vector%0A%0Adef compute_structure_mask(spectrogram):%0A    norm_spectrogram = normalize(spectrogram)%0A    binary_structure = mark_cells_times_larger_than_median(norm_spectrogram, 3)%0A%0A    n_hood = np.ones((4, 4))%0A    binary_structure = morphology.binary_dilation(binary_structure, n_hood)%0A%0A    # plot it%0A    utils.plot_matrix(binary_structure)%0A%0A    binary_structure = morphology.binary_erosion(binary_structure, n_hood)%0A%0A    # plot it%0A    #utils.plot_matrix(binary_structure)%0A%0A    indicator_vector = np.array(%5Bset_one_if_column_contains_one(col) for col in np.transpose(binary_structure)%5D)%0A    indicator_vector = smooth_indicator_vector(indicator_vector)%0A%0A    return indicator_vector%0A%0Adef smooth_indicator_vector(indicator_vector):%0A    n_hood = np.ones(4)%0A    indicator_vector = morphology.binary_dilation(indicator_vector, n_hood)%0A    indicator_vector = morphology.binary_dilation(indicator_vector, n_hood)%0A%0A    # type casting is a bitch%0A    return 1*indicator_vector%0A%0Adef set_one_if_column_contains_one(col):%0A    nb_ones = np.count_nonzero(col)%0A    if nb_ones %3E 0:%0A        return int(1)%0A    else:%0A        return int(0)%0A%0Adef mark_cells_times_larger_than_median(spectrogram, number_times_larger):%0A    row_medians = np.median(spectrogram, axis=1)%0A    col_medians = np.median(spectrogram, axis=0)%0A    for row in range(spectrogram.shape%5B0%5D):%0A        for col in range(spectrogram.shape%5B1%5D):%0A            if spectrogram%5Brow%5D%5Bcol%5D %3E 3*row_medians%5Brow%5D %5C%0A               and spectrogram%5Brow%5D%5Bcol%5D %3E 3*col_medians%5Bcol%5D:%0A                spectrogram%5Brow%5D%5Bcol%5D = 1%0A            else:%0A                spectrogram%5Brow%5D%5Bcol%5D = 0%0A%0A    return spectrogram%0A%0A%0Adef extract_signal(mask, spectrogram):%0A    print(%22extract_signal is undefined%22)%0A%0A%0Adef normalize(X):%0A    mi = np.min(X)%0A    ma = np.max(X)%0A%0A    X = (X-mi)/(ma-mi)%0A    return X
 %0A

Add methods for signal/noise mask computations.