Пример #1
0
 private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         return((byte)(b >= Threshold ? 255 : 0));
     }, PixelFilter);
 }
Пример #2
0
 private void ProcessPlane(ImagePlane plane, Func <int, byte, byte> calculationFunc, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         return(calculationFunc(ValueProvider.Provide(), b));
     }, PixelFilter);
 }
Пример #3
0
        /// <summary>
        /// Scales the image using bilinear interpolation.
        /// </summary>
        /// <param name="inputImage">Image to scale.</param>
        /// <param name="newSize">Size to resize to.</param>
        /// <returns>Scaled image.</returns>
        private Image ProcessBiliniar(Image inputImage, Size2D newSize)
        {
            var newImage = new Image(newSize, inputImage.Planes.Count);

            double scaleX = (double)(inputImage.Width - 1) / newSize.Width;
            double scaleY = (double)(inputImage.Height - 1) / newSize.Height;

            for (int i = 0; i < inputImage.Planes.Count; i++)
            {
                byte[,] inputBytes = inputImage.Planes[i].GetPixelsAs2DArray();
                ProcessingHelper.ProcessMono(newImage.Planes[i], (b, y, x) =>
                {
                    var pY       = (int)(scaleY * y);
                    double yDiff = (scaleY * y) - pY;
                    var pX       = (int)(scaleX * x);
                    double xDiff = (scaleX * x) - pX;

                    return((byte)(inputBytes[pY, pX] * (1 - xDiff) * (1 - yDiff) +
                                  inputBytes[pY, pX + 1] * (1 - yDiff) * xDiff +
                                  inputBytes[pY + 1, pX] * yDiff * (1 - xDiff) +
                                  inputBytes[pY + 1, pX + 1] * yDiff * xDiff));
                });
            }

            return(newImage);
        }
Пример #4
0
 private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         return(ValueProvider.Provide());
     }, PixelFilter);
 }
Пример #5
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            var valueDic = BuildValueDictionary(Mode, plane, bounds);

            ProcessingHelper.ProcessMono(plane, bounds, (b, y, x) =>
            {
                return((Mode == SmearMode.VerticalFromTop || Mode == SmearMode.VerticalFromBottom) ? valueDic[x] : valueDic[y]);
            }, PixelFilter);
        }
Пример #6
0
        /// <summary>
        /// Scales the image using nearest neighbor interpolation.
        /// </summary>
        /// <param name="inputImage">Image to scale.</param>
        /// <param name="newSize">Size to resize to.</param>
        /// <returns>Scaled image.</returns>
        private static Image ProcessNearestNeighbor(Image inputImage, Size2D newSize)
        {
            var newImage = new Image(newSize, inputImage.Planes.Count);

            double scaleX = newSize.Width / (double)inputImage.Width;
            double scaleY = newSize.Height / (double)inputImage.Height;

            for (int i = 0; i < inputImage.Planes.Count; i++)
            {
                byte[,] inputBytes = inputImage.Planes[i].GetPixelsAs2DArray();
                ProcessingHelper.ProcessMono(newImage.Planes[i], (b, y, x) =>
                {
                    var yUnscaled = (int)(y / scaleY);
                    var xUnscaled = (int)(x / scaleX);
                    return(inputBytes[yUnscaled, xUnscaled]);
                });
            }

            return(newImage);
        }
Пример #7
0
        /// <summary>
        /// Applies the gain value
        /// to the given <paramref name="inputImage"/>.
        /// </summary>
        /// <param name="inputImage">Image to apply gain to.</param>
        /// <returns>Processed image.</returns>
        public Image Process(Image inputImage)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }

            ProcessingHelper.ProcessRGB(inputImage, (rgb) =>
            {
                byte r = WrapAroundR ? (byte)ProcessingHelper.ClampPixelValue((rgb.R * FactorRR) + (rgb.G * FactorRG) + (rgb.B * FactorRB))
                             : (byte)((rgb.R * FactorRR) + (rgb.G * FactorRG) + (rgb.B * FactorRB));
                byte g = WrapAroundG ? (byte)ProcessingHelper.ClampPixelValue((rgb.R * FactorGR) + (rgb.G * FactorGG) + (rgb.B * FactorGB))
                             : (byte)((rgb.R * FactorGR) + (rgb.G * FactorGG) + (rgb.B * FactorGB));
                byte b = WrapAroundB ? (byte)ProcessingHelper.ClampPixelValue((rgb.R * FactorBR) + (rgb.G * FactorBG) + (rgb.B * FactorBB))
                             : (byte)((rgb.R * FactorBR) + (rgb.G * FactorBG) + (rgb.B * FactorBB));

                return(new RGBPixel(r, g, b));
            }, this.GetProcessingBounds(inputImage), PixelFilter);

            return(inputImage);
        }
Пример #8
0
 private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         if (ShiftDirection == BitShiftDirection.Left)
         {
             int pixelValue = b << ValueProvider.Provide();
             if (WrapAround && pixelValue > 255)
             {
                 return(255);
             }
             else
             {
                 return((byte)pixelValue);
             }
         }
         else
         {
             return((byte)(b >> ValueProvider.Provide()));
         }
     }, PixelFilter);
 }
Пример #9
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            int byteCounter = 0;

            byte[] sortedBytes;

            unsafe
            {
                if (UseAOI)
                {
                    if (Mode == SortMode.Ascending)
                    {
                        sortedBytes = plane.GetAllPixelsIn(AOI).Select(p => *(byte *)p).OrderBy(i => i).ToArray();
                    }
                    else
                    {
                        sortedBytes = plane.GetAllPixelsIn(AOI).Select(p => *(byte *)p).OrderByDescending(i => i).ToArray();
                    }
                }
                else
                {
                    if (Mode == SortMode.Ascending)
                    {
                        sortedBytes = plane.AllPixels.Select(p => *(byte *)p).OrderBy(i => i).ToArray();
                    }
                    else
                    {
                        sortedBytes = plane.AllPixels.Select(p => *(byte *)p).OrderByDescending(i => i).ToArray();
                    }
                }
            }

            ProcessingHelper.ProcessMono(plane, bounds, (b) =>
            {
                return(sortedBytes[byteCounter++]);
            }, PixelFilter);
        }
Пример #10
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            var rnd         = new Random(DateTime.Now.Ticks.GetHashCode());
            int byteCounter = 0;

            byte[] shuffledBytes;

            unsafe
            {
                if (UseAOI)
                {
                    shuffledBytes = plane.GetAllPixelsIn(AOI).Select(p => *(byte *)p).OrderBy(i => rnd.Next()).ToArray();
                }
                else
                {
                    shuffledBytes = plane.AllPixels.Select(p => *(byte *)p).OrderBy(i => rnd.Next()).ToArray();
                }
            }

            ProcessingHelper.ProcessMono(plane, bounds, (b) =>
            {
                return(shuffledBytes[byteCounter++]);
            }, PixelFilter);
        }