Esempio n. 1
0
 def get_crop(e, center_location, window_size, freqs=[18, 38, 120, 200]):
     """
     Returns a crop of data around the pixels specified in the center_location.
     """
     # Get grid sampled around center_location
     grid = getGrid(window_size) + np.expand_dims(
         np.expand_dims(center_location, 1), 1)
     channels = []
     for f in freqs:
         # Interpolate data onto grid
         memmap = e.data_memmaps(f)[0]
         data = linear_interpolation(memmap,
                                     grid,
                                     boundary_val=0,
                                     out_shape=window_size)
         del memmap
         # Set non-finite values (nan, positive inf, negative inf) to zero
         if np.any(np.invert(np.isfinite(data))):
             data[np.invert(np.isfinite(data))] = 0
         channels.append(np.expand_dims(data, 0))
     channels = np.concatenate(channels, 0)
     labels = nearest_interpolation(e.label_memmap(),
                                    grid,
                                    boundary_val=-100,
                                    out_shape=window_size)
     return channels, labels
Esempio n. 2
0
    def get_sample(self):
        """

        :return: [(int) y-coordinate, (int) x-coordinate], (Echogram) selected echogram
        """
        #Random echogram
        ei = np.random.randint(len(self.echograms))

        #Random x-loc with y-location of seabed
        x = np.random.randint(
            self.window_size[1] // 2,
            self.echograms[ei].shape[1] - (self.window_size[1] // 2))
        y = self.echograms[ei].get_seabed()[x]

        #Check if there is any fish-labels in crop
        grid = getGrid(self.window_size) + np.expand_dims(
            np.expand_dims([y, x], 1), 1)
        labels = nearest_interpolation(self.echograms[ei].label_memmap(),
                                       grid,
                                       boundary_val=0,
                                       out_shape=self.window_size)

        if np.any(labels != 0):
            return self.get_sample()  #Draw new sample

        return [y, x], self.echograms[ei]
Esempio n. 3
0
def get_full(echogram, freqs):
    channels = []
    shape = echogram.shape
    grid = getGrid(shape)
    for f in freqs:
        # Interpolate data onto grid
        memmap = echogram.data_memmaps(f)[0]
        data = linear_interpolation(memmap, grid, boundary_val=0, out_shape=shape)
        # Set non-finite values (nan, positive inf, negative inf) to zero
        if np.any(np.invert(np.isfinite(data))):
            data[np.invert(np.isfinite(data))] = 0

        channels.append(np.expand_dims(data, 0))
    channels = np.concatenate(channels, 0)

    labels = nearest_interpolation(echogram.label_memmap(), grid, boundary_val=-100, out_shape=shape)
    return channels, labels