//------------------------------------------------------------------------------------------------
        //Создание изображения из матрицы интенсивностей серого по шаблону
        public static WriteableBitmap CreateGrayScaleWriteableBitmapFromMatrix(
            RealMatrix grayScaleMatrix,
            int dpiX, int dpiY, BitMask2D bitMask
            )
        {
            int             pixelWidth      = grayScaleMatrix.ColumnCount;
            int             pixelHeight     = grayScaleMatrix.RowCount;
            WriteableBitmap writeableBitmap = WriteableBitmapCreator.CreateWriteableBitmap
                                                  (pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Bgra32);
            WriteableBitmapWrapper bitmapWrapper = WriteableBitmapWrapper.Create(writeableBitmap);

            for (int x = 0; x < pixelWidth; x++)
            {
                for (int y = 0; y < pixelHeight; y++)
                {
                    if (bitMask[y, x] == true)
                    {
                        int  grayIntensity = ( int )Math.Round(grayScaleMatrix[y, x]);
                        byte red, green, blue;
                        red = green = blue = Convert.ToByte(grayIntensity);
                        Color color = Color.FromRgb(red, green, blue);
                        bitmapWrapper.SetPixelColor(x, y, color);
                    }
                }
            }
            return(writeableBitmap);
        }
        //-----------------------------------------------------------------------------------------------------


        //-----------------------------------------------------------------------------------------------------
        //Обрезка изображения
        public WriteableBitmap GetSubBitmap(System.Drawing.Point leftTop, System.Drawing.Point rightBottom)
        {
            int newImageWidth  = Convert.ToInt32(Math.Abs(rightBottom.X - leftTop.X)) + 1;
            int newImageHeight = Convert.ToInt32(Math.Abs(rightBottom.Y - leftTop.Y)) + 1;

            media.PixelFormat pixelFormat = this.Image.Format;
            int             dpiX          = Convert.ToInt32(OS.OS.SystemDpiX);
            int             dpiY          = Convert.ToInt32(OS.OS.SystemDpiY);
            WriteableBitmap newBitmap     = WriteableBitmapCreator.CreateWriteableBitmap
                                                (newImageWidth, newImageHeight, dpiX, dpiY, pixelFormat);
            WriteableBitmapWrapper newImageWrapper = WriteableBitmapWrapper.Create(newBitmap);

            for (int y = leftTop.Y, newY = 0; y <= rightBottom.Y; y++, newY++)
            {
                for (int x = leftTop.X, newX = 0; x <= rightBottom.X; x++, newX++)
                {
                    media.Color color = this.GetPixelColor(x, y);
                    newImageWrapper.SetPixelColor(newX, newY, color);
                }
            }

            return(newBitmap);
        }