Exemple #1
0
        private void HistogramDlg_Load(object sender, EventArgs e)
        {
            StatisticsInformationCommand command = new StatisticsInformationCommand();

            try
            {
                command.Channel = RasterColorChannel.Master;
                command.Start   = 0;
                command.End     = 255;
                command.Run(_image);

                if (_isGrayScale)
                {
                    _numRangeMin.Maximum = _numRangeMax.Maximum = _imageMaxValue;
                    _numRangeMin.Minimum = _numRangeMax.Minimum = _imageMinValue;
                }

                _penColor         = Color.Black;
                _pixels           = _image.Width * _image.Height;
                _mean             = command.Mean;
                _numRangeMin.Text = _imageMinValue.ToString();
                _numRangeMax.Text = _imageMaxValue.ToString();
                _median           = command.Median;

                _cmbChanel.SelectedIndex = 0;

                HistogramCommand commandHist = new HistogramCommand();
                commandHist.Channel = HistogramCommandFlags.Master;
                commandHist.Run(_image);
                long[] histogramValues = commandHist.Histogram;

                if (_isGrayScale)
                {
                    switch (_image.BitsPerPixel)
                    {
                    case 1:
                    case 8:
                        _histValues = histogramValues;
                        break;

                    case 16:
                    case 12:
                        int size = (int)Math.Ceiling(Math.Log(_imageMaxValue - _imageMinValue, 2));
                        size = (int)Math.Pow(2, size);
                        if (size == 0)
                        {
                            size++;
                        }
                        _histValues = new long[size];

                        for (int i = _imageMinValue, j = 0; i <= _imageMaxValue; i++, j++)
                        {
                            int x = (i < 0) ? histogramValues.Length + i : i;
                            _histValues[j] = histogramValues[x];
                        }
                        break;
                    }
                    _cmbChanel.Enabled = false;
                }
                else
                {
                    _gbGrayScaleRange.Enabled = false;
                    _histValues     = histogramValues;
                    _lblMax.Enabled = _lblMin.Enabled = false;
                }

                _lblLevel.Text        = DemosGlobalization.GetResxString(GetType(), "Resx_Level") + " = " + _level;
                _lblCount.Text        = DemosGlobalization.GetResxString(GetType(), "Resx_Count") + " = " + 0;
                _lblMax.Text          = DemosGlobalization.GetResxString(GetType(), "Resx_Max") + " = " + _imageMaxValue;
                _lblMin.Text          = DemosGlobalization.GetResxString(GetType(), "Resx_Min") + " = " + _imageMinValue;
                _lblToltalPixels.Text = DemosGlobalization.GetResxString(GetType(), "Resx_ToltalPixels") + " = " + _pixels;
                _lblMean.Text         = DemosGlobalization.GetResxString(GetType(), "Resx_Mean") + " = " + Math.Round(_mean, 2);
                _lblMedian.Text       = DemosGlobalization.GetResxString(GetType(), "Resx_Median") + " = " + _median;
                _lblPercentil.Text    = DemosGlobalization.GetResxString(GetType(), "Resx_Percentil") + " = " + 0 + "%";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
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)
            {
            }
        }
Exemple #3
0
        private void HistogramDlg_Load(object sender, EventArgs e)
        {
            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)
                    {
                        if (_image.Signed)
                        {
                            MaxClrVal = (1 << (HighBit - LowBit)) - 1;
                            MinValue  = -(1 << (HighBit - LowBit));
                        }
                        else
                        {
                            MaxClrVal = (1 << ((HighBit - LowBit) + 1)) - 1;
                        }
                    }
                    else
                    {
                        MaxClrVal = 0xffff;
                    }
                }
                else
                {
                    MaxClrVal = 0xff;
                }
            }

            StatisticsInformationCommand command = new StatisticsInformationCommand();

            try
            {
                command.Channel = RasterColorChannel.Master;
                command.Start   = MinValue;
                command.End     = MaxClrVal;

                command.Run(_image);
                if (_isGrayScale)
                {
                    _numRangeMin.Maximum = _numRangeMax.Maximum = _imageMaxValue;
                    _numRangeMin.Minimum = _numRangeMax.Minimum = _imageMinValue;
                }

                _penColor         = Color.Black;
                _pixels           = _image.Width * _image.Height;
                _mean             = command.Mean;
                _numRangeMin.Text = _imageMinValue.ToString();
                _numRangeMax.Text = _imageMaxValue.ToString();
                _median           = command.Median;

                _cmbChanel.SelectedIndex = 0;

                HistogramCommand commandHist = new HistogramCommand();
                commandHist.Channel = HistogramCommandFlags.Master;
                commandHist.Run(_image);
                long[] histogramValues = commandHist.Histogram;

                if (_isGrayScale)
                {
                    switch (_image.BitsPerPixel)
                    {
                    case 1:
                    case 8:
                        _histValues = histogramValues;
                        break;

                    case 16:
                    case 12:
                        int size = (int)Math.Ceiling(Math.Log(_imageMaxValue - _imageMinValue, 2));
                        size = (int)Math.Pow(2, size);
                        if (size == 0)
                        {
                            size++;
                        }
                        _histValues = new long[size];

                        for (int i = _imageMinValue, j = 0; i <= _imageMaxValue; i++, j++)
                        {
                            int x = (i < 0) ? histogramValues.Length + i : i;
                            _histValues[j] = histogramValues[x];
                        }
                        break;
                    }

                    CheckBestClipping();

                    _cmbChanel.Enabled = false;
                }
                else
                {
                    _gbGrayScaleRange.Enabled = false;
                    _histValues     = histogramValues;
                    _lblMax.Enabled = _lblMin.Enabled = false;
                }

                _lblLevel.Text        = " Level = " + _level;
                _lblCount.Text        = " Count = " + 0;
                _lblMax.Text          = " Max = " + _imageMaxValue;
                _lblMin.Text          = " Min = " + _imageMinValue;
                _lblToltalPixels.Text = " Total Pixels = " + _pixels;
                _lblMean.Text         = " Mean = " + Math.Round(_mean, 2);
                _lblMedian.Text       = " Median = " + _median;
                _lblPercentil.Text    = " Percentil = " + 0 + "%";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }

            _image.UseLookupTable = useLookup;
        }