コード例 #1
0
ファイル: Initializer.cs プロジェクト: GerFern/ImageProject
        public override IMatrixImage Invoke(IMatrixImage input)
        {
            var image = (IMatrixImage)input.Clone();

            if (image is MatrixImage <byte> imgByte)
            {
                foreach (var layer in imgByte.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <byte>(Code, this));
                }
            }
            else if (image is MatrixImage <int> imgInt)
            {
                foreach (var layer in imgInt.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <int>(Code, this));
                }
            }
            else if (image is MatrixImage <float> imgSingle)
            {
                foreach (var layer in imgSingle.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <float>(Code, this));
                }
            }
            else if (image is MatrixImage <double> imgDouble)
            {
                foreach (var layer in imgDouble.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <double>(Code, this));
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(image);
        }
コード例 #2
0
ファイル: WeightMediane.cs プロジェクト: GerFern/ImageProject
        public override IMatrixImage Invoke(IMatrixImage input)
        {
            var image = (IMatrixImage)input.Clone();

            int offset = (3 * 3) / 2;

            if (image is MatrixImage <byte> imgByte)
            {
                foreach (var layer in imgByte.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        var t = a[0] * 3;
                        if (t > byte.MaxValue)
                        {
                            t = byte.MaxValue;
                        }
                        a[0] = (byte)t;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else if (image is MatrixImage <short> imgInt16)
            {
                foreach (var layer in imgInt16.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        var t = a[0] * 3;
                        if (t > short.MaxValue)
                        {
                            t = short.MaxValue;
                        }
                        a[0] = (short)t;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else if (image is MatrixImage <int> imgInt32)
            {
                foreach (var layer in imgInt32.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        a[0] *= 3;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else if (image is MatrixImage <long> imgInt64)
            {
                foreach (var layer in imgInt64.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        a[0] *= 3;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else if (image is MatrixImage <float> imgSingle)
            {
                foreach (var layer in imgSingle.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        a[0] *= 3;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else if (image is MatrixImage <double> imgDouble)
            {
                foreach (var layer in imgDouble.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(3, 3, a =>
                    {
                        a[0] *= 3;
                        return(a.OrderBy(a => a).ElementAt(offset));
                    });
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(image);
        }
コード例 #3
0
        public override IMatrixImage Invoke(IMatrixImage input)
        {
            var image  = (IMatrixImage)input.Clone();
            int length = Width * Height;
            int offset = (Width * Height) / 2;

            if (image is MatrixImage <byte> imgByte)
            {
                foreach (var layer in imgByte.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        byte min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else if (image is MatrixImage <short> imgInt16)
            {
                foreach (var layer in imgInt16.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        short min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else if (image is MatrixImage <int> imgInt32)
            {
                foreach (var layer in imgInt32.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        int min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else if (image is MatrixImage <long> imgInt64)
            {
                foreach (var layer in imgInt64.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        long min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else if (image is MatrixImage <float> imgSingle)
            {
                foreach (var layer in imgSingle.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        float min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else if (image is MatrixImage <double> imgDouble)
            {
                foreach (var layer in imgDouble.SplitWithoutAlpha())
                {
                    layer.SlidingWindow(Width, Height, a =>
                    {
                        double min = a[0], max = a[0];
                        for (int i = 1; i < offset; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        for (int i = offset + 1; i < length; i++)
                        {
                            if (a[i] < min)
                            {
                                min = a[i];
                            }
                            else if (a[i] > max)
                            {
                                max = a[i];
                            }
                        }
                        if (a[offset] > max || a[offset] < min)
                        {
                            return(a.OrderBy(a => a).ElementAt(offset));
                        }
                        else
                        {
                            return(a[offset]);
                        }
                    });
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(image);
        }