Exemple #1
0
        public imageConditionAndData(object inputDenseMatrix, Image <Gray, Byte> binaryMaskImage = null)
        {
            if (inputDenseMatrix.GetType() != typeof(DenseMatrix))
            {
                return;
            }
            dmSourceData = (DenseMatrix)((DenseMatrix)inputDenseMatrix).Clone();
            if (binaryMaskImage == null)
            {
                maskImageBinary = new Image <Gray, byte>(dmSourceData.ColumnCount, dmSourceData.RowCount);
                maskImageBinary.SetValue(new Gray(1));
            }
            else
            {
                maskImageBinary = binaryMaskImage.Copy();
            }
            isImageGrayscaled = false;
            //sourceImageBgr = imgPr.tmpImage.Copy();
            //sourceImageGrayscale = null;

            thresholdingUsageTop = false;
            thresholdingUsageBtm = true;
            thresholdingValue    = 255;


            selection = null;

            currentColorScheme = new ColorScheme("");
            //makeThresholdedDataImage();
            dataHasBeenModified = true;

            HighlightMask   = null;
            highlightedArea = 0.0d;
        }
Exemple #2
0
        public void makeHihghlightMask()
        {
            if (currentColorSchemeRuler.Selection == null)
            {
                return;
            }
            double      maxValue = ((RectangleF)currentColorSchemeRuler.Selection.SelectionRectReal).Top;
            double      minValue = maxValue - ((RectangleF)currentColorSchemeRuler.Selection.SelectionRectReal).Height;
            DenseMatrix tmpDM    = (DenseMatrix)(dmSourceData.Clone());


            DenseMatrix dmToDetermineHighlightedArea = (DenseMatrix)dmSourceData.Clone();

            dmToDetermineHighlightedArea.MapInplace(
                new Func <double, double>(x => ((x < minValue) || (x > maxValue)) ? 0.0d : 1.0d));
            highlightedArea = dmToDetermineHighlightedArea.Values.Sum();

            tmpDM.MapInplace(
                new Func <double, double>((x) =>
            {
                return(((x < minValue) || (x > maxValue)) ? 100.0d : 255.0d);
            }), MathNet.Numerics.LinearAlgebra.Zeros.AllowSkip);

            HighlightMask = ImageProcessing.grayscaleImageFromDenseMatrixWithFixedValuesBounds(tmpDM, 0.0d, 255.0d).Convert <Gray, double>();
            HighlightMask = HighlightMask.Mul(maskImageBinary.Convert <Gray, double>());
            HighlightMask = HighlightMask / 255.0d;

            selection = null;

            dataHasBeenModified = true;
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="imageConditionAndData"/> class.
        /// note: grayscaled, with fixed grayscale ruler 0.0d-255.0d
        /// </summary>
        /// <param name="imgPr">The img pr.</param>
        /// <param name="channelNum">The channel number.</param>
        public imageConditionAndData(ImageProcessing imgPr, int channelNum)
        {
            maskImageBinary      = imgPr.significantMaskImageBinary.Copy();
            isImageGrayscaled    = true;
            sourceImageGrayscale = imgPr.getMaskedImageChannelImage(channelNum);
            sourceImageBgr       = null;

            thresholdingUsageTop = false;
            thresholdingUsageBtm = true;
            thresholdingValue    = 255;

            dmSourceData = ImageProcessing.DenseMatrixFromImage(sourceImageGrayscale);


            currentColorScheme      = new ColorScheme("");
            currentColorSchemeRuler = new ColorSchemeRuler(this, dataMinValue(), dataMaxValue());
            selection = null;


            //makeThresholdedDataImage();
            dataHasBeenModified = true;

            HighlightMask   = null;
            highlightedArea = 0.0d;
        }
Exemple #4
0
 public void ClearSelection()
 {
     selection           = null;
     HighlightMask       = null;
     highlightedArea     = 0.0d;
     dataHasBeenModified = true;
 }
Exemple #5
0
        //attention!
        //int channelNum - zero-based channel number with B-G-R scheme
        public imageConditionAndData(Bitmap coloredBitmap, int channelNum)
        {
            ImageProcessing imgPr = new ImageProcessing(coloredBitmap, true);

            maskImageBinary = imgPr.significantMaskImageBinary;
            //imgPr.Dispose();
            isImageGrayscaled    = true;
            sourceImageGrayscale = new Image <Bgr, Byte>(coloredBitmap)[channelNum];
            sourceImageBgr       = null;
            sourceImageGrayscale = sourceImageGrayscale.Mul(maskImageBinary);

            thresholdingUsageTop = false;
            thresholdingUsageBtm = true;
            thresholdingValue    = 255;

            //Image<Gray, Byte> thresholdedImage = imgPr.getMaskedImageChannelBitmapThresholded(channelNum, thresholdingValue, thresholdingUsageTop, thresholdingUsageBtm);
            dmSourceData = ImageProcessing.DenseMatrixFromImage(sourceImageGrayscale);

            currentColorScheme      = new ColorScheme("");
            currentColorSchemeRuler = new ColorSchemeRuler(this, dataMinValue(), dataMaxValue());
            selection = null;

            //makeThresholdedDataImage();
            dataHasBeenModified = true;

            HighlightMask   = null;
            highlightedArea = 0.0d;
        }
Exemple #6
0
        private void pbRes_MouseUp(object sender, MouseEventArgs e)
        {
            // ReSharper disable InconsistentNaming
            imageConditionAndData currentICD = null;
            // ReSharper restore InconsistentNaming
            Type theSenderDataType = typeof(imageConditionAndData);



            if (e.Button == MouseButtons.Left && sender.Equals(meLeftButtonDownSender))
            {
                PictureBoxSelection pbSelection = null;

                if (sender == pbRes)
                {
                    currentICD        = imgData;
                    theSenderDataType = imgData.GetType();
                }
                else if (sender == pbScale)
                {
                    currentICD        = imgData;
                    theSenderDataType = imgData.currentColorSchemeRuler.GetType();
                }


                //если уже есть selection у этого объекта, а это выделение пусто - проверить, было ли оно внутри
                //если было внутри - значит, был клик или даблклик внутри выделения - не обрабатывать здесь
                if (theSenderDataType == typeof(imageConditionAndData))
                {
                    pbSelection = new PictureBoxSelection(sender, meLeftButtonDownArgs.Location, e.Location, currentICD);
                    if ((pbSelection.IsEmptySelection) && (currentICD.Selection != null))
                    {
                        if (currentICD.Selection.CheckIfDoubleclickedinsideSelection(sender, e, currentICD))
                        {
                            return;
                        }
                    }
                    currentICD.Selection = pbSelection;
                }
                else if (theSenderDataType == typeof(ColorSchemeRuler))
                {
                    pbSelection = new PictureBoxSelection(sender, meLeftButtonDownArgs.Location, e.Location, currentICD.currentColorSchemeRuler);
                    currentICD.currentColorSchemeRuler.Selection = pbSelection;
                }


                HighlightLinkedSelection(pbSelection);
                RaisePaintEvent(null, null);

                if ((theSenderDataType == typeof(ColorSchemeRuler)) && (imgData.HighlightMask != null))
                {
                    string testToShow = "significant area: " + imgData.maskImageBinary.CountNonzero()[0] + Environment.NewLine;
                    testToShow += "highlighted area: " + imgData.highlightedArea + Environment.NewLine;
                    testToShow += "highlighted area relative: " + (imgData.highlightedArea / (double)imgData.maskImageBinary.CountNonzero()[0]).ToString("e") + Environment.NewLine;
                    ThreadSafeOperations.SetTextTB(tbStats, testToShow, true);
                }
            }
        }
 /// <summary>
 /// DEPRECATED - use ColorSchemeRuler(imageConditionAndData imgData) instead
 /// </summary>
 /// <param name="currentColorScheme">The current color scheme.</param>
 /// <param name="inMinValue">The minimum data value.</param>
 /// <param name="inMaxValue">The maximum data value.</param>
 public ColorSchemeRuler(ColorScheme currentColorScheme, double inMinValue = -255.0d, double inMaxValue = 255.0d)
 {
     minValue            = inMinValue;
     maxValue            = inMaxValue;
     colorScheme         = currentColorScheme;
     markerPositionValue = inMaxValue;
     selection           = null;
     imgToRule           = null;
     isMarginsFixed      = true;
 }
Exemple #8
0
 private void HighlightLinkedSelection(PictureBoxSelection theSelection)
 {
     if (theSelection.usedImageData.GetType().Equals(typeof(imageConditionAndData)))
     {
         ((imageConditionAndData)(theSelection.usedImageData)).currentColorSchemeRuler.makeHihghlightMask();
     }
     else if (theSelection.usedImageData.GetType().Equals(typeof(ColorSchemeRuler)))
     {
         ((ColorSchemeRuler)(theSelection.usedImageData)).imgToRule.makeHihghlightMask();
     }
 }
 public ColorSchemeRuler(ColorSchemeRuler sourceRuler)
 {
     minValue            = sourceRuler.minValue;
     maxValue            = sourceRuler.maxValue;
     colorScheme         = sourceRuler.colorScheme;
     markerPositionValue = maxValue;
     selection           = null;
     imgToRule           = null;
     //isMarginsFixed = imgData.isColorSchemeMarginsFixed;
     isMarginsFixed = sourceRuler.isMarginsFixed;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorSchemeRuler"/> class using the imgData
 /// </summary>
 /// <param name="imgData">The image data and condition.</param>
 public ColorSchemeRuler(imageConditionAndData imgData)
 {
     minValue = imgData.dataMinValue();
     maxValue = imgData.dataMaxValue();
     if (imgData.currentColorScheme.isColorSchemeSymmetric)
     {
         minValue = -Math.Max(Math.Abs(minValue), Math.Abs(maxValue));
         maxValue = Math.Max(Math.Abs(minValue), Math.Abs(maxValue));
     }
     colorScheme         = imgData.currentColorScheme;
     markerPositionValue = maxValue;
     selection           = null;
     imgToRule           = imgData;
     //isMarginsFixed = imgData.isColorSchemeMarginsFixed;
     isMarginsFixed = false;
 }
Exemple #11
0
        /// <summary>
        /// Constructs  the image from selection.
        /// </summary>
        /// <param name="theSelection">The selection.</param>
        /// <returns>imageConditionAndData.</returns>
        public imageConditionAndData SelectedImageData(PictureBoxSelection theSelection = null)
        {
            if ((theSelection == null) && (selection != null))
            {
                theSelection = selection;
            }
            if (theSelection == null)
            {
                return(this);
            }

            Rectangle   theSelectionRectangle = (Rectangle)theSelection.SelectionRectReal;
            DenseMatrix subMatrix             = (DenseMatrix)dmSourceData.SubMatrix(
                theSelectionRectangle.Location.Y,
                theSelectionRectangle.Height,
                theSelectionRectangle.Location.X,
                theSelectionRectangle.Width);
            Image <Gray, Byte> img = ImageProcessing.grayscaleImageFromDenseMatrix(subMatrix);

            DenseMatrix maskMatrix = ImageProcessing.DenseMatrixFromImage(maskImageBinary);

            maskMatrix = (DenseMatrix)maskMatrix.SubMatrix(
                theSelectionRectangle.Location.Y,
                theSelectionRectangle.Height,
                theSelectionRectangle.Location.X,
                theSelectionRectangle.Width);
            //Image<Gray, Byte> maskSubImageBinary = maskImageBinary.GetSubRect(theSelectionRectangle);
            Image <Gray, Byte> maskSubImageBinary = ImageProcessing.grayscaleImageFromDenseMatrixWithFixedValuesBounds(maskMatrix, 0.0d, 1.0d);//  maskImageBinary.GetSubRect(theSelectionRectangle);

            maskSubImageBinary = maskSubImageBinary / 255;

            //Image<Gray, double> tmpHighlightingImage = img.CopyBlank();
            //tmpHighlightingImage.Draw((Rectangle)theSelection.SelectionRectReal, new Gray(255), -1);
            //img = img.AddWeighted(tmpHighlightingImage, 1.0, 0.15, 0.0);
            //img.Draw((Rectangle)theSelection.SelectionRectReal, new Gray(255), 1);
            //ImageProcessing imgPr = new ImageProcessing(img.Bitmap, false);
            //imgPr.significantMaskImageBinary = maskSubImageBinary;
            //imgPr.significantMaskImage = maskSubImageBinary*255;
            imageConditionAndData retImageData = new imageConditionAndData(subMatrix, maskSubImageBinary);

            retImageData.currentColorScheme                     = currentColorScheme;
            retImageData.currentColorSchemeRuler                = new ColorSchemeRuler(currentColorSchemeRuler);
            retImageData.currentColorSchemeRuler.imgToRule      = retImageData;
            retImageData.currentColorSchemeRuler.IsMarginsFixed = false;
            //retImageData.UpdateColorSchemeRuler();
            return(retImageData);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorSchemeRuler"/> class.
        /// With the forced maximum and minimum values
        /// </summary>
        /// <param name="imgData">The image data and condition.</param>
        /// <param name="minValueIn">The forced minimum value.</param>
        /// <param name="maxValueIn">The forced maximum value.</param>
        public ColorSchemeRuler(imageConditionAndData imgData, double minValueIn, double maxValueIn)
        {
            minValue = minValueIn;
            if ((!double.IsNaN(imgData.DmSourceData.Values.Min())) && (minValue >= imgData.DmSourceData.Values.Min()))
            {
                minValue = imgData.DmSourceData.Values.Min();
            }

            maxValue = maxValueIn;
            if ((!double.IsNaN(imgData.DmSourceData.Values.Max())) && (maxValue <= imgData.DmSourceData.Values.Max()))
            {
                maxValue = imgData.DmSourceData.Values.Max();
            }

            colorScheme         = imgData.currentColorScheme;
            markerPositionValue = maxValue;
            selection           = null;
            imgToRule           = imgData;
            //isMarginsFixed = imgData.isColorSchemeMarginsFixed;
            isMarginsFixed = true;
        }
        public void makeHihghlightMask()
        {
            if (imgToRule.Selection == null)
            {
                return;
            }

            imageConditionAndData tmpImgData = imgToRule.SelectedImageData();
            double filterMaxValue            = tmpImgData.DmSourceData.Values.Max();
            double filterMinValue            = tmpImgData.DmSourceData.Values.Min();

            selection = null;


            DenseMatrix dmHighlightDenseMatrix = DenseMatrix.Create(currentDimY, currentDimX, new Func <int, int, double>
                                                                    (
                                                                        (y, x) =>
            {
                double curValue = (double)y;
                curValue        = 1.0d - (1.0d + curValue) / (double)currentDimY;
                curValue        = minValue + curValue * (maxValue - minValue);
                if ((curValue >= filterMinValue) && (curValue <= filterMaxValue))
                {
                    return(255.0d);
                }
                else
                {
                    return(100.0d);
                }
            }
                                                                    ));
            Image <Gray, Byte> highlightImage = ImageProcessing.grayscaleImageFromDenseMatrixWithFixedValuesBounds(dmHighlightDenseMatrix, 0.0d, 255.0d);


            HighlightMask         = highlightImage.Convert <Gray, double>();
            HighlightMaskRelative = HighlightMask / 255.0d;
            //ImageProcessing.grayscaleImageFromDenseMatrixWithFixedValuesBounds(tmpDM, 0.0d, 255.0d).Convert<Gray, double>();
            //HighlightMask = HighlightMask / 255.0d;
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="imageConditionAndData"/> class.
        /// note: with the fixed ruler bounds
        /// </summary>
        /// <param name="imgPr">The image processing object contains image data and some processing templates.</param>
        public imageConditionAndData(ImageProcessing imgPr)
        {
            maskImageBinary      = imgPr.significantMaskImageBinary.Copy();
            isImageGrayscaled    = false;
            sourceImageBgr       = imgPr.tmpImage.Copy();
            sourceImageGrayscale = null;

            thresholdingUsageTop = false;
            thresholdingUsageBtm = true;
            thresholdingValue    = 255;

            dmSourceData = ImageProcessing.DenseMatrixFromImage(sourceImageBgr.Convert <Gray, Byte>());

            currentColorScheme = new ColorScheme("");
            //currentColorSchemeRuler = new ColorSchemeRuler(currentColorScheme, dataMinValue(), dataMaxValue());
            currentColorSchemeRuler = new ColorSchemeRuler(this, -255.0d, 255.0d);
            selection = null;

            //makeThresholdedDataImage();
            dataHasBeenModified = true;

            HighlightMask   = null;
            highlightedArea = 0.0d;
        }
 public PictureBoxSelection(PictureBoxSelection selectionToCopy)
     : this(selectionToCopy.underlyingPictureBox, selectionToCopy._pDown, selectionToCopy._pUp, selectionToCopy.usedImageData)
 {
 }
 /// <summary>
 /// Clears the selection property so there will be no selected area at the ruler reapresenting image
 /// and there will be no selection data if something requests it
 /// </summary>
 public void ClearSelection()
 {
     selection     = null;
     HighlightMask = null;
 }