예제 #1
0
        public void UpdateDataAfterCommand()
        {
            if (_viewer.Image.GrayscaleMode != RasterGrayscaleMode.None)
            {
                switch (_viewer.Image.BitsPerPixel)
                {
                case 8:
                    _currentPalette = _viewer.Image.GetPalette();
                    _LUTSize        = 256;
                    _minValue       = 0;
                    _maxValue       = 255;
                    _isWLImage      = true;
                    break;

                case 12:
                case 16:
                    _viewer.Image.UseLookupTable = true;
                    _currentPalette = _viewer.Image.GetLookupTable();
                    _highBit        = _viewer.Image.HighBit;
                    if (_highBit == -1)
                    {
                        _highBit = _viewer.Image.BitsPerPixel - 1;
                    }
                    if (_currentPalette == null)
                    {
                        _LUTSize  = (int)Math.Pow(2, _highBit + 1);
                        _maxValue = (_viewer.Image.Signed) ? _LUTSize / 2 - 1 : _LUTSize - 1;
                        _minValue = (_viewer.Image.Signed) ? -_LUTSize / 2 : 0;
                        createPalette();
                    }
                    else
                    {
                        _LUTSize = _currentPalette.Length;
                        MinMaxValuesCommand minMaxValueCmd = new MinMaxValuesCommand();
                        minMaxValueCmd.Run(_viewer.Image);
                        _maxValue = minMaxValueCmd.MaximumValue;
                        _minValue = minMaxValueCmd.MinimumValue;
                    }
                    _isWLImage = true;
                    break;
                }
                _scale    = ((_maxValue - _minValue) / 1000 > 0) ? (_maxValue - _minValue) / 1000 : 1;
                _maxWidth = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) - 1;
                _minWidth = 1;
                _maxLevel = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) - 1;
                _minLevel = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) * -1 + 1;

                if (_viewer.Image.Signed)
                {
                    _flags |= RasterPaletteWindowLevelFlags.Signed;
                    getWindowLevelForSigned(_currentPalette);
                }
                else
                {
                    getWindowLevelForUnSigned(_currentPalette);
                }
            }
        }
예제 #2
0
        private void ChangeThePalette()
        {
            if (_viewer.Image.BitsPerPixel == 1)
            {
                return;
            }
            try
            {
                int low = (int)(_windowLevelCenter - _windowLevelWidth / 2.0);
                int high = (int)(_windowLevelCenter + _windowLevelWidth / 2.0);
                int minValue, maxVale;

                _currentPalette = new RasterColor[_LUTSize];

                MinMaxValuesCommand cmd = new MinMaxValuesCommand();
                cmd.Run(_viewer.Image);
                minValue = cmd.MinimumValue;
                maxVale  = cmd.MaximumValue;

                RasterPalette.WindowLevelFillLookupTable(
                    _currentPalette,
                    new RasterColor(0, 0, 0),
                    new RasterColor(255, 255, 255),
                    low,
                    high,
                    _viewer.Image.LowBit,
                    _highBit,
                    minValue,
                    maxVale,
                    0,
                    _flags);

                if (_viewer.Image.BitsPerPixel == 8)
                {
                    _viewer.Image.SetPalette(_currentPalette, 0, _currentPalette.Length);
                }
                else
                {
                    _viewer.Image.WindowLevel(
                        _viewer.Image.LowBit,
                        _highBit,
                        _currentPalette,
                        RasterWindowLevelMode.PaintAndProcessing);
                }
            }
            catch (Exception /*ex*/)
            {
            }
        }
예제 #3
0
        public HistogramDlg(RasterImage image, bool isGray)
        {
            InitializeComponent();;
            _value       = new long[500];
            _graph       = _pnlHistogram.CreateGraphics();
            _isGrayScale = isGray;

            if (_isGrayScale)
            {
                MinMaxValuesCommand cmd = new MinMaxValuesCommand();
                cmd.Run(image);
                _imageMinValue = cmd.MinimumValue;
                _imageMaxValue = cmd.MaximumValue;
            }
            _image = image;
        }
예제 #4
0
        public void ApplyWindowLeveling( )
        {
            try
            {
                if (image != null && image.IsGray)
                {
                    if (image.MaxValue == 0)
                    {
                        MinMaxValuesCommand cmd = new MinMaxValuesCommand();
                        cmd.Run(image);
                        image.MinValue = cmd.MinimumValue;
                        image.MaxValue = cmd.MaximumValue;
                    }

                    MinMaxValuesCommand minMaxCommand = new MinMaxValuesCommand();

                    minMaxCommand.Run(image);
                    image.MinValue = minMaxCommand.MinimumValue;
                    image.MaxValue = minMaxCommand.MaximumValue;
                    ApplyLinearVoiLookupTableCommand voiCommand = new ApplyLinearVoiLookupTableCommand();
                    if (ReverseOrder)
                    {
                        voiCommand.Flags = VoiLookupTableCommandFlags.ReverseOrder;
                    }
                    else
                    {
                        voiCommand.Flags = VoiLookupTableCommandFlags.None;
                    }

                    voiCommand.Center = _WindowCenter;
                    voiCommand.Width  = _WindowWidth;
                    voiCommand.Run(image);
                }
            }
            catch
            {
            }
        }
예제 #5
0
        void UpdateControls()
        {
            try
            {
                _lblPage.Text            = string.Format("Page {0}:{1}", _image.Page, _image.PageCount);
                _btnPageFirst.Enabled    = _image.Page > 1;
                _btnPagePrevious.Enabled = _image.Page > 1;
                _btnPageNext.Enabled     = _image.Page < _image.PageCount;
                _btnPageLast.Enabled     = _image.Page < _image.PageCount;

                int index = 0;
                _lvInfo.Items[index++].SubItems[1].Text = _image.OriginalFormat.ToString();
                _lvInfo.Items[index++].SubItems[1].Text = string.Format("{0} x {1} pixels", _image.Width, _image.Height);
                _lvInfo.Items[index++].SubItems[1].Text = string.Format("{0} x {1} dpi", _image.XResolution, _image.YResolution);
                _lvInfo.Items[index++].SubItems[1].Text = _image.BitsPerPixel.ToString();
                _lvInfo.Items[index++].SubItems[1].Text = _image.BytesPerLine.ToString();
                _lvInfo.Items[index++].SubItems[1].Text = _image.DataSize.ToString();
                _lvInfo.Items[index++].SubItems[1].Text = Constants.GetNameFromValue(typeof(RasterViewPerspective), _image.ViewPerspective);
                _lvInfo.Items[index++].SubItems[1].Text = Constants.GetNameFromValue(typeof(RasterByteOrder), _image.Order);
                _lvInfo.Items[index++].SubItems[1].Text = _image.HasRegion ? "Yes" : "No";
                if (_image.IsCompressed)
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Run Length Limited (RLE)";
                }
                else
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Not compressed";
                }

                if (_image.IsDiskMemory)
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Disk";
                }
                else if (_image.IsTiled)
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Tiled";
                }
                else if (_image.IsConventionalMemory)
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Managed memory";
                }
                else
                {
                    _lvInfo.Items[index++].SubItems[1].Text = "Unmanaged memory";
                }

                _lvInfo.Items[index++].SubItems[1].Text = _image.Signed ? "Yes" : "No";
                _lvInfo.Items[index++].SubItems[1].Text = Constants.GetNameFromValue(typeof(RasterGrayscaleMode), _image.GrayscaleMode);

                _lvInfo.Items[index++].SubItems[1].Text = _image.LowBit.ToString();
                _lvInfo.Items[index++].SubItems[1].Text = _image.HighBit.ToString();


                bool useLookup = _image.UseLookupTable;
                _image.UseLookupTable = false;

                int MinValue = 0;
                int MaxClrVal;

                if (_image.UseLookupTable == true)
                {
                    MinValue  = 0;
                    MaxClrVal = 255;
                }
                else
                {
                    int HighBit = (_image.HighBit > 0) ? _image.HighBit : (_image.BitsPerPixel - 1);
                    int LowBit  = (_image.LowBit < 0) ? 0 : _image.LowBit;
                    if (_image.Order == RasterByteOrder.Gray || _image.BitsPerPixel >= 48)
                    {
                        if (_image.BitsPerPixel == 16 || _image.BitsPerPixel == 12)
                        {
                            MaxClrVal = (1 << ((HighBit - LowBit) + 1)) - 1;
                        }
                        else
                        {
                            MaxClrVal = 0xffff;
                        }
                    }
                    else
                    {
                        MaxClrVal = 0xff;
                    }
                }

                StatisticsInformationCommand command = new StatisticsInformationCommand();

                command.Channel = RasterColorChannel.Master;
                command.Start   = MinValue;
                command.End     = MaxClrVal;
                command.Run(_image);
                _image.UseLookupTable = useLookup;

                _lvInfo.Items[index++].SubItems[1].Text = Math.Round(command.Mean, 2).ToString();
                _lvInfo.Items[index++].SubItems[1].Text = Math.Round(command.StandardDeviation, 2).ToString();
                _lvInfo.Items[index++].SubItems[1].Text = command.Median.ToString();

                if ((_image.BitsPerPixel == 8 || _image.BitsPerPixel == 12 || _image.BitsPerPixel == 16) && _image.GrayscaleMode != RasterGrayscaleMode.None)
                {
                    MinMaxValuesCommand cmd = new MinMaxValuesCommand();
                    cmd.Run(_image);
                    _lvInfo.Items[index++].SubItems[1].Text = cmd.MinimumValue.ToString();
                    _lvInfo.Items[index++].SubItems[1].Text = cmd.MaximumValue.ToString();
                }
                else
                {
                    _lvInfo.Items[index++].SubItems[1].Text = _image.MinValue.ToString();
                    _lvInfo.Items[index++].SubItems[1].Text = _image.MaxValue.ToString();
                }

                _lvInfo.Items[index++].SubItems[1].Text = command.PixelCount.ToString();
            }
            catch (Exception)
            {
            }
        }
예제 #6
0
        private void ApplyFilter()
        {
            try
            {
                RasterImage runImage = _originalBitmap.Clone();

                if (_cbInvert.Checked)
                {
                    runImage.UseLookupTable = false;
                    InvertCommand invComd = new InvertCommand();
                    invComd.Run(runImage);
                }

                BackGroundRemovalCommand backgroundRemovalCommand = new BackGroundRemovalCommand(Convert.ToInt32(_numRemovalFactor.Value));
                backgroundRemovalCommand.Run(runImage);

                MinMaxValuesCommand minMaxCmd = new MinMaxValuesCommand();
                minMaxCmd.Run(runImage);
                int min = minMaxCmd.MinimumValue;
                int max = minMaxCmd.MaximumValue;

                if (_cbEnableEnhancements.Checked)
                {
                    AverageCommand avrcmd = new AverageCommand();
                    avrcmd.Dimension = 5;
                    avrcmd.Run(runImage);

                    MultiscaleEnhancementCommand MSECommand = new MultiscaleEnhancementCommand();
                    MSECommand.Contrast            = Convert.ToInt32(_numContrast.Value * 100);
                    MSECommand.EdgeCoefficient     = Convert.ToInt32(_numEdgeCoef.Value * 100);
                    MSECommand.EdgeLevels          = Convert.ToInt32(_numEdgeLevel.Value);
                    MSECommand.LatitudeCoefficient = 140;
                    MSECommand.LatitudeLevels      = 5;
                    MSECommand.Flags = MultiscaleEnhancementCommandFlags.EdgeEnhancement | MultiscaleEnhancementCommandFlags.LatitudeReduction;
                    MSECommand.Type  = MultiscaleEnhancementCommandType.Gaussian;
                    MSECommand.Run(runImage);
                }
                else
                {
                    AverageCommand avrcmd = new AverageCommand();
                    avrcmd.Dimension = 3;
                    avrcmd.Run(runImage);
                }

                ApplyLinearVoiLookupTableCommand voiCmd = new ApplyLinearVoiLookupTableCommand();
                voiCmd.Center = (min + max) / 2;
                voiCmd.Width  = max - min;
                voiCmd.Flags  = VoiLookupTableCommandFlags.UpdateMinMax;
                voiCmd.Run(runImage);

                GetLinearVoiLookupTableCommand voiLutCommand = new GetLinearVoiLookupTableCommand(GetLinearVoiLookupTableCommandFlags.None);
                voiLutCommand.Run(runImage);
                _form.WindowLevelWidth  = (int)voiLutCommand.Width;
                _form.WindowLevelCenter = (int)voiLutCommand.Center;

                _viewer.Image = runImage;
            }
            catch (System.Exception /*ex*/)
            {
            }
        }
예제 #7
0
파일: DROC.cs 프로젝트: khaha2210/radio
        private void AutoApplyWW_WC(MedicalViewerCell cell, int _WW, int _WC)
        {

            try
            {
                if (cell.Image.Order == RasterByteOrder.Gray && cell.Image.BitsPerPixel > 8)
                {
                    // update lookup table

                    try
                    {

                        ApplyLinearVoiLookupTableCommand command = new ApplyLinearVoiLookupTableCommand();
                        MinMaxBitsCommand minMaxBits = new MinMaxBitsCommand();
                        MinMaxValuesCommand minMaxValues = new MinMaxValuesCommand();
                        //if (ADJUST_WOB)
                        //command.Flags = VoiLookupTableCommandFlags.ReverseOrder;
                        // else
                        command.Flags = VoiLookupTableCommandFlags.None;

                        minMaxBits.Run(cell.Image);
                        cell.Image.LowBit = minMaxBits.MinimumBit;
                        cell.Image.HighBit = minMaxBits.MaximumBit;
                        minMaxValues.Run(cell.Image);
                        command.Width = _WW;
                        command.Center = _WC;
                        command.Run(cell.Image);
                        cell.Invalidate();
                        WindowLevelCommand _WindowLevelCommand = new WindowLevelCommand();
                        _WindowLevelCommand.HighBit = cell.Image.HighBit;
                        _WindowLevelCommand.LowBit = cell.Image.LowBit;
                        _WindowLevelCommand.LookupTable = cell.Image.GetLookupTable();
                        //_WindowLevelCommand.Order = RasterByteOrder.Rgb;
                        _WindowLevelCommand.Run(cell.Image);
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            finally
            {

            }
        }
예제 #8
0
파일: DROC.cs 프로젝트: khaha2210/radio
        void ShowWindowLeveling(MedicalViewer _mecViewer)
        {
            try
            {
                if (!_DicomMedicalViewer.IsValidCell()) return;
                RasterImage Img = _CurrCell.Image;
                RasterWindowLevelDialog windowLevelDlg = new RasterWindowLevelDialog();

                int lookupSize;
                MinMaxBitsCommand minMaxBits = new MinMaxBitsCommand();
                MinMaxValuesCommand minMaxValues = new MinMaxValuesCommand();
                RasterColor[] lookupTable;

                minMaxBits.Run(Img);
                minMaxValues.Run(Img);

                lookupSize = (1 << (minMaxBits.MaximumBit - minMaxBits.MinimumBit + 1));
                lookupTable = new RasterColor[lookupSize];


                windowLevelDlg.Image = Img;
                windowLevelDlg.ShowPreview = true;
                windowLevelDlg.ShowRange = true;
                windowLevelDlg.ShowZoomLevel = true;
                windowLevelDlg.ZoomToFit = true;
                windowLevelDlg.LowBit = minMaxBits.MinimumBit;
                windowLevelDlg.HighBit = minMaxBits.MaximumBit;// > 4998 ? 4998 : minMaxBits.MaximumBit;
                windowLevelDlg.High = minMaxValues.MaximumValue;//> 4998 ? 4998 : minMaxValues.MaximumValue;
                windowLevelDlg.Low = minMaxValues.MinimumValue;
                windowLevelDlg.High = minMaxValues.MaximumValue;
                windowLevelDlg.WindowLevelFlags = RasterPaletteWindowLevelFlags.Inside | RasterPaletteWindowLevelFlags.Linear | RasterPaletteWindowLevelFlags.DicomStyle;
                windowLevelDlg.LookupTable = lookupTable;
                windowLevelDlg.Signed = Img.Signed;

                switch (Img.GrayscaleMode)
                {
                    case RasterGrayscaleMode.OrderedNormal:
                        {
                            windowLevelDlg.StartColor = new RasterColor(0, 0, 0);
                            windowLevelDlg.EndColor = new RasterColor(255, 255, 255);

                            break;
                        }

                    case RasterGrayscaleMode.OrderedInverse:
                        {
                            windowLevelDlg.StartColor = new RasterColor(255, 255, 255);
                            windowLevelDlg.EndColor = new RasterColor(0, 0, 0);

                            break;
                        }

                    case RasterGrayscaleMode.NotOrdered:
                        {
                            windowLevelDlg.StartColor = new RasterColor(0, 0, 0);
                            windowLevelDlg.EndColor = new RasterColor(255, 255, 255);

                            break;
                        }

                    default:
                        {
                            MessageBox.Show(Owner,
                                              "Window Level is not supported for this bitmap order",
                                              "Window Level Error",
                                              MessageBoxButtons.OK);

                            //_menuItemColorWindowLevel.Enabled = false;

                            return;
                        }
                }


                if (windowLevelDlg.ShowDialog(Owner) == DialogResult.OK)
                {

                    RasterPalette.WindowLevelFillLookupTable(lookupTable,
                                                              windowLevelDlg.StartColor,
                                                              windowLevelDlg.EndColor,
                                                              windowLevelDlg.Low,
                                                              windowLevelDlg.High,
                                                              windowLevelDlg.LowBit,
                                                              windowLevelDlg.HighBit,
                                                              minMaxValues.MinimumValue,
                                                              minMaxValues.MaximumValue,
                                                              windowLevelDlg.Factor,
                                                              windowLevelDlg.WindowLevelFlags |
                                                              (windowLevelDlg.Signed ? RasterPaletteWindowLevelFlags.Signed : RasterPaletteWindowLevelFlags.None));

                    Img.WindowLevel(windowLevelDlg.LowBit,
                                                        windowLevelDlg.HighBit,
                                                        lookupTable,
                                                        RasterWindowLevelMode.PaintAndProcessing);

                   _CurrCell.Image = Img.CloneAll();
                    _DicomMedicalViewer.try2FreeImage(ref Img);
                }
            }
            catch (Exception ex)
            {
                //Messager.ShowError(this, ex);
            }
            finally
            {
                // UpdateControls();
            }
        }
예제 #9
0
파일: DROC.cs 프로젝트: khaha2210/radio
        private void AutoApplyWW_WC(RasterImage img)
        {
            
            try
            {
                if (lblAppliedLastWL.IsChecked==false || WC == 0 || WW == 0)
                {
                    AllowAppliedWL = false;
                    return;
                }
                using (Leadtools.Commands.Demos.WaitCursor wait = new Leadtools.Commands.Demos.WaitCursor())
                {


                    if (img.Order == RasterByteOrder.Gray && img.BitsPerPixel > 8)
                    {
                        // update lookup table

                        try
                        {

                            ApplyLinearVoiLookupTableCommand command = new ApplyLinearVoiLookupTableCommand();
                            MinMaxBitsCommand minMaxBits = new MinMaxBitsCommand();
                            MinMaxValuesCommand minMaxValues = new MinMaxValuesCommand();
                            if (ADJUST_WOB)
                                command.Flags = VoiLookupTableCommandFlags.ReverseOrder;
                            else
                                command.Flags = VoiLookupTableCommandFlags.None;

                            minMaxBits.Run(img);
                            img.LowBit = minMaxBits.MinimumBit;
                            img.HighBit = minMaxBits.MaximumBit;
                            minMaxValues.Run(img);
                            command.Width = WW;
                            command.Center = WC;
                            command.Run(img);
                            //_CurrCell.Invalidate();
                        }
                        catch
                        {
                        }
                    }



                }
            }
            catch
            {
            }
            finally
            {
               
            }
        }
예제 #10
0
파일: DROC.cs 프로젝트: khaha2210/radio
        private void AutoApplyWW_WC()
        {
            bool AllowAppliedWL = true;
            try
            {
                if (lblAppliedLastWL.IsChecked==false || WC == 0 || WW == 0)
                {
                    AllowAppliedWL = false;
                    return;
                }
                using (Leadtools.Commands.Demos.WaitCursor wait = new Leadtools.Commands.Demos.WaitCursor())
                {


                    if (_CurrCell.Image.Order == RasterByteOrder.Gray && _CurrCell.Image.BitsPerPixel > 8)
                    {
                        // update lookup table

                        try
                        {

                            ApplyLinearVoiLookupTableCommand command = new ApplyLinearVoiLookupTableCommand();
                            MinMaxBitsCommand minMaxBits = new MinMaxBitsCommand();
                            MinMaxValuesCommand minMaxValues = new MinMaxValuesCommand();
                            if (ADJUST_WOB)
                                command.Flags = VoiLookupTableCommandFlags.ReverseOrder;
                            else
                                command.Flags = VoiLookupTableCommandFlags.None;

                            minMaxBits.Run(_CurrCell.Image);
                            _CurrCell.Image.LowBit = minMaxBits.MinimumBit;
                            _CurrCell.Image.HighBit = minMaxBits.MaximumBit;
                            minMaxValues.Run(_CurrCell.Image);
                            command.Width = WW;
                            command.Center = WC;
                            command.Run(_CurrCell.Image);
                            _CurrCell.Invalidate();
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (AllowAppliedWL)
                {
                    _DicomMedicalViewer.SetWindowLevel(_CurrCell, WW, WC);
                    
                }
            }
        }
예제 #11
0
        public void Initialize(ImageInformation info, RasterPaintProperties paintProperties, bool snap)
        {
            _viewer.BeginUpdate();
            UpdatePaintProperties(paintProperties);
            _viewer.Image = info.Image;
            if (_viewer.Image != null)
            {
                _viewer.Image.Changed += new EventHandler <RasterImageChangedEventArgs>(Image_Changed);
            }
            _name = info.Name;
            if (snap)
            {
                Snap();
            }
            UpdateCaption();
            _viewer.EndUpdate();

            _isWLImage  = false;
            _isMagGlass = false;

            if (_viewer.Image.GrayscaleMode != RasterGrayscaleMode.None)
            {
                switch (_viewer.Image.BitsPerPixel)
                {
                case 8:
                    _currentPalette = _viewer.Image.GetPalette();
                    _LUTSize        = 256;
                    _minValue       = 0;
                    _maxValue       = 255;
                    _isWLImage      = true;
                    break;

                case 12:
                case 16:
                    _viewer.Image.UseLookupTable = true;
                    _currentPalette = _viewer.Image.GetLookupTable();
                    _highBit        = _viewer.Image.HighBit;
                    if (_highBit == -1)
                    {
                        _highBit = _viewer.Image.BitsPerPixel - 1;
                    }
                    if (_currentPalette == null)
                    {
                        _LUTSize  = (int)Math.Pow(2, _highBit + 1);
                        _maxValue = (_viewer.Image.Signed) ? _LUTSize / 2 - 1 : _LUTSize - 1;
                        _minValue = (_viewer.Image.Signed) ? -_LUTSize / 2 : 0;
                    }
                    else
                    {
                        _LUTSize = _currentPalette.Length;
                        MinMaxValuesCommand minMaxValueCmd = new MinMaxValuesCommand();
                        minMaxValueCmd.Run(_viewer.Image);
                        _maxValue = minMaxValueCmd.MaximumValue;
                        _minValue = minMaxValueCmd.MinimumValue;
                    }
                    _isWLImage = true;
                    break;
                }
                _scale             = ((_maxValue - _minValue) / 1000 > 0) ? (_maxValue - _minValue) / 1000 : 1;
                _maxWidth          = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) - 1;
                _minWidth          = 1;
                _maxLevel          = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) - 1;
                _minLevel          = (int)Math.Pow(2, _viewer.Image.BitsPerPixel) * -1 + 1;
                _windowLevelCenter = (_maxValue + _minValue) / 2;
                _windowLevelWidth  = _maxValue - _minValue;
                if (_viewer.Image.Signed)
                {
                    _flags |= RasterPaletteWindowLevelFlags.Signed;
                }
                ChangeThePalette();
            }
        }