Example #1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            Image3D image;

            //string testPath = @"MANIX\CER-CT\ANGIO CT";
            //string testPath = @"BRAINIX\SOUS - 702";
            //string testPath = @"BRAINIX\T2W-FE-EPI - 501";
            string testPath = @"vtkBrain";

            double min, max;
            using (var reader = new DicomReader(TestData.GetPath(testPath)))
            {
                image = reader.ReadImage3D();

                min = reader.MinValue;
                max = reader.MaxValue;
            }

            display = new DisplayImage(image.LengthX, image.LengthY);

            var tf = new TransferFunction1D();
            tf.Add(0, Color.Black);
            tf.Add(max * 0.2, Color.Blue);
            tf.Add(max * 0.6, Color.Red);
            tf.Add(max, Color.Yellow);

            renderer = new TransferFunctionRenderer(image, display, tf);

            scrollBarSlice.Maximum = image.LengthZ - 1;
            pictureBoxDisplay.Image = display.GetBitmap();

            Render();
        }
Example #2
0
 protected override void OnValidate(Image3D image)
 {
     base.OnValidate(image);
     tf = tfBuilder.CreateTransferFunction();
 }
Example #3
0
        public TransferFunction1D CreateTransferFunction()
        {
            var tf = new TransferFunction1D();

            var sortedItems = from i in Items orderby i.Value select i;

            foreach (var item in sortedItems)
            {
                tf.Add(item.Value, item.Color);
            }

            return tf;
        }
Example #4
0
 protected override void OnValidate(Image3D image)
 {
     if (image.LengthZ != 1) { throw new LogException("can only render Images with exactly one slice"); }
     tf = tfBuilder.CreateTransferFunction();
 }
Example #5
0
        public void Render(DisplayImage display, TransferFunction1D tf)
        {
            // find max value
            int histogramMax = 0;
            int histogramMax2 = 0;
            int histogramSum = 0;
            for (int i = 0; i < histogramValues.Length; i++)
            {
                var v = histogramValues[i];
                if (v > histogramMax)
                {
                    histogramMax2 = histogramMax;
                    histogramMax = v;
                }

                if (v > histogramMax2 && v < histogramMax)
                {
                    histogramMax2 = v;
                }
                histogramSum += v;
            }

            int histogramHeight = histogramSum * 4 / Count; // TODO: find a suitable height function

            if (histogramHeight == 0) { histogramHeight = 1; } // avoid division by 0 error

            // draw histogram values
            int displayHeight = display.Height;
            int displayWidth = display.Width;

            double delta = (Maximum - Minimum) / Count;

            for (int x = 0; x < displayWidth; x++)
            {
                int histogramIndexStart = (x * Count) / (displayWidth);
                int histogramIndexEnd = ((x + 1) * Count) / (displayWidth);

                int sum = 0;
                for (int i = histogramIndexStart; i < histogramIndexEnd; i++)
                {
                    sum += histogramValues[i];
                }

                int barHeight = Math.Min(displayHeight, (sum * displayHeight) / histogramHeight);

                Color tfColor = tf.GetColor(Minimum + delta * x);
                for (int y = 0; y < 3; y++)
                {
                    display.SetPixel(x, y, tfColor);
                }
                for (int y = 3; y < (displayHeight - barHeight); y++)
                {
                    if (y >= display.Height) { break; }
                    display.SetPixel(x, y, Colors.Transparent);
                }
                for (int y = (displayHeight - barHeight); y < displayHeight; y++)
                {
                    if (y >= display.Height) { break; }
                    display.SetPixel(x, y, tfColor);
                }
            }
        }