public static unsafe ComplexImage GetSubComplexImage(this UnmanagedImage image, int x, int y, int width, int height, bool zeroPadding = true) { const float norm = ComplexImage.MAX_MAGNITUDE / (float)byte.MaxValue; if (x < 0 || y < 0 || image.Width < width || image.Height < height) { throw new DimensionMismatchException(); } var result = zeroPadding ? new ComplexImage((int)MathCV.UpperPow2((uint)width), (int)MathCV.UpperPow2((uint)height)) : new ComplexImage(width, height); var c0Data = result.Channel0; var c1Data = result.Channel1; var c2Data = result.Channel2; ComplexImage.Compatible.CheckFormat(image, out var pb); var srcDataPtr = (byte *)(image.ImageData + (y * image.Stride) + (x * pb)); var srcPadd = image.Stride - (width * pb); var dstPadd = result.Width - width; for (int i = 0, n = result.Width * height; i < n; i += dstPadd, srcDataPtr += srcPadd) { for (var iTo = i + width; i < iTo; i++, srcDataPtr += pb) { c0Data[i] = srcDataPtr[RGB.R] * norm; c1Data[i] = srcDataPtr[RGB.G] * norm; c2Data[i] = srcDataPtr[RGB.B] * norm; } } return(result); }
/// <summary> /// Create a sin funktion with frequency f along the given direction /// </summary> /// <param name="f"></param> /// <param name="angle">direction of the sin in degrees</param> /// <returns></returns> public static Complex2D GenerateSin(int w, int h, double f, double angle) { var result = new Complex2D(w, h); var a = ((2 * Math.PI * f) / w) * Math.Cos(angle = MathCV.ToRad(angle)); var b = ((2 * Math.PI * f) / h) * Math.Sin(angle); var d = result.Data; for (int y = 0, i = 0; y < h; y++) { var v = y * b; for (var x = 0; x < w; x++, i++) { d[i] = Math.Sin(v + (x * a)); } } return(result); }
/// <summary> /// Create an ComplexImage from this image with a width/height that is the smallest power of two which isgreater or equal /// than the size of the input image. /// </summary> /// <param name="image"></param> public static ComplexImage ToComplexImageZeroPad(this UnmanagedImage image) => ToComplexImageZeroPad( image, MathCV.UpperPow2(image.Width), MathCV.UpperPow2(image.Height) );