maad.util.crop_image

maad.util.crop_image(im, tn, fn, fcrop=None, tcrop=None)[source]

Crop a spectrogram (or an image) in time (horizontal X axis) and frequency (vertical y axis)

Parameters:
im2d ndarray

image to be cropped

tn, fn1d ndarray

tn is the time vector. fn is the frequency vector. They are required in order to know the correspondance between pixels and (time,frequency)

fcrop, tcroplist of 2 scalars [min, max], optional, default is None

fcrop corresponds to the min and max boundary frequency values tcrop corresponds to the min and max boundary time values

Returns:
im2d ndarray

image cropped

tn, fn, 1d ndarray

new time and frequency vectors

Examples

>>> w, fs = maad.sound.load('../data/cold_forest_daylight.wav') 
>>> Sxx_power,tn,fn,_ = maad.sound.spectrogram(w,fs)
>>> Lxx = maad.spl.power2dBSPL(Sxx_power, gain=42) # convert into dB SPL
>>> fig_kwargs = {'vmax': Lxx.max(),
                'vmin':0,
                'extent':(tn[0], tn[-1], fn[0], fn[-1]),
                'title':'Power spectrogram density (PSD)',
                'xlabel':'Time [s]',
                'ylabel':'Frequency [Hz]',
                }
>>> fig, ax = maad.util.plot2d(Lxx,**fig_kwargs)      
>>> Lxx_crop, tn_crop, fn_crop = maad.util.crop_image(Lxx, tn, fn, fcrop=(2000,10000), tcrop=(0,30))
>>> fig_kwargs = {'vmax': Lxx.max(),
                'vmin':0,
                'extent':(tn_crop[0], tn_crop[-1], fn_crop[0], fn_crop[-1]),
                'title':'Crop of the power spectrogram density (PSD)',
                'xlabel':'Time [s]',
                'ylabel':'Frequency [Hz]',
                }
>>> fig, ax = maad.util.plot2d(Lxx_crop,**fig_kwargs)