def ImageSpectrum(parameters, subset): #---------------------------------------------- # Compute Image Spectrum or Power Spectrum #---------------------------------------------- image = subset.image # given subset image if parameters.MeanSubstractionFlag: image = image - np.mean(image) # substract mean value Spectrum = imfft(image) # FFT of the given image mag = cv2.magnitude(Spectrum[:, :, 0], Spectrum[:, :, 1]) if parameters.DecibelRepresentationFlag: mag = 20 * np.log(mag) # amplitude spectrum (sqrt(Im**2 +Re**2)) #power Spectrum S = Spectrum[:, :, 0] + 1j * Spectrum[:, :, 1] mag2 = np.real(S * np.conjugate(S)) if parameters.DecibelRepresentationFlag: mag2 = 20 * np.log(mag2) #mag2 = np.abs(mag)**2 # selected spectrum to be plotted if parameters.PowerSpectrumFlag == True: spectrum = mag2 else: spectrum = mag #-------------------------------- # define the wavenumber axis #-------------------------------- step = 1 / subset.resolution[0] freqs = np.linspace(0, (spectrum.shape[1] - 1) * step / spectrum.shape[1], spectrum.shape[1]) fCenter = 0.5 * (freqs[np.int(spectrum.shape[1] / 2)] + freqs[np.int(spectrum.shape[1] / 2) - 1]) freqs = freqs - fCenter # axis centered on 0 k = 2 * np.pi * (freqs) #store data ImageSpectrum = CL.SpectrumData(k, spectrum) return ImageSpectrum
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 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