Esempio n. 1
0
        private bool ShowImage()
        {
            try
            {
                DicomElement element = null;
                element = _dsImage.FindFirstElement(null, DemoDicomTags.PixelData, true);
                int bitmapCount = _dsImage.GetImageCount(element);
                if (bitmapCount > 0)
                {
                    FreeImage();
                    if (bitmapCount == 1)
                    {
                        if (element != null)
                        {
                            RasterImage image;

                            image = _dsImage.GetImage(element, 0, 0, RasterByteOrder.Gray, _getImageFlags);

                            _viewer.Image = image;
                        }
                    }
                    else
                    {
                        if (element != null)
                        {
                            LoadBitmapList(element);
                        }
                    }

                    if (element != null)
                    {
                        _imageInfo = _dsImage.GetImageInformation(element, 0);
                    }

                    if ((_dicomAnnotationsUtilities != null) && (_viewer.Image != null))
                    {
                        _dicomAnnotationsUtilities.DisplayWidth  = _viewer.Image.Width;
                        _dicomAnnotationsUtilities.DisplayHeight = _viewer.Image.Height;
                    }

                    return(true);
                }
                else
                {
                    Messager.ShowInformation(this, "Please note that this dataset doesn't include any images.");
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.Assert(false);
                throw exception;
            }
            return(false);
        }
Esempio n. 2
0
        private void LoadImage(object data)
        {
            DicomDataSet ds    = data as DicomDataSet;
            int          count = 0;
            RasterImage  image = null;

            if (Dataset == null)
            {
                Cell.Image = null;
                return;
            }

            count = ds.GetImageCount(null);
            SetLoadProgress(count > 0, count);
            for (int i = 0; i < count; i++)
            {
                RasterImage img = ds.GetImage(null, i, 0, RasterByteOrder.Rgb | RasterByteOrder.Gray, DicomGetImageFlags.AutoApplyVoiLut | DicomGetImageFlags.AutoScaleModalityLut);

                if (image == null)
                {
                    image = img.Clone();
                }
                else
                {
                    image.AddPage(img);
                }
                SetProgressValue(i + 1);
                Thread.Sleep(0);
            }

            SetCellImage(image);
        }
Esempio n. 3
0
        private void LoadDataset(string filename)
        {
            if (_DataView != null)
            {
                _DataView.Dispose();
            }

            _DataView = new DicomDataSet();
            try
            {
                RasterImage image = null;
                int         count = 0;

                _DataView.Load(filename, DicomDataSetLoadFlags.None);
                count = _DataView.GetImageCount(null);
                image = _DataView.GetImages(null, 0, count, 0, RasterByteOrder.Rgb | RasterByteOrder.Gray,
                                            DicomGetImageFlags.AutoApplyVoiLut | DicomGetImageFlags.AutoApplyModalityLut);
                if (image != null)
                {
                    Cell.Image          = image;
                    Cell.FitImageToCell = true;
                    if (image.GrayscaleMode != RasterGrayscaleMode.None)
                    {
                        Cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);
                        Cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.Frame);
                    }
                }
                tabControl.SelectedTab = tabPageViewer;
            }
            catch (Exception e)
            {
                Messager.ShowError(this, e);
            }
        }
Esempio n. 4
0
        private void LoadImage(RasterImage image)
        {
            int count = 0;

            Clear();
            if (image == null)
            {
                count = _DataSet.GetImageCount(null);
                if (count > 0)
                {
#if !LEADTOOLS_V20_OR_LATER
                    DicomGetImageFlags getImageFlags =
                        DicomGetImageFlags.AutoApplyModalityLut |
                        DicomGetImageFlags.AutoApplyVoiLut |
                        DicomGetImageFlags.AutoScaleModalityLut |
                        DicomGetImageFlags.AutoScaleVoiLut |
                        DicomGetImageFlags.AutoDectectInvalidRleCompression;
#else
                    DicomGetImageFlags getImageFlags =
                        DicomGetImageFlags.AutoApplyModalityLut |
                        DicomGetImageFlags.AutoApplyVoiLut |
                        DicomGetImageFlags.AutoScaleModalityLut |
                        DicomGetImageFlags.AutoScaleVoiLut |
                        DicomGetImageFlags.AutoDetectInvalidRleCompression;
#endif // #if !LEADTOOLS_V20_OR_LATER

                    image = _DataSet.GetImages(null, 0, count, 0, RasterByteOrder.Rgb | RasterByteOrder.Gray,
                                               getImageFlags);
                }

                animationToolStripMenuItem.Enabled = count > 1;
            }

            if (image != null)
            {
                MedicalViewerCell cell = _MedicalViewer.Cells[0] as MedicalViewerCell;

                cell.Image          = image;
                cell.FitImageToCell = true;
                if (image.GrayscaleMode != RasterGrayscaleMode.None)
                {
                    cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);
                    cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.Frame);
                }

                animationToolStripMenuItem.Enabled = image.PageCount > 1;
            }
        }
Esempio n. 5
0
        private void anonymizefileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            anonymizeopenFileDialog.Multiselect = false;
            anonymizeopenFileDialog.Filter      = "DICOM Files (*.dcm;*.dic)|*.dcm;*.dic|All files (*.*)|*.*";
            if (anonymizeopenFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                DicomDataSet dsAnonymized = new DicomDataSet();

                _ActiveDataSet.Reset();
                try
                {
                    _ActiveDataSet.Load(anonymizeopenFileDialog.FileName, DicomDataSetLoadFlags.None);
                    dsAnonymized = Anonymize();

                    AnonymizedInfo info = new AnonymizedInfo()
                    {
                        AnonymizedDataset = dsAnonymized
                    };

                    //
                    // Store the image count as a tag of the first node.  This is so we don't have to query the dataset during the Idle event.
                    //
                    if (treeGridViewTags.Nodes.Count > 0)
                    {
                        DicomElement element = dsAnonymized.FindFirstElement(null, DicomTag.PixelData, true);

                        if (element != null)
                        {
                            info.ImageCount = dsAnonymized.GetImageCount(element);
                        }
                    }
                    treeGridViewDifference.Tag = info;
                }
                catch (Exception exception)
                {
                    Messager.ShowError(this, exception);
                }
                finally
                {
                    ToggleProgress(false);
                }
            }
        }
Esempio n. 6
0
        void Convert(DicomDataSet ds)
        {
            DicomElement element;

            element = ds.FindFirstElement(null, DemoDicomTags.PixelData, true);
            if (element == null)
            {
                continue;
            }

            for (int i = 0; i < ds.GetImageCount(element); i++)
            {
                RasterImage           image;
                DicomImageInformation info = ds.GetImageInformation(element, i);
                image = ds.GetImage(element, i, 0, info.IsGray ? RasterByteOrder.Gray : RasterByteOrder.Rgb,
                                    DicomGetImageFlags.AutoApplyModalityLut |
                                    DicomGetImageFlags.AutoApplyVoiLut |
                                    DicomGetImageFlags.AllowRangeExpansion);
                //ds.
            }
        }
Esempio n. 7
0
        private void toolStripButtonRefresh_Click(object sender, EventArgs e)
        {
            DicomDataSet   dsAnonymized = Anonymize();
            AnonymizedInfo info         = new AnonymizedInfo()
            {
                AnonymizedDataset = dsAnonymized
            };

            //
            // Store the image count as a tag of the first node.  This is so we don't have to query the dataset during the Idle event.
            //
            if (treeGridViewTags.Nodes.Count > 0)
            {
                DicomElement element = dsAnonymized.FindFirstElement(null, DicomTag.PixelData, true);

                if (element != null)
                {
                    info.ImageCount = dsAnonymized.GetImageCount(element);
                }
            }
            treeGridViewDifference.Tag = info;
        }
Esempio n. 8
0
        private DicomDataSet Anonymize()
        {
            DicomDataSet dsAnonymized = new DicomDataSet();

            try
            {
                DicomElement pixelData = null;

                pixelData = _ActiveDataSet.FindFirstElement(null, DicomTag.PixelData, true);
                _Anonymizer.BlackoutRects.Clear();
                if (toolStripButtonRedact.Checked && pixelData != null && _ActiveDataSet.GetImageCount(pixelData) > 0)
                {
                    using (SelectBlackoutRectsDialog dlgRects = new SelectBlackoutRectsDialog(_ActiveDataSet))
                    {
                        if (dlgRects.ShowDialog(this) == DialogResult.OK && dlgRects.BlackoutRects.Count > 0)
                        {
                            _Anonymizer.BlackoutRects.AddRange(dlgRects.BlackoutRects);
                        }
                    }
                }

                if (_ActiveDataSet.InformationClass != DicomClassType.BasicDirectory)
                {
                    dsAnonymized.Copy(_ActiveDataSet, null, null);
                    ToggleProgress(true);
                    _Anonymizer.Anonymize(dsAnonymized);
                    ShowDifference(_ActiveDataSet, dsAnonymized);
                }
            }
            catch (Exception exception)
            {
                Messager.ShowError(this, exception);
            }
            finally
            {
                ToggleProgress(false);
            }
            return(dsAnonymized);
        }
Esempio n. 9
0
        private void LoadImage(object data)
        {
            DicomDataSet ds    = data as DicomDataSet;
            int          count = 0;
            RasterImage  image = null;

            if (Dataset == null)
            {
                Cell.Image = null;
                return;
            }

            bool         isStructuredDisplay = IsStructuredDisplay(ds);
            DicomElement pixelData           = ds.FindFirstElement(null, DicomTag.PixelData, true);

            if (pixelData == null)
            {
                if (isStructuredDisplay)
                {
                    count = 1;
                }
            }
            else
            {
                count = ds.GetImageCount(pixelData);
            }

            SetLoadProgress(count > 0, count);
            string exceptionMessage = string.Empty;

            for (int i = 0; i < count; i++)
            {
                RasterImage img = null;

                try
                {
                    if (pixelData != null)
                    {
                        img = ds.GetImage(pixelData, i, 0, RasterByteOrder.Rgb | RasterByteOrder.Gray, DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut | DicomGetImageFlags.AutoScaleModalityLut | DicomGetImageFlags.AutoScaleVoiLut | DicomGetImageFlags.AutoDetectInvalidRleCompression);
                    }
                    else if (isStructuredDisplay)
                    {
                        StructuredDisplayImageOptions sdOptions = new StructuredDisplayImageOptions();
                        sdOptions.ShowOverlay = _optionsAgent.Get <bool>("ExportLayoutIncludeMetadata", true);
                        DicomGetImageFlags getImageFlags = DicomGetImageFlags.AutoScaleModalityLut | DicomGetImageFlags.AutoScaleVoiLut | DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut;
                        img = ds.GetStructuredDisplayImage(GetSopInstanceCallBack, getImageFlags, sdOptions);;
                    }
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                }

                if (img != null)
                {
                    if (image == null)
                    {
                        image = img.Clone();
                    }
                    else
                    {
                        image.AddPage(img);
                    }
                }
                SetProgressValue(i + 1);
                Thread.Sleep(0);
            }

            string photometricInterpretation = GetDicomTag(ds, DicomTag.PhotometricInterpretation);

            if (!string.IsNullOrEmpty(photometricInterpretation))
            {
                Cell.PhotometricInterpretation = photometricInterpretation;
            }

            SetCellInfo(image,
                        ds.GetValue <string>(DicomTag.PatientID, string.Empty),
                        ds.GetValue <string>(DicomTag.PatientName, string.Empty),
                        ds.GetValue <string>(DicomTag.WindowWidth, string.Empty),
                        ds.GetValue <string>(DicomTag.WindowCenter, string.Empty),
                        isStructuredDisplay);

            if (!string.IsNullOrEmpty(exceptionMessage))
            {
                string errorMessage = string.Format("Failed to show image.\n{0}", exceptionMessage);

                if (count > 1)
                {
                    errorMessage = string.Format("Failed to load one or more image frames.\n{0}", exceptionMessage);
                }
                Messager.ShowError(this, errorMessage);
            }
        }