Esempio n. 1
0
        public static void SaveTo(string path, DiVolume volume)
        {
            for (int slice = 0; slice < volume.Slices; slice++)
            {
                MemoryStream ms = new MemoryStream();

                BinaryWriter writer = new BinaryWriter(ms);
                int          rows   = volume.Rows;
                int          cols   = volume.Cols;
                for (int py = 0; py < rows; py++)
                {
                    for (int px = 0; px < cols; px++)
                    {
                        writer.Write((short)((volume[slice, py, px] / 255f) * 4095));
                    }
                }


                writer.Close();

                EvilDICOM.Core.DICOMObject obj = new EvilDICOM.Core.DICOMObject(new List <EvilDICOM.Core.Interfaces.IDICOMElement>()
                {
                    new UnsignedShort(new Tag("0028", "0010"), (ushort)volume.Rows),
                    new UnsignedShort(new Tag("0028", "0011"), (ushort)volume.Cols),
                    new OtherByteString(TagHelper.PIXEL_DATA, ms.ToArray())
                });

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                obj.Write(path + "\\slice" + slice + ".dcm");
            }
        }
Esempio n. 2
0
        private Bitmap GetSliceXZImageFor(DiVolume image, int selectedSlice)
        {
            Bitmap bitmap = new Bitmap(image.Cols, image.Slices);

            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            Parallel.For(0, image.Slices, pz =>
            {
                unsafe
                {
                    for (int px = 0; px < image.Cols; px++)
                    {
                        var value = image.Data[pz, selectedSlice, px];
                        *(((int *)data.Scan0) + pz * image.Cols + px) = ColorFrom(value).ToArgb();
                    }
                }
            });

            bitmap.UnlockBits(data);

            return(bitmap);
        }
Esempio n. 3
0
        private Bitmap UpdateSliceYZImageFor(Bitmap bitmap, DiVolume image, int selectedSlice)
        {
            {
                BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                Parallel.For(0, image.Rows, py =>
                {
                    unsafe
                    {
                        for (int pz = 0; pz < image.Slices; pz++)
                        {
                            var value = image.Data[pz, py, selectedSlice];
                            *(((int *)data.Scan0) + py * image.Slices + pz) = ColorFrom(value).ToArgb();
                        }
                    }
                });

                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
Esempio n. 4
0
        private void load_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browser = new FolderBrowserDialog();

            browser.SelectedPath = Application.StartupPath;
            if (browser.ShowDialog() == DialogResult.OK)
            {
                var dirs = Directory.GetDirectories(browser.SelectedPath).OrderBy(d => int.Parse(Path.GetFileName(d))).ToArray();
                volumes = new List <DiVolume>();
                images  = new byte[dirs.Count()][, , ];

                int counter = 0;
                foreach (var dir in dirs)
                {
                    var data = DiVolume.LoadFrom(dir);

                    images[counter]  = data;
                    byte[,,] newdata = data;
                    switch (useFilter)
                    {
                    case 0:
                        newdata = Filter.GaussianFilter(data, false);
                        break;

                    case 1:
                        newdata = Filter.MeanFilter(data, false);
                        break;

                    case 2:
                        newdata = Filter.MedianFilter(data, false);
                        break;

                    case 3:
                        newdata = Filter.BilateralFilter(data, false);
                        break;

                    case 4:
                        newdata = Filter.PrewittFilter(data);
                        break;

                    case 5:
                        newdata = Filter.SobelFilter(data);
                        break;

                    case 6:
                        newdata = Filter.RobertsFilter(data);
                        break;

                    case 7:
                        newdata = Filter.LoGFilter(data);
                        break;

                    case 8:
                        newdata = Filter.GaussianFilter(data, true);
                        break;

                    case 9:
                        newdata = Filter.MeanFilter(data, true);
                        break;

                    case 10:
                        newdata = Filter.MedianFilter(data, true);
                        break;

                    case 11:
                        newdata = Filter.BilateralFilter(data, true);
                        break;

                    case 12:
                        newdata = Filter.CotrastSt(data);
                        break;

                    case 13:
                        newdata = Filter.HistogramEqualization(data);
                        break;

                    default:
                        break;
                    }
                    var volume = new DiVolume(newdata);

                    //if (counter == 0)
                    //{
                    float limit;
                    float[,,] edge = Edge(newdata, out limit);

                    StreamWriter bw = new StreamWriter("pointCloud" + counter + ".xyz");

                    for (int pz = 0; pz < edge.GetLength(0); pz++)
                    {
                        for (int py = 0; py < edge.GetLength(1); py++)
                        {
                            for (int px = 0; px < edge.GetLength(2); px++)
                            {
                                var a = pz;
                                if (edge[pz, py, px] > limit)
                                {
                                    bw.WriteLine(a + " " + py + " " + px);
                                }
                            }
                        }
                    }
                    bw.Close();
                    //}

                    volumes.Add(volume);

                    vWidth  = volume.Cols;
                    vHeight = volume.Rows;
                    vSlices = volume.Slices;

                    SetStage("Loading...", (++counter) / (float)dirs.Length);
                }

                sliceXY = new Bitmap(vWidth, vHeight);
                sliceXZ = new Bitmap(vWidth, vSlices);
                sliceYZ = new Bitmap(vSlices, vHeight);

                SetCursorAt(vWidth / 2, vHeight / 2, vSlices / 2);

                selector.Minimum = 0;
                selector.Maximum = volumes.Count - 1;
                selector.Value   = 0;

                SelectImage(0);
            }
        }
        private void load_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browser = new FolderBrowserDialog();

            browser.SelectedPath = Application.StartupPath;
            if (browser.ShowDialog() == DialogResult.OK)
            {
                var dirs = Directory.GetDirectories(browser.SelectedPath).OrderBy(d => int.Parse(Path.GetFileName(d))).ToArray();
                volumes = new List <DiVolume>();
                images  = new byte[dirs.Count()][, , ];

                int counter = 0;
                foreach (var dir in dirs)
                {
                    var data = DiVolume.LoadFrom(dir);
                    images[counter]  = data;
                    byte[,,] newdata = data;
                    switch (useFilter)
                    {
                    case 0:
                        newdata = Filter.GaussianFilter(data, false);
                        break;

                    case 1:
                        newdata = Filter.MeanFilter(data, false);
                        break;

                    case 2:
                        newdata = Filter.MedianFilter(data, false);
                        break;

                    case 3:
                        newdata = Filter.BilateralFilter(data, false);
                        break;

                    case 4:
                        newdata = Filter.PrewittFilter(data);
                        break;

                    case 5:
                        newdata = Filter.SobelFilter(data);
                        break;

                    case 6:
                        newdata = Filter.RobertsFilter(data);
                        break;

                    case 7:
                        newdata = Filter.LoGFilter(data);
                        break;

                    case 8:
                        newdata = Filter.GaussianFilter(data, true);
                        break;

                    case 9:
                        newdata = Filter.MeanFilter(data, true);
                        break;

                    case 10:
                        newdata = Filter.MedianFilter(data, true);
                        break;

                    case 11:
                        newdata = Filter.BilateralFilter(data, true);
                        break;

                    case 12:
                        newdata = Filter.CotrastSt(data);
                        break;

                    case 13:
                        newdata = Filter.HistogramEqualization(data);
                        break;

                    default:
                        break;
                    }
                    var volume = new DiVolume(newdata);

                    volumes.Add(volume);

                    vWidth  = volume.Cols;
                    vHeight = volume.Rows;
                    vSlices = volume.Slices;

                    SetStage("Loading...", (++counter) / (float)dirs.Length);
                }

                sliceXY = new Bitmap(vWidth, vHeight);
                sliceXZ = new Bitmap(vWidth, vSlices);
                sliceYZ = new Bitmap(vSlices, vHeight);

                SetCursorAt(vWidth / 2, vHeight / 2, vSlices / 2);

                selector.Minimum = 0;
                selector.Maximum = volumes.Count - 1;
                selector.Value   = 0;

                SelectImage(0);
            }
        }