예제 #1
0
        internal static FloatImage ConvolveSingle(T image, FloatImage kernel, int kernelWidth, int kernelHeight)
        {
            int kernelXRadius = kernel.Width >> 1;
            int kernelYRadius = kernelHeight >> 1;

            FloatImage r     = new FloatImage(image.Width, image.Height);
            float      total = kernel.Sum();

            for (int dy = 0; dy < image.Height; dy++)
            {
                for (int dx = 0; dx < image.Width; dx++)
                {
                    float v   = 0f;
                    float sum = 0f;
                    for (int ky = 0; ky < kernelHeight; ky++)
                    {
                        int sy = dy + ky - kernelYRadius;
                        if (sy < 0 || image.Height <= sy)
                        {
                            continue;
                        }

                        for (int kx = 0; kx < kernelWidth; kx++)
                        {
                            int sx = dx + kx - kernelXRadius;
                            if (sx < 0 || image.Width <= sx)
                            {
                                continue;
                            }

                            byte  sv = image[sx, sy];
                            float kv = kernel[kx, ky];
                            v   += sv * kv;
                            sum += kv;
                        }
                    }

                    r[dx, dy] = total == sum ? v : (v * total / sum);
                }
            }

            return(r);
        }
예제 #2
0
 FloatImage IByteImageOperations.Convolve(IByteImageWrapper image, FloatImage kernel)
 => Convolve((T)image, kernel);
예제 #3
0
 public Projections(int regionWidth, int regionHeight, int lineCount)
 {
     Region        = new Imaging.FloatImage(regionWidth, regionHeight);
     PixelsPerLine = new int[lineCount];
 }