Esempio n. 1
0
        static void Main(string[] args)
        {
            try {
                // Create an image
                PixelIDValueEnum pixelType = PixelIDValueEnum.sitkUInt8;
                VectorUInt32     imageSize = new VectorUInt32(new uint[] { 128, 128 });
                Image            image     = new Image(imageSize, pixelType);

                // Create a face image
                VectorDouble faceSize   = new VectorDouble(new double[] { 64, 64 });
                VectorDouble faceCenter = new VectorDouble(new double[] { 64, 64 });
                Image        face       = SimpleITK.GaussianSource(pixelType, imageSize, faceSize, faceCenter);

                // Create eye images
                VectorDouble eyeSize    = new VectorDouble(new double[] { 5, 5 });
                VectorDouble eye1Center = new VectorDouble(new double[] { 48, 48 });
                VectorDouble eye2Center = new VectorDouble(new double[] { 80, 48 });
                Image        eye1       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye1Center, 150);
                Image        eye2       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye2Center, 150);

                // Apply the eyes to the face
                face = SimpleITK.Subtract(face, eye1);
                face = SimpleITK.Subtract(face, eye2);
                face = SimpleITK.BinaryThreshold(face, 200, 255, 255);


                // Create the mouth
                VectorDouble mouthRadii  = new VectorDouble(new double[] { 30, 20 });
                VectorDouble mouthCenter = new VectorDouble(new double[] { 64, 76 });
                Image        mouth       = SimpleITK.GaussianSource(pixelType, imageSize, mouthRadii, mouthCenter);
                mouth = SimpleITK.BinaryThreshold(mouth, 200, 255, 255);
                mouth = SimpleITK.Subtract(255, mouth);

                // Paste the mouth onto the face
                VectorUInt32 mouthSize = new VectorUInt32(new uint[] { 64, 18 });
                VectorInt32  mouthLoc  = new VectorInt32(new int[] { 32, 76 });
                face = SimpleITK.Paste(face, mouth, mouthSize, mouthLoc, mouthLoc);

                // Apply the face to the original image
                image = SimpleITK.Add(image, face);

                // Display the results
                if (Environment.GetEnvironmentVariable("SITK_NOSHOW") == null)
                {
                    SimpleITK.Show(image, "Hello World: CSharp", true);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Esempio n. 2
0
        public Bitmap konwertujObraz(Image obraz1, int przekroj = 0)
        {
            uint r = obraz1.GetWidth();
            //  VectorUInt32 w = new VectorUInt32(new[] { r, 512, 4 + 1 });

            VectorInt32 start = new VectorInt32(new[] { 0, 0, 0 });
            VectorInt32 size1 = new VectorInt32(new[] { 512, 512, 1 });

            obraz1 = WybierzPrzekroj(obraz1, przekroj);
            IntensityWindowingImageFilter normalize = new IntensityWindowingImageFilter();

            normalize.SetOutputMinimum(0);
            normalize.SetOutputMaximum(255);
            obraz1 = normalize.Execute(obraz1);

            PixelIDValueEnum u = PixelIDValueEnum.sitkFloat32;
            int          len   = 1;
            Image        input = SimpleITK.Cast(obraz1, u);
            VectorUInt32 size  = input.GetSize();

            for (int dim = 0; dim < input.GetDimension(); dim++)
            {
                len *= (int)size[dim];
            }
            IntPtr buffer    = input.GetBufferAsFloat();
            float  bufferPtr = (float)buffer.ToInt32();

            float[] bufferAsArray = new float[len];
            float[,] newData = new float[size[0], size[1]];
            Marshal.Copy(buffer, bufferAsArray, 0, len);
            obrazBitmap = new Bitmap(Convert.ToInt32(size[0]), Convert.ToInt32(size[1]));
            for (int j = 0; j < size[1]; j++)
            {
                for (int i = 0; i < size[0]; i++)
                {
                    var bur = bufferAsArray[j * size[1] + i];
                    System.Drawing.Color newColor = System.Drawing.Color.FromArgb((int)bur, 0, 0, 0);
                    obrazBitmap.SetPixel(j, i, newColor);
                }
            }
            Color s = obrazBitmap.GetPixel(34, 56);

            return(obrazBitmap);
        }
Esempio n. 3
0
        protected override void OnMouseMove(MouseEventArgsF e)
        {
            base.OnMouseMove(e);
            PointInt32 b = new PointInt32(e.X, e.Y);

            if (this.moveOffsetMode)
            {
                VectorInt32 num2 = (VectorInt32)(b - this.lastPt);
                this.downPt.X += num2.X;
                this.downPt.Y += num2.Y;
            }
            if ((e.Button == MouseButtons.Left) && (this.mouseDown == MouseButtons.Left))
            {
                VectorDouble num3 = (VectorDouble)(b - this.downPt);
                if (num3.Length >= 10.0)
                {
                    goto Label_00B1;
                }
            }
            if (!this.rect.HasPositiveArea)
            {
                if ((e.Button == MouseButtons.Middle) && (this.mouseDown == MouseButtons.Middle))
                {
                    PointDouble documentScrollPosition = base.DocumentWorkspace.DocumentScrollPosition;
                    documentScrollPosition.X += b.X - this.lastPt.X;
                    documentScrollPosition.Y += b.Y - this.lastPt.Y;
                    base.DocumentWorkspace.DocumentScrollPosition = documentScrollPosition;
                    base.Update();
                }
                else
                {
                    this.rect = RectInt32.Zero;
                }
                goto Label_0173;
            }
Label_00B1:
            this.rect = RectInt32Util.FromPixelPoints(this.downPt, b);
            this.rect = RectInt32.Intersect(this.rect, base.ActiveLayer.Bounds());
            this.UpdateDrawnRect();
Label_0173:
            this.lastPt = b;
        }
Esempio n. 4
0
        protected virtual void OnKeyDown(KeyEventArgs e)
        {
            if (!e.Handled)
            {
                if (!this.keysThatAreDown.ContainsKey(e.KeyData))
                {
                    this.keysThatAreDown.Add(e.KeyData, new KeyTimeInfo());
                }
                if ((!this.IsMouseDown && !this.panMode) && (e.KeyCode == Keys.Space))
                {
                    this.EnterPanMode();
                }
                else if ((this.panMode && e.Control) && e.KeyData.IsArrowKey())
                {
                    VectorInt32 num;
                    switch (e.KeyCode)
                    {
                    case Keys.Left:
                        num = new VectorInt32(-1, 0);
                        break;

                    case Keys.Up:
                        num = new VectorInt32(0, -1);
                        break;

                    case Keys.Right:
                        num = new VectorInt32(1, 0);
                        break;

                    case Keys.Down:
                        num = new VectorInt32(0, 1);
                        break;

                    default:
                        throw ExceptionUtil.InvalidEnumArgumentException <Keys>(e.KeyData, "e.KeyData");
                    }
                    PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView;
                    canvasView.ViewportCanvasOffset += this.CanvasView.ConvertViewportToCanvas(num * 100);
                }
                this.OnKeyPress(e.KeyData);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Extracts the position on the specified axis.
        /// </summary>
        /// <param name="image">The ITK image.</param>
        /// <param name="axisType">Type of the axis.</param>
        /// <param name="index">The position.</param>
        /// <returns>
        /// The extracted position as two-dimensional ITK image.
        /// </returns>
        /// <exception cref="ArgumentNullException">image</exception>
        public Image ExtractPosition(Image image, AxisType axisType, uint index)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            var size        = image.GetSize();
            var indexVector = new VectorInt32 {
                0, 0, 0
            };
            int indexConverted = Convert.ToInt32(index);

            switch (axisType)
            {
            case AxisType.X:
                size[0]        = 0;
                indexVector[0] = indexConverted;
                break;

            case AxisType.Y:
                size[1]        = 0;
                indexVector[1] = indexConverted;
                break;

            case AxisType.Z:
                size[2]        = 0;
                indexVector[2] = indexConverted;
                break;

            default:
                break;
            }

            var filter = new ExtractImageFilter();

            filter.SetSize(size);
            filter.SetIndex(indexVector);

            return(filter.Execute(image));
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public Image ExtractPosition(Image image, AxisType axisType, int index)
        {
            Ensure.ArgumentNotNull(image, nameof(image));

            var size        = image.GetSize();
            var indexVector = new VectorInt32 {
                0, 0, 0
            };
            int indexConverted = Convert.ToInt32(index);

            switch (axisType)
            {
            case AxisType.X:
                size[0]        = 0;
                indexVector[0] = indexConverted;
                break;

            case AxisType.Y:
                size[1]        = 0;
                indexVector[1] = indexConverted;
                break;

            case AxisType.Z:
                size[2]        = 0;
                indexVector[2] = indexConverted;
                break;

            default:
                break;
            }

            ExtractImageFilter filter = new ExtractImageFilter();

            filter.SetSize(size);
            filter.SetIndex(indexVector);
            Image output = filter.Execute(image);

            filter.Dispose();

            return(output);
        }
            public bool IsUnderAttack(VectorInt32 d, int value, int length)
            {
                var a = 0;

                for (int i = 1; i <= length + 1; i++)
                {
                    var o = d * i;
                    var t = ByOffset(o.X, o.Y);

                    if (t != null)
                    {
                        if (t.Value == value)
                            a++;
                        else
                        {
                            //if (t.Value == -value)
                            //    a--;

                            break;
                        }
                    }
                }

                if (a > 0)
                {
                    for (int i = 1; i < length; i++)
                    {
                        var o = d * -i;
                        var t = ByOffset(o.X, o.Y);

                        if (t != null)
                        {
                            if (t.Value == value)
                                a++;
                            else
                            {
                                //if (t.Value == -value)
                                //    a--;

                                break;
                            }
                        }
                    }
                }

                return a >= length;
            }
Esempio n. 8
0
        public Bitmap konwertujObraz(Image obraz1, int przekroj = 0)
        {
            uint r = obraz1.GetWidth();
            //  VectorUInt32 w = new VectorUInt32(new[] { r, 512, 4 + 1 });

            VectorInt32 start = new VectorInt32(new[]{ 0, 0, 0 });
            VectorInt32 size1 = new VectorInt32(new[]{ 512, 512, 1 });
                obraz1 = WybierzPrzekroj(obraz1, przekroj);
                IntensityWindowingImageFilter normalize = new IntensityWindowingImageFilter();
                normalize.SetOutputMinimum(0);
                normalize.SetOutputMaximum(255);
                obraz1 = normalize.Execute(obraz1);
            
            PixelIDValueEnum u = PixelIDValueEnum.sitkFloat32;
            int len = 1;
            Image input= SimpleITK.Cast(obraz1, u);
            VectorUInt32 size = input.GetSize();
            for (int dim = 0; dim < input.GetDimension(); dim++)
            {
                len *= (int)size[dim];
            }
            IntPtr buffer = input.GetBufferAsFloat();
            float bufferPtr = (float)buffer.ToInt32();
            float[] bufferAsArray = new float[len]; 
            float[,] newData = new float[size[0], size[1]];
            Marshal.Copy(buffer, bufferAsArray, 0, len);
            obrazBitmap = new Bitmap(Convert.ToInt32(size[0]), Convert.ToInt32(size[1]));
            for (int j = 0; j < size[1]; j++)
            {
                for (int i = 0; i < size[0]; i++)
                {
                    var bur = bufferAsArray[j * size[1] + i];
                    System.Drawing.Color newColor = System.Drawing.Color.FromArgb((int)bur, 0, 0, 0);
                    obrazBitmap.SetPixel(j, i, newColor);
                }
            }
           Color s= obrazBitmap.GetPixel(34, 56);
            return obrazBitmap;
        }