def SubsetSpectrum(parameters, subset_input): #-------------------------------------------------------------------------------------- # function that process a given subset image estimate the wave incident direction # and compute the wave spectrum #-------------------------------------------------------------------------------------- #-------------------------- # A) Subset Processing #-------------------------- # scale sub-images IP_Parameters = parameters.SubsetProcessingParameters image = IP.ScaleImage(subset_input.image, IP_Parameters.IntensityType) subset = CL.Subset(subset_input.CenterPoint, image, subset_input.coordinates, subset_input.resolution, subset_input.FlagFlip) #stretch contrast if IP_Parameters.ConstrastStretchFlag: image = IP.ContrastStretch(image, IP_Parameters.IntensityType) subset = CL.Subset(subset.CenterPoint, image, subset.coordinates, subset.resolution, subset.FlagFlip) #-------------------------- # B) Subset Spectrum #-------------------------- Image_Spectrum = ImageSpectrum(IP_Parameters, subset) #-------------------------- # C) Direction Estimate #-------------------------- DE_Parameters = parameters.DirectionEstimateParameters direction = DirectionEstimate(DE_Parameters, subset, Image_Spectrum) #-------------------------------------- # D) Apply Butterworth Elliptic Filter #------------------------------------- IF_Parameters = parameters.FilterParameters if IF_Parameters.FlagFilter: FilteredImage = ImageFilter(IF_Parameters, subset, direction) image = IP.ScaleImage(FilteredImage, 32) subset = CL.Subset(subset.CenterPoint, image, subset.coordinates, subset.resolution, subset.FlagFlip) Image_Spectrum = ImageSpectrum(IP_Parameters, subset) #--------------------------- # C1) Direction re-estimate #--------------------------- DE_Parameters = parameters.DirectionEstimateParameters direction = DirectionEstimate(DE_Parameters, subset, Image_Spectrum) #--------------------------------------------- # E) Extract Wave Series and Compute Spectrum #--------------------------------------------- SP_Parameters = parameters.SpectrumParameters.WaveSpectrumParameters K, Ks, S, Sp, Sstd = WavesMeanSpectrum(SP_Parameters, subset, direction) #--------------------------------------------- # F) Store data #--------------------------------------------- Spectrum = CL.SpectrumData(Ks, Sp) subset_output = subset Spectrum_Computed_Data = CL.SpectrumComputedData(direction, Spectrum, Image_Spectrum, subset_output) return Spectrum_Computed_Data
def RadialSpectrum(parameters, subset_input): #-------------------------- # A) Subset Processing #-------------------------- # scale sub-images IP_Parameters = parameters.SubsetProcessingParameters image = IP.ScaleImage(subset_input.image, IP_Parameters.IntensityType) subset = CL.Subset(subset_input.CenterPoint, image, subset_input.coordinates, subset_input.resolution, subset_input.FlagFlip) #stretch contrast if IP_Parameters.ConstrastStretchFlag > 0: image = IP.ContrastStretch(image, IP_Parameters.IntensityType) subset = CL.Subset(subset.CenterPoint, image, subset.coordinates, subset.resolution, subset.FlagFlip) #-------------------------- # B) Subset Spectrum #-------------------------- Image_Spectrum = ImageSpectrum(IP_Parameters, subset) #-------------------------- # C) Direction Estimate #-------------------------- # determine radius of influence R, _, _ = Influence_Radius(Image_Spectrum) DE_Parameters = parameters.DirectionEstimateParameters direction = DirectionEstimate(DE_Parameters, subset, Image_Spectrum) #-------------------------------------- # D) Apply Butterworth Elliptic Filter #------------------------------------- IF_Parameters = parameters.FilterParameters DE_Parameters = parameters.DirectionEstimateParameters if IF_Parameters.FlagFilter: FilteredImage = ImageFilter(IF_Parameters, subset, direction) image = IP.ScaleImage(FilteredImage, 32) subset = CL.Subset(subset.CenterPoint, image, subset.coordinates, subset.resolution, subset.FlagFlip) #------------------------------ # E) Perform Image Padding #------------------------------ RI_Parameters = parameters.SpectrumParameters.WaveSpectrumParameters #--------------------------------------------------- # F) Re-Compute Image Spectrum and wave direction #---------------------------------------------------- Image_Spectrum = ImageSpectrum(IP_Parameters, subset) direction = DirectionEstimate(DE_Parameters, subset, Image_Spectrum) #------------------------------------------------ # G) Process Spectrum #------------------------------------------------ Spectrum = Image_Spectrum.Spectrum k = Image_Spectrum.k mask = MaskPlot(R, subset) Spectrum[mask] = 0 #--------------------------------------------- # H) Compute radial integration and #--------------------------------------------- Rr, RadialIntegration = RadialProjection(Spectrum) #--------------------------------------------- # I) Evaluate k-axis in agreement with Radius #--------------------------------------------- dk = np.sum(np.diff(k)) / (k.shape[0] - 1) kr = Rr * dk """ fig, ax = plt.subplots(1) ax.plot(kr, RadialIntegration) ax.plot(kr, RadialIntegration,'or') plt.show() """ #--------------------------------------------- # I) store data #--------------------------------------------- Spectrum = CL.SpectrumData(kr, RadialIntegration) subset_output = subset Spectrum_Computed_Data = CL.SpectrumComputedData(direction, Spectrum, Image_Spectrum, subset_output) return Spectrum_Computed_Data
def ComputeSpectrum(SubsetParameters, ComputingParameters, Subsets): #-------------------------------------------------------------------------- # Estimate Subsets Spectra and directions and determine their mean values #-------------------------------------------------------------------------- WaveSpectra, Directions, ImageSpectra = [], [], [] for i in range(SubsetParameters.BoxNb): subset = Subsets[i] # Compute wave related spectrum if ComputingParameters.SpectrumParameters.WaveSpectrumParameters.SpectrumType in { 'waves', 'Waves' }: # use a multiple of wave signal SpectrumComputedData = SubsetSpectrum(ComputingParameters, subset) elif ComputingParameters.SpectrumParameters.WaveSpectrumParameters.SpectrumType in { 'radial', 'Radial' }: # use the radial integration of the Image Spectrum SpectrumComputedData = RadialSpectrum(ComputingParameters, subset) else: sys.exit("Method for Spectrum Estimation not defined") # store data Directions.append(SpectrumComputedData.WaveDirection) WaveSpectra.append(SpectrumComputedData.WaveSpectrum) ImageSpectra.append(SpectrumComputedData.ImageSpectrum) # compute mean directions direction = np.nanmean(Directions) # compute mean Spectrum K = np.zeros((SubsetParameters.BoxNb, WaveSpectra[0].k.shape[0])) WSP = np.zeros((SubsetParameters.BoxNb, WaveSpectra[0].Spectrum.shape[0])) for i in range(SubsetParameters.BoxNb): K[i, :] = WaveSpectra[i].k WSP[i, :] = WaveSpectra[i].Spectrum k = np.mean(K, axis=0) spectrum = np.mean(WSP, axis=0) spectrumstd = np.std(WSP, axis=0) """ fig, ax = plt.subplots(1) for i in range(SubsetParameters.BoxNb): ax.plot(K[i,:], WSP[i,:]) plt.show() """ # compute peak wavelength PeakWavelength = WavelengthEstimate(ComputingParameters, k, spectrum) # store processed data Spectrum = CL.SpectrumProcessedData(k, spectrum, spectrumstd, PeakWavelength) # post-processing data for figures and statistics SubscenesSpectrum = CL.SpectrumComputedData(Directions, WaveSpectra, ImageSpectra, Subsets) # store mean data ComputedSpectrumData = CL.SpectrumComputedData(direction, Spectrum) return ComputedSpectrumData, SubscenesSpectrum