/// <summary> /// Transforms this image by dividing it element-wise with the specified kernel. /// </summary> /// <param name="kernel">The kernel to divide by. If the kernel has one channel, it will be divided from all channels of this image, else the corresponding channels will be divided.</param> public void DivideBy(FourierWorker kernel) { if (!(kernel.FourierWidth == FourierWidth && kernel.FourierHeight == FourierHeight)) { throw new ArgumentException("The passed FourierWorker must have the same FourierWidth and FourierHeight as this instance.", nameof(kernel)); } if (kernel.ShiftAxes) { FFTAfter = !FFTAfter; } if (kernel.ComponentCount == 1) { ComplexF[] mult = kernel.values[0]; ParallelLoop.For(0, FourierPixelCount, i => { int componentCount = ComponentCount; for (int c = 0; c < componentCount; c++) { values[c][i] /= mult[i]; } }, ImageLib.ParallelCutoff / ComponentCount); } else { int min = Math.Min(ComponentCount, kernel.ComponentCount); ComplexF[][] val = kernel.values; ParallelLoop.For(0, FourierPixelCount, i => { for (int c = 0; c < min; c++) { values[c][i] /= val[c][i]; } }, ImageLib.ParallelCutoff / min); } }
/// <summary> /// Copies the specified image into a new instance. /// </summary> /// <param name="image">The Fouurier image to copy.</param> public FourierWorker(FourierWorker image) { if (image == null || image.values == null) { return; } FFTAfter = image.FFTAfter; OriginalMax = image.OriginalMax; NormalizationCap = image.NormalizationCap; FourierWidth = image.FourierWidth; FourierHeight = image.FourierHeight; FourierSize = image.FourierSize; FourierPixelCount = image.FourierPixelCount; FourierPixelComponentCount = image.FourierPixelComponentCount; alphaReference = image.alphaReference; if (alphaReference != null) { alphaReference.ShallowClone(); } ShiftAxes = image.ShiftAxes; TargetWidth = image.TargetWidth; TargetHeight = image.TargetHeight; TargetSize = image.TargetSize; ComponentCount = image.ComponentCount; TargetPixelCount = image.TargetPixelCount; TargetPixelComponentCount = image.TargetPixelComponentCount; fourierWidthLog2 = image.fourierWidthLog2; fourierHeightLog2 = image.fourierHeightLog2; values = new ComplexF[ComponentCount][]; for (int c = 0; c < ComponentCount; c++) { values[c] = new ComplexF[FourierPixelCount]; Array.Copy(image.values[c], values[c], FourierPixelCount); } }