Inheritance: MonoBehaviour
Esempio n. 1
0
 private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         return((byte)(b >= Threshold ? 255 : 0));
     }, PixelFilter);
 }
Esempio n. 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);
 }
        public unsafe static int[] LineValues(this Image image, int line)
        {
            if (line < 0 || line > image.Height)
            {
                throw new ArgumentException("That line is not possible");
            }

            ImagePlane plane = image.Planes[0];

            var size   = plane.Parent.Size;
            var access = plane.GetLinearAccess();

            var xInc  = access.XInc.ToInt64();
            var yInc  = access.YInc.ToInt64();
            var pBase = (byte *)access.BasePtr;

            int y = line;

            int[] lineValues = new int[size.Width];
            for (int x = 0; x < size.Width; x++)
            {
                var pPixel = pBase + x * xInc + y * yInc;
                lineValues[x] = *pPixel;
            }

            return(lineValues);
        }
Esempio n. 4
0
 private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
 {
     ProcessingHelper.ProcessMono(plane, bounds, (b) =>
     {
         return(ValueProvider.Provide());
     }, PixelFilter);
 }
Esempio n. 5
0
        /*  По умолчанию область*/
        private void Reset_Click(object sender, EventArgs e)
        {
            if (pixels8 != null || pixels16 != null)
            {
                if ((pixels8.Count > 0) || (pixels16.Count > 0))
                {
                    EraseHistogramArray();
                    winWidth             = dec.windowWidth;
                    winCentre            = dec.windowCentre;
                    ImagePlane.viewcolor = false;
                    if (bpp == 8)
                    {
                        if (spp == 1)
                        {
                            ImagePlane.SetParameters(ref pixels8, imageWidth, imageHeight, winWidth, winCentre, spp, false, this, histogram, inkColor);
                        }
                    }

                    if (bpp == 16)
                    {
                        ImagePlane.SetParameters(ref pixels16, intercept, imageWidth, imageHeight, winWidth, winCentre, false, this, ref histogram, inkColor);
                    }
                }
            }
            else
            {
                MessageBox.Show("Загрузите DICOM файл перед восстановлением параметров!");
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Updates <see cref="ImagePlane" /> with <see cref="ImageTexture" />.
        /// </summary>
        public virtual void DisplayImage()
        {
            InitializeImagePlane();
            PlaceImagePlane();

            imagePlaneMaterial.mainTexture = ImageTexture;
            ImagePlane.SetActive(true);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            if (plane.TryGetLinearAccess(out LinearAccessData data))
            {
                int startY      = bounds.StartY;
                int startX      = bounds.StartX;
                int boundsY     = startY + bounds.Height;
                int boundsX     = startX + bounds.Width;
                int imageHeight = plane.Parent.Height;
                int imageWidth  = plane.Parent.Width;
                var yInc        = (int)data.YInc;
                var xInc        = (int)data.XInc;

                unsafe
                {
                    var pBase = (byte *)data.BasePtr;
                    for (int yy = bounds.StartY; yy < boundsY; yy += PixelateSize)
                    {
                        int offsetY        = PixelateSize / 2;
                        int yyPixelateSize = yy + PixelateSize;
                        for (int xx = bounds.StartX; xx < boundsX; xx += PixelateSize)
                        {
                            int offsetX        = PixelateSize / 2;
                            int xxPixelateSize = xx + PixelateSize;

                            while (xx + offsetX >= imageWidth)
                            {
                                offsetX--;
                            }
                            while (yy + offsetY >= imageHeight)
                            {
                                offsetY--;
                            }

                            byte *pPixelatedPixel = pBase + ((yy + offsetY) * yInc) + ((xx + offsetX) * xInc);
                            for (int y = yy; y < yyPixelateSize && y < imageHeight; y++)
                            {
                                byte *pLine = pBase + yInc * y;

                                for (int x = xx; x < xxPixelateSize && x < imageWidth; x++)
                                {
                                    byte *pPixel = pLine + xInc * x;
                                    if (PixelFilter.Check(*pPixel, y * boundsY + x))
                                    {
                                        *pPixel = *pPixelatedPixel;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentException("Plane could not be accessed linearly", nameof(plane));
            }
        }
Esempio n. 9
0
        public unsafe PixelHelper(ImagePlane plane)
        {
            Size   = plane.Parent.Size;
            Access = plane.GetLinearAccess <byte>();

            XInc  = Access.XInc.ToInt64();
            YInc  = Access.YInc.ToInt64();
            PBase = (byte *)Access.BasePtr;
        }
Esempio n. 10
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            var outputPlane = ProcessingHelper.ProcessMonoKernel(plane, (kl) =>
            {
                return(kl.Where(b => b.HasValue).Min(b => b.Value));
            }, KernelSize, bounds, PixelFilter);

            outputPlane.CopyTo(plane.Parent.Planes[plane.Plane]);
        }
Esempio n. 11
0
        private void ProcessPlane(ImagePlane plane, int[] weights, ProcessingBounds bounds, int weightSum)
        {
            var outputPlane = ProcessingHelper.ProcessMonoKernel(plane, (kl) =>
            {
                return(ApplyWeights(kl, weights, weightSum));
            }, KernelSize, bounds, PixelFilter);

            outputPlane.CopyTo(plane.Parent.Planes[plane.Plane]);
        }
        public ImageRenderer()
        {
            imagePlane      = new ImagePlane();
            _viewParametres = new ViewParametres();

            _tools = new ITool[]
            {
                new SelectionTool(this)
            };
        }
Esempio n. 13
0
            /// <summary>
            /// Hides <see cref="ImagePlane"/>.
            /// </summary>
            private void OnDisable()
            {
#if UNITY_EDITOR
                if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    ImagePlane.SetActive(false);
                    Reset();
                }
#endif
            }
Esempio n. 14
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            var outputPlane = ProcessingHelper.ProcessMonoKernel(plane, (kl) =>
            {
                var stripped = kl.Where(b => b.HasValue);
                return((byte)(stripped.Sum(b => b.Value) / stripped.Count()));
            }, KernelSize, bounds, PixelFilter);

            outputPlane.CopyTo(plane.Parent.Planes[plane.Plane]);
        }
Esempio n. 15
0
            /// <summary>
            /// Shows <see cref="ImagePlane"/> and calls <see cref="SetArucoObject"/>.
            /// </summary>
            private void OnEnable()
            {
#if UNITY_EDITOR
                if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && ArucoObject)
                {
                    Create();
                    Display();
                    ImagePlane.SetActive(true);
                }
#endif
            }
Esempio n. 16
0
        private void ProcessPlane(ImagePlane plane, ProcessingBounds bounds)
        {
            var outputPlane = ProcessingHelper.ProcessMonoKernel(plane, (kl) =>
            {
                var stripped = kl.Where(b => b.HasValue).ToArray();
                Array.Sort(stripped);
                return(UseHigherMedian ? stripped[stripped.Length / 2].Value : stripped[(stripped.Length / 2) - 1].Value);
            }, KernelSize, bounds, PixelFilter);

            outputPlane.CopyTo(plane.Parent.Planes[plane.Plane]);
        }
Esempio n. 17
0
 public static ImagePlane ProcessMonoKernel(ImagePlane plane, Func <byte?[], byte> processingFunc, KernelSize kernel, PixelFilterChain filterChain)
 {
     if (filterChain == null || !filterChain.HasActiveFilter)
     {
         return(ProcessMonoKernel(plane, processingFunc, kernel));
     }
     else
     {
         return(ProcessMonoKernel(plane, processingFunc, kernel, new ProcessingBounds(plane.Parent.Bounds), filterChain));
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Processes the pixels of the given <paramref name="plane"/>
 /// with the given <paramref name="processorFunc"/>.
 /// </summary>
 /// <param name="plane">The plane whose pixels to process.</param>
 /// <param name="processorFunc">Func that takes a byte, processes
 /// it and returns a byte.</param>
 /// <param name="filterChain">Optional filter chain.</param>
 public static void ProcessMono(ImagePlane plane, Func <byte, byte> processorFunc, PixelFilterChain filterChain)
 {
     if (filterChain == null || !filterChain.HasActiveFilter)
     {
         ProcessMono(plane, processorFunc);
     }
     else
     {
         ProcessMono(plane, new ProcessingBounds(plane.Parent.Bounds), processorFunc, filterChain);
     }
 }
Esempio n. 19
0
 /// <summary>
 ///     Resets <see cref="Image" />, <see cref="ImageTexture" /> and <see cref="ImagePlane" />.
 /// </summary>
 public virtual void ResetImage()
 {
     Image        = null;
     ImageTexture = null;
     if (imagePlaneMaterial != null)
     {
         imagePlaneMaterial.mainTexture = null;
     }
     if (ImagePlane != null)
     {
         ImagePlane.SetActive(false);
     }
 }
                    /// <summary>
                    /// Creates and returns an initialized version of this struct.
                    /// </summary>
                    /// <param name="width">Width of the image plane.</param>
                    /// <param name="height">Height of the image plane.</param>
                    /// <param name="stride">Stride of the image plane.</param>
                    /// <param name="bytesPerPixel">Bytes per pixel of the image plane.</param>
                    /// <param name="size">Size of the image plane.</param>
                    /// <param name="data">Pointer to the image data for the image plane.</param>
                    /// <param name="bytes">Byte array representation of to the image data for the image plane.</param>
                    /// <returns>An initialized version of this struct.</returns>
                    public static ImagePlane Create(uint width, uint height, uint stride, uint bytesPerPixel, uint size, IntPtr data)
                    {
                        ImagePlane imagePlane = new ImagePlane()
                        {
                            Width         = width,
                            Height        = height,
                            Stride        = stride,
                            BytesPerPixel = bytesPerPixel,
                            Size          = size,
                            Data          = data
                        };

                        return(imagePlane);
                    }
Esempio n. 21
0
 private void forward_Click(object sender, EventArgs e)
 {
     if (image_number < num_of_images)
     {
         pixels16.Clear();
         dec.EraseFields();
         ImagePlane.EraseFields();
         image_number++;
         image_label.Text = path + image_number;
         safename         = "_" + image_number;
         navi             = true;
         ReadAndDisplayDicomFile(path + safename, safename);
     }
 }
Esempio n. 22
0
                /// <summary>
                /// Creates and returns an initialized version of this struct.
                /// </summary>
                /// <param name="width">Width of the image plane.</param>
                /// <param name="height">Height of the image plane.</param>
                /// <param name="stride">Stride of the image plane.</param>
                /// <param name="bytesPerPixel">Bytes per pixel of the image plane.</param>
                /// <param name="size">Size of the image plane.</param>
                /// <param name="data">Pointer to the image data for the image plane.</param>
                /// <param name="byteArrayToUse">Optional byte array to store frame data in managed memory.</param>
                /// <returns>An initialized version of this struct.</returns>
                public static ImagePlane Create(uint width, uint height, uint stride, uint bytesPerPixel, uint size, IntPtr data, byte[] byteArrayToUse = null)
                {
                    ImagePlane imagePlane = new ImagePlane();

                    imagePlane.Width         = width;
                    imagePlane.Height        = height;
                    imagePlane.Stride        = stride;
                    imagePlane.BytesPerPixel = bytesPerPixel;
                    imagePlane.Size          = size;
                    imagePlane.DataPtr       = data;
                    if (byteArrayToUse != null)
                    {
                        imagePlane.Data = byteArrayToUse;
                        Marshal.Copy(data, imagePlane.Data, 0, imagePlane.Data.Length);
                    }
                    return(imagePlane);
                }
Esempio n. 23
0
        /// <summary>
        /// Gets the pixels of the given <paramref name="plane"/>
        /// as a 2D byte array.
        /// </summary>
        /// <param name="plane">Plane to get pixels of.</param>
        /// <returns>Pixels of the given <paramref name="plane"/> as
        /// 2D byte array.</returns>
        public static byte[,] GetPixelsAs2DArray(this ImagePlane plane)
        {
            var inputPixels = plane.GetPixels().ToArray();
            int height      = plane.Parent.Height;
            int width       = plane.Parent.Width;
            var pixels      = new byte[height, width];

            for (int y = 0; y < height; y++)
            {
                int yW = y * width;
                for (int x = 0; x < width; x++)
                {
                    pixels[y, x] = inputPixels[yW + x];
                }
            }

            return(pixels);
        }
Esempio n. 24
0
        /// <summary>
        /// Processes the pixels of the given <paramref name="plane"/>
        /// in the given <paramref name="bounds"/> with the
        /// given <paramref name="processorFunc"/>.
        /// </summary>
        /// <param name="plane">The plane whose pixels to process.</param>
        /// <param name="bounds">Bounds defining which pixels to process.</param>
        /// <param name="processorFunc">Func that takes a byte, processes
        /// it and returns a byte.</param>
        /// <param name="filterChain">Optional filter chain.</param>
        public static void ProcessMono(ImagePlane plane, ProcessingBounds bounds, Func <byte, byte> processorFunc, PixelFilterChain filterChain)
        {
            if (filterChain == null || !filterChain.HasActiveFilter)
            {
                ProcessMono(plane, bounds, processorFunc);
                return;
            }
            if (processorFunc == null)
            {
                throw new ArgumentNullException(nameof(processorFunc));
            }

            if (plane.TryGetLinearAccess(out LinearAccessData data))
            {
                var yInc    = (int)data.YInc;
                var xInc    = (int)data.XInc;
                int startY  = bounds.StartY;
                int startX  = bounds.StartX;
                int boundsY = startY + bounds.Height;
                int boundsX = startX + bounds.Width;
                unsafe
                {
                    var pBase = (byte *)data.BasePtr;

                    Parallel.For(startY, boundsY, (y) =>
                    {
                        byte *pLine = pBase + yInc * y;

                        for (int x = startX; x < boundsX; x++)
                        {
                            byte *pPixel = pLine + xInc * x;
                            if (filterChain.Check(*pPixel, y * boundsY + x))
                            {
                                *pPixel = processorFunc.Invoke(*pPixel);
                            }
                        }
                    });
                }
            }
            else
            {
                throw new ArgumentException("Plane could not be accessed linear", nameof(plane));
            }
        }
Esempio n. 25
0
        /// <summary>
        ///     Initializes <see cref="ImagePlane" />.
        /// </summary>
        protected virtual void InitializeImagePlane()
        {
            // Loads the prefab
            if (ImagePlanePrefab == null)
            {
                ImagePlanePrefab = Resources.Load("ArucoObjectDisplayerImagePlane") as GameObject;
            }

            // Creates the image plane if null
            if (ImagePlane == null)
            {
                // Finds or creates the image plane gameObject
                var imagePlaneTransform = transform.Find(ImagePlanePrefab.name);
                if (imagePlaneTransform != null)
                {
                    ImagePlane = imagePlaneTransform.gameObject;
                }
                else
                {
                    ImagePlane      = Instantiate(ImagePlanePrefab, transform);
                    ImagePlane.name = ImagePlanePrefab.name;
                }

                // Updates the image plane material
#if UNITY_EDITOR
                if (!EditorApplication.isPlayingOrWillChangePlaymode)
#else
                if (Application.isEditor)
#endif
                {
                    var renderer = ImagePlane.GetComponent <Renderer>();
                    imagePlaneMaterial      = new Material(renderer.sharedMaterial);
                    renderer.sharedMaterial = imagePlaneMaterial;
                }
                else
                {
                    imagePlaneMaterial = ImagePlane.GetComponent <Renderer>().material;
                }

                // Don't save in the scene : dynamically generated
                ImagePlane.hideFlags = HideFlags.DontSaveInEditor;
            }
        }
Esempio n. 26
0
        private void test_head_Click(object sender, EventArgs e)
        {
            path = "E:\\tsvme\\DICOM images\\kid\\";

            for (int i = 30; i < 190; i++)
            {
                safename = "_" + Convert.ToString(i);
                pixels16.Clear();
                pixels8.Clear();
                dec.EraseFields();
                ImagePlane.EraseFields();
                Cursor = Cursors.WaitCursor;
                ReadAndDisplayDicomFile(path + safename, safename);
                Cursor           = Cursors.Default;
                image_label.Text = path + safename;
                num_of_images++;
            }
            image_number = num_of_images;
        }
Esempio n. 27
0
        private void Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "All DICOM Files(*.*)|*.*";

            if ((ofd.ShowDialog() == DialogResult.OK) && (ofd.FileName.Length > 0))
            {
                pixels16.Clear();
                pixels8.Clear();
                dec.EraseFields();
                ImagePlane.EraseFields();

                Cursor = Cursors.WaitCursor;
                ReadAndDisplayDicomFile(ofd.FileName, ofd.SafeFileName);
                Cursor           = Cursors.Default;
                image_label.Text = ofd.FileName;
                num_of_images++;
            }
            ofd.Dispose();
        }
        public static unsafe int[] ToHistogram(this ImagePlane plane)
        {
            var histogram = new int[byte.MaxValue + 1];

            var size   = plane.Parent.Size;
            var access = plane.GetLinearAccess();

            var xInc  = access.XInc.ToInt64();
            var yInc  = access.YInc.ToInt64();
            var pBase = (byte *)access.BasePtr;

            for (int y = 0; y < size.Height; y++)
            {
                for (int x = 0; x < size.Width; x++)
                {
                    var pPixel = pBase + x * xInc + y * yInc;
                    ++histogram[*pPixel];
                }
            }
            return(histogram);
        }
Esempio n. 29
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);
 }
Esempio n. 30
0
        private static IDictionary <int, byte> BuildValueDictionary(SmearMode mode, ImagePlane plane, ProcessingBounds bounds)
        {
            var dic = new Dictionary <int, byte>();

            if (mode == SmearMode.VerticalFromTop)
            {
                for (int x = bounds.StartX; x < bounds.StartX + bounds.Width; x++)
                {
                    dic.Add(x, (byte)plane.GetPixel(x, bounds.StartY));
                }
            }
            else if (mode == SmearMode.VerticalFromBottom)
            {
                for (int x = bounds.StartX; x < bounds.StartX + bounds.Width; x++)
                {
                    dic.Add(x, (byte)plane.GetPixel(x, bounds.StartY + bounds.Height - 1));
                }
            }
            else if (mode == SmearMode.HorizontalFromLeft)
            {
                for (int y = bounds.StartY; y < bounds.StartY + bounds.Height; y++)
                {
                    dic.Add(y, (byte)plane.GetPixel(bounds.StartX, y));
                }
            }
            else if (mode == SmearMode.HorizontalFromRight)
            {
                for (int y = bounds.StartY; y < bounds.StartY + bounds.Height; y++)
                {
                    dic.Add(y, (byte)plane.GetPixel(bounds.StartX + bounds.Width - 1, y));
                }
            }
            else
            {
                throw new ArgumentException("Unknown Smear Mode", nameof(mode));
            }

            return(dic);
        }
Esempio n. 31
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   An Image extension method that resize image. </summary>
        /// <remarks>   Aaevans, 2/16/2016. </remarks>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when one or more required arguments are null.
        /// </exception>
        /// <param name="source">       The source to act on. </param>
        /// <param name="dimension">    The dimension. </param>
        /// <param name="plane">        The plane. </param>
        /// <returns>   An Image. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public static Image ResizeImage(this Image source, int dimension, ImagePlane plane)
        {
            if (source == null) throw new ArgumentNullException("source");

            var destWidth = 1;
            var destHeight = 1;

            try
            {
                float factor;
                switch (plane)
                {
                    case ImagePlane.Horizontal:
                        factor = (dimension + 1) / (float)source.Width;
                        destWidth = dimension;
                        destHeight = (int)(source.Height * factor);
                        break;

                    case ImagePlane.Vertical:
                        factor = (dimension + 1) / (float)source.Height;
                        destWidth = (int)(source.Width * factor);
                        destHeight = dimension;
                        break;

                    case ImagePlane.Crop:
                        if (source.Height <= source.Width) factor = (dimension + 1) / (float)source.Height;
                        else factor = (dimension + 1) / (float)source.Width;

                        destWidth = (int)(source.Width * factor);
                        destHeight = (int)(source.Height * factor);
                        break;
                }

                var bmp = new Bitmap(destWidth, destHeight);

                using (var gfx = Graphics.FromImage(bmp))
                {
                    gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    gfx.CompositingQuality = CompositingQuality.HighQuality;
                    gfx.DrawImage(source, 0, 0, destWidth, destHeight);
                }

                Image resizedImage = bmp;
                return resizedImage;
            }
            catch (Exception)
            {
                return null;
            }
        }