示例#1
0
 /// <summary>
 /// Set the border of a matrix to a specific value.
 /// </summary>
 public static void SetBorder <T>(this Matrix <T> matrix, Border2l border, T value)
 {
     matrix.ApplyCenterBordersAndCorners(border,
                                         m => { },
                                         m => m.Set(value), m => m.Set(value), m => m.Set(value), m => m.Set(value),
                                         m => m.Set(value), m => m.Set(value), m => m.Set(value), m => m.Set(value));
 }
示例#2
0
 /// <summary>
 /// Set the border of an image volume to a specific value.
 /// </summary>
 public static void SetBorder <T>(this Volume <T> volume, Border2l border, T value)
 {
     volume.ApplyCenterBordersAndCorners(border,
                                         v => { },
                                         v => v.Set(value), v => v.Set(value), v => v.Set(value), v => v.Set(value),
                                         v => v.Set(value), v => v.Set(value), v => v.Set(value), v => v.Set(value));
 }
示例#3
0
        /// <summary>
        /// Creates a new matrix with a border of the supplied size around the supplied matrix.
        /// the resulting matrix starts at zero coordinates.
        /// </summary>
        public static Matrix <T> CopyWithBorder <T>(this Matrix <T> matrix, Border2l border)
        {
            var bm = new Matrix <T>(matrix.SX + border.Min.X + border.Max.X,
                                    matrix.SY + border.Min.Y + border.Max.Y);

            bm.SubCenter(border).Set(matrix);
            return(bm);
        }
示例#4
0
        /// <summary>
        /// Creates a new image volume with a border of the supplied size
        /// around the supplied image volume.
        /// </summary>
        public static Volume <T> CopyWithBorder <T>(this Volume <T> volume, Border2l border)
        {
            var iv = new V3l(volume.SX + border.Min.X + border.Max.X,
                             volume.SY + border.Min.Y + border.Max.Y,
                             volume.SZ).CreateImageVolume <T>();

            iv.SubCenter(border).Set(volume);
            return(iv);
        }
示例#5
0
        /// <summary>
        /// Creates a new matrix with a border of the supplied size around the supplied matrix.
        /// the resulting matrix starts at zero coordinates.
        /// </summary>
        public static Matrix <T1> MapWithBorder <T, T1>(
            this Matrix <T> matrix, Border2l border,
            Func <T, T1> item_fun)
        {
            var bm = new Matrix <T1>(matrix.SX + border.Min.X + border.Max.X,
                                     matrix.SY + border.Min.Y + border.Max.Y);

            bm.SubCenter(border).SetMap(matrix, item_fun);
            return(bm);
        }
示例#6
0
        /// <summary>
        /// Creates a new image volume with a border of the supplied size
        /// around the supplied image volume.
        /// </summary>
        public static Volume <T1> MapWithBorder <T, T1>(
            this Volume <T> volume, Border2l border,
            Func <T, T1> item_fun)
        {
            var iv = new V3l(volume.SX + border.Min.X + border.Max.X,
                             volume.SY + border.Min.Y + border.Max.Y,
                             volume.SZ).CreateImageVolume <T1>();

            iv.SubCenter(border).SetMap(volume, item_fun);
            return(iv);
        }
示例#7
0
        /// <summary>
        /// Creates a new matrix with a border of the supplied size around the supplied matrix.
        /// The resulting matrix retains the coordinates of the original matrix.
        /// </summary>
        public static Matrix <T> CopyWithBorderWindow <T>(this Matrix <T> matrix, Border2l border)
        {
            var bm = new Matrix <T>(matrix.SX + border.Min.X + border.Max.X,
                                    matrix.SY + border.Min.Y + border.Max.Y)
            {
                F = new V2l(matrix.FX - border.Min.X, matrix.FY - border.Min.Y)
            };

            bm.SubCenter(border).Set(matrix);
            return(bm);
        }
示例#8
0
 /// <summary>
 /// Process an image volume with specific actions for the center and border
 /// parts.
 /// </summary>
 public static void ApplyCenterBordersAndCorners <Td, Tv>(
     this Matrix <Td, Tv> source, Border2l border,
     Action <Matrix <Td, Tv> > actCenter,
     Action <Matrix <Td, Tv> > actMinX, Action <Matrix <Td, Tv> > actMaxX,
     Action <Matrix <Td, Tv> > actMinY, Action <Matrix <Td, Tv> > actMaxY,
     Action <Matrix <Td, Tv> > actMinXMinY, Action <Matrix <Td, Tv> > actMaxXMinY,
     Action <Matrix <Td, Tv> > actMinXMaxY, Action <Matrix <Td, Tv> > actMaxXMaxY)
 {
     actCenter(source.SubCenter(border));
     actMinX(source.SubMinX(border)); actMaxX(source.SubMaxX(border));
     actMinY(source.SubMinY(border)); actMaxY(source.SubMaxY(border));
     actMinXMinY(source.SubMinXMinY(border)); actMaxXMinY(source.SubMaxXMinY(border));
     actMinXMaxY(source.SubMinXMaxY(border)); actMaxXMaxY(source.SubMaxXMaxY(border));
 }
示例#9
0
 /// <summary>
 /// Process an image volume with specific actions for the center and border
 /// parts.
 /// </summary>
 public static void ApplyCenterBordersAndCorners <T>(
     this Volume <T> source, Border2l border,
     Action <Volume <T> > actCenter,
     Action <Volume <T> > actMinX, Action <Volume <T> > actMaxX,
     Action <Volume <T> > actMinY, Action <Volume <T> > actMaxY,
     Action <Volume <T> > actMinXMinY, Action <Volume <T> > actMaxXMinY,
     Action <Volume <T> > actMinXMaxY, Action <Volume <T> > actMaxXMaxY)
 {
     actCenter(source.SubCenter(border));
     actMinX(source.SubMinX(border)); actMaxX(source.SubMaxX(border));
     actMinY(source.SubMinY(border)); actMaxY(source.SubMaxY(border));
     actMinXMinY(source.SubMinXMinY(border)); actMaxXMinY(source.SubMaxXMinY(border));
     actMinXMaxY(source.SubMinXMaxY(border)); actMaxXMaxY(source.SubMaxXMaxY(border));
 }
示例#10
0
 /// <summary>
 /// Replicate the border pixels of the center region outward.
 /// </summary>
 public static void ReplicateBorder <T>(this Matrix <T> matrix, Border2l border)
 {
     matrix.ApplyCenterBordersAndCorners(new Border2l(border.Min, border.Max),
                                         m => { },
                                         m => m.SetByCoord(y => m[m.EX, y], (y, x, vy) => vy),
                                         m => m.SetByCoord(y => m[m.FX - 1, y], (y, x, vy) => vy),
                                         m =>
     {
         var tm = m.SubMatrixWindow(m.F, m.S.YX, m.D.YX, m.F.YX);
         tm.SetByCoord(y => tm[tm.EX, y], (y, x, vy) => vy);
     },
                                         m =>
     {
         var tm = m.SubMatrixWindow(m.F, m.S.YX, m.D.YX, m.F.YX);
         tm.SetByCoord(y => tm[tm.FX - 1, y], (y, x, vy) => vy);
     },
                                         m => { var v = m[m.EX, m.EY]; m.SetByCoord((x, y) => v); },
                                         m => { var v = m[m.FX - 1, m.EY]; m.SetByCoord((x, y) => v); },
                                         m => { var v = m[m.EX, m.FY - 1]; m.SetByCoord((x, y) => v); },
                                         m => { var v = m[m.FX - 1, m.FY - 1]; m.SetByCoord((x, y) => v); });
 }
示例#11
0
 /// <summary>
 /// Replicate the border pixels of the center region outward.
 /// </summary>
 public static void ReplicateBorder <T>(this Volume <T> volume, Border2l border)
 {
     volume.ApplyCenterBordersAndCorners(border,
                                         v => { },
                                         v => v.SetByCoord(z => false, (z, y, vz) => v[v.EX, y, z], (z, y, x, vz, vy) => vy),
                                         v => v.SetByCoord(z => false, (z, y, vz) => v[v.FX - 1, y, z], (z, y, x, vz, vy) => vy),
                                         v =>
     {
         var tv = v.SubVolumeWindow(v.F, v.S.YXZ, v.D.YXZ, v.F.YXZ);
         tv.SetByCoord(z => false, (z, y, vz) => tv[tv.EX, y, z], (z, y, x, vz, vy) => vy);
     },
                                         v =>
     {
         var tv = v.SubVolumeWindow(v.F, v.S.YXZ, v.D.YXZ, v.F.YXZ);
         tv.SetByCoord(z => false, (z, y, vz) => tv[tv.FX - 1, y, z], (z, y, x, vz, vy) => vy);
     },
                                         v => v.SetByCoord(z => v[v.EX, v.EY, z], (z, y, vz) => false, (z, y, x, vz, vy) => vz),
                                         v => v.SetByCoord(z => v[v.FX - 1, v.EY, z], (z, y, vz) => false, (z, y, x, vz, vy) => vz),
                                         v => v.SetByCoord(z => v[v.EX, v.FY - 1, z], (z, y, vz) => false, (z, y, x, vz, vy) => vz),
                                         v => v.SetByCoord(z => v[v.FX - 1, v.FY - 1, z], (z, y, vz) => false, (z, y, x, vz, vy) => vz));
 }
示例#12
0
        /// <summary>
        /// Process an image volume with specific actions for the center and
        /// border parts.
        /// </summary>
        public static Volume <T1> WithProcessedCenterBordersAndCorners <T, T1>(
            this Volume <T> source, Border2l border,
            Func <Volume <T>, Volume <T1> > funCenter,
            Func <Volume <T>, Volume <T1> > funMinX, Func <Volume <T>, Volume <T1> > funMaxX,
            Func <Volume <T>, Volume <T1> > funMinY, Func <Volume <T>, Volume <T1> > funMaxY,
            Func <Volume <T>, Volume <T1> > funMinXMinY, Func <Volume <T>, Volume <T1> > funMaxXMinY,
            Func <Volume <T>, Volume <T1> > funMinXMaxY, Func <Volume <T>, Volume <T1> > funMaxXMaxY)
        {
            var target = source.Size.CreateImageVolume <T1>();

            target.F = source.F;
            target.SubCenter(border).Set(funCenter(source.SubCenter(border)));
            target.SubMinX(border).Set(funMinX(source.SubMinX(border)));
            target.SubMaxX(border).Set(funMaxX(source.SubMaxX(border)));
            target.SubMinY(border).Set(funMinY(source.SubMinY(border)));
            target.SubMaxY(border).Set(funMaxY(source.SubMaxY(border)));
            target.SubMinXMinY(border).Set(funMinXMinY(source.SubMinXMinY(border)));
            target.SubMaxXMinY(border).Set(funMaxXMinY(source.SubMaxXMinY(border)));
            target.SubMinXMaxY(border).Set(funMinXMaxY(source.SubMinXMaxY(border)));
            target.SubMaxXMaxY(border).Set(funMaxXMaxY(source.SubMaxXMaxY(border)));
            return(target);
        }
示例#13
0
        /// <summary>
        /// Process an image volume with specific actions for the center and border
        /// parts.
        /// </summary>
        public static Matrix <T1> ProcessCenterBordersAndCorners <T, T1>(
            this Matrix <T> source, Border2l border,
            Action <Matrix <T>, Matrix <T1> > actCenter,
            Action <Matrix <T>, Matrix <T1> > actMinX, Action <Matrix <T>, Matrix <T1> > actMaxX,
            Action <Matrix <T>, Matrix <T1> > actMinY, Action <Matrix <T>, Matrix <T1> > actMaxY,
            Action <Matrix <T>, Matrix <T1> > actMinXMinY, Action <Matrix <T>, Matrix <T1> > actMaxXMinY,
            Action <Matrix <T>, Matrix <T1> > actMinXMaxY, Action <Matrix <T>, Matrix <T1> > actMaxXMaxY)
        {
            var target = new Matrix <T1>(source.Size);

            target.F = source.F;

            actCenter(source.SubCenter(border), target.SubCenter(border));
            actMinX(source.SubMinX(border), target.SubMinX(border));
            actMaxX(source.SubMaxX(border), target.SubMaxX(border));
            actMinY(source.SubMinY(border), target.SubMinY(border));
            actMaxY(source.SubMaxY(border), target.SubMaxY(border));
            actMinXMinY(source.SubMinXMinY(border), target.SubMinXMinY(border));
            actMaxXMinY(source.SubMaxXMinY(border), target.SubMaxXMinY(border));
            actMinXMaxY(source.SubMinXMaxY(border), target.SubMinXMaxY(border));
            actMaxXMaxY(source.SubMaxXMaxY(border), target.SubMaxXMaxY(border));

            return(target);
        }
示例#14
0
 /// <summary>
 /// Get the minimal x edge part of a matrix with the specified border.
 /// Note that the part retains the pixel coordinates of the original matrix.
 /// </summary>
 public static Matrix <T> SubMinX <T>(this Matrix <T> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.FX, m.FY + b.Min.Y,
                              b.Min.X, m.SY - b.Min.Y - b.Max.Y));
 }
示例#15
0
 /// <summary>
 /// Get the maximal x edge part of a matrix with the specified border.
 /// Note that the part retains the pixel coordinates of the original matrix.
 /// </summary>
 public static Matrix <Td, Tv> SubMaxX <Td, Tv>(this Matrix <Td, Tv> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.EX - b.Max.X, m.FY + b.Min.Y,
                              b.Max.X, m.SY - b.Min.Y - b.Max.Y));
 }
示例#16
0
 public static Matrix <T> SubMinY <T>(this Matrix <T> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.FX + b.Min.X, m.FY,
                              m.SX - b.Min.X - b.Max.X, b.Min.Y));
 }
示例#17
0
 /// <summary>
 /// Get the maximal y edge part of a matrix with the specified border.
 /// Note that the part retains the pixel coordinates of the original matrix.
 /// </summary>
 public static Matrix <Td, Tv> SubMaxY <Td, Tv>(this Matrix <Td, Tv> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.FX + b.Min.X, m.EY - b.Max.Y,
                              m.SX - b.Min.X - b.Max.X, b.Max.Y));
 }
示例#18
0
 /// <summary>
 /// Get the center part of an image volume with the specified border.
 /// Note that the part retains the pixel coordinates of the original volume.
 /// </summary>
 public static Volume <T> SubCenter <T>(this Volume <T> v, Border2l b)
 {
     return(v.SubVolumeWindow(v.FX + b.Min.X, v.FY + b.Min.Y, v.FZ,
                              v.SX - b.Max.X - b.Min.X, v.SY - b.Max.Y - b.Min.Y, v.SZ));
 }
示例#19
0
 /// <summary>
 /// Get the minimal x/minmal y corner part of an image volume with the specified border.
 /// Note that the part retains the pixel coordinates of the original volume.
 /// </summary>
 public static Volume <T> SubMinXMinY <T>(this Volume <T> v, Border2l b)
 {
     return(v.SubVolumeWindow(v.FX, v.FY, v.FZ,
                              b.Min.X, b.Min.Y, v.SZ));
 }
示例#20
0
 /// <summary>
 /// Get the maximal x/maximal y corner part of a matrix with the specified border.
 /// Note that the part retains the pixel coordinates of the original matrix.
 /// </summary>
 public static Matrix <T> SubMaxXMaxY <T>(this Matrix <T> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.EX - b.Max.X, m.EY - b.Max.Y,
                              b.Max.X, b.Max.Y));
 }
示例#21
0
 /// <summary>
 /// Get the maximal y edge part of an image volume with the specified border.
 /// Note that the part retains the pixel coordinates of the original volume.
 /// </summary>
 public static Volume <T> SubMaxY <T>(this Volume <T> v, Border2l b)
 {
     return(v.SubVolumeWindow(v.FX + b.Min.X, v.EY - b.Max.Y, v.FZ,
                              v.SX - b.Min.X - b.Max.X, b.Max.Y, v.SZ));
 }
示例#22
0
 /// <summary>
 /// Get the maximal x edge part of an image volume with the specified border.
 /// Note that the part retains the pixel coordinates of the original volume.
 /// </summary>
 public static Volume <T> SubMaxX <T>(this Volume <T> v, Border2l b)
 {
     return(v.SubVolumeWindow(v.EX - b.Max.X, v.FY + b.Min.Y, v.FZ,
                              b.Max.X, v.SY - b.Min.Y - b.Max.Y, v.SZ));
 }
示例#23
0
        public static Volume <T> GetMatrixFromTiles <T>(
            this Border2l border, long x, long y, Func <long, long, Box.Flags, Volume <T> > x_y_loadFun)
        {
            var flipped = border.Flipped;
            var center  = x_y_loadFun(x, y, Box.Flags.All);

            if (center.IsInvalid)
            {
                return(center);
            }
            var result = center.CopyWithBorderWindow(border);

            if (border.Min.Y > 0)
            {
                if (border.Min.X > 0)
                {
                    var tnn = x_y_loadFun(x - 1, y - 1, Box.Flags.MaxXMaxY);
                    if (tnn.IsValid)
                    {
                        result.SubMinXMinY(border).Set(tnn.SubMaxXMaxY(flipped));
                    }
                }
                var t0n = x_y_loadFun(x, y - 1, Box.Flags.MaxY);
                if (t0n.IsValid)
                {
                    result.SubMinY(border).Set(t0n.SubMaxY(border.Min.Y));
                }
                if (border.Max.X > 0)
                {
                    var tpn = x_y_loadFun(x + 1, y - 1, Box.Flags.MinXMaxY);
                    if (tpn.IsValid)
                    {
                        result.SubMaxXMinY(border).Set(tpn.SubMinXMaxY(flipped));
                    }
                }
            }
            if (border.Min.X > 0)
            {
                var tn0 = x_y_loadFun(x - 1, y, Box.Flags.MaxX);
                if (tn0.IsValid)
                {
                    result.SubMinX(border).Set(tn0.SubMaxX(border.Min.X));
                }
            }
            if (border.Max.X > 0)
            {
                var tp0 = x_y_loadFun(x + 1, y, Box.Flags.MinX);
                if (tp0.IsValid)
                {
                    result.SubMaxX(border).Set(tp0.SubMinX(border.Max.X));
                }
            }
            if (border.Max.Y > 0)
            {
                if (border.Min.X > 0)
                {
                    var tnp = x_y_loadFun(x - 1, y + 1, Box.Flags.MaxXMinY);
                    if (tnp.IsValid)
                    {
                        result.SubMinXMaxY(border).Set(tnp.SubMaxXMinY(flipped));
                    }
                }
                var t0p = x_y_loadFun(x, y + 1, Box.Flags.MinY);
                if (t0p.IsValid)
                {
                    result.SubMaxY(border).Set(t0p.SubMinY(border.Max.Y));
                }
                if (border.Max.X > 0)
                {
                    var tpp = x_y_loadFun(x + 1, y + 1, Box.Flags.MinXMinY);
                    if (tpp.IsValid)
                    {
                        result.SubMaxXMaxY(border).Set(tpp.SubMinXMinY(flipped));
                    }
                }
            }
            return(result);
        }
示例#24
0
 /// <summary>
 /// Get the minimal x/minmal y corner part of a matrix with the specified border.
 /// Note that the part retains the pixel coordinates of the original matrix.
 /// </summary>
 public static Matrix <Td, Tv> SubMinXMinY <Td, Tv>(this Matrix <Td, Tv> m, Border2l b)
 {
     return(m.SubMatrixWindow(m.FX, m.FY,
                              b.Min.X, b.Min.Y));
 }