Exemplo n.º 1
0
        public cFeedBackMessage Run(c3DNewWorld _3DWorld)
        {
            if (base.Start() == false)
            {
                base.FeedBackMessage.IsSucceed = false;
                return base.FeedBackMessage;
            }

            #region Properties Management
            object _firstValue = base.ListProperties.FindByName("Thresold");
            double Thresold = 0.5;
            if (_firstValue == null)
            {
                base.GenerateError("-Thresold- not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                Thresold = (double)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("-Thresold- cast didn't work");
                return base.FeedBackMessage;
            }

            _firstValue = base.ListProperties.FindByName("Split objects ?");
            bool IsSplit = false;
            if (_firstValue == null)
            {
                base.GenerateError("-Split objects ?- not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                IsSplit = (bool)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("-Split objects ?- cast didn't work");
                return base.FeedBackMessage;
            }
            #endregion

            ListObjects = new cListGeometric3DObject("");

            if (IsSplit == false)
            {
                c3DMeshObject MyMesh = null;

                if (this.VTKInput == null)
                {
                    MyMesh = new c3DMeshObject(this.Input, Thresold);
                }
                else
                {
                    MyMesh = new c3DMeshObject(this.VTKInput, (int)Thresold);

                }
                MyMesh.Create(Color.Aqua, this.Pos );
                ListObjects.Name = MyMesh.GetName() + " metaobject";
                ListObjects.Add(MyMesh);

            }
            else
            {
                // ok that's a little bit more complicated now
                // first we need to binarize the image
                cImageSegmentationThreshold IST = new cImageSegmentationThreshold();
                IST.ListProperties.FindByName("Threshold").SetNewValue(Thresold);
                cImage SourceImage = new cImage(this.Input, false);
                IST.SetInputData(SourceImage);
                IST.Run();

                // now perform image labeling
                cImage BinImage = IST.GetOutPut();
                cImage LabeledImage = new cImage(BinImage, false);
                ConnectedComponentSet CCS = new ConnectedComponentSet(BinImage,LabeledImage,SourceImage,  0, eConnectivity.THREED_6, 0, float.MaxValue);

                Random RD = new Random();

                int IdxObj = 1;
                // loop over each object
                int NumObj = CCS.Count;

                ListObjects.Name = "T_" + Thresold + " [" + SourceImage.Name + " Metaobject";

                for(int i = 0;i<NumObj;i++)
                {
                    ConnectedVoxels item = CCS[i];

                 //   if (item.Volume <= 1) continue;

                    List<cPoint3D> ExtremePts = item.GetExtremaPoints();
                    // crop the labeled image
                    cImage TmpIm = LabeledImage.Crop(ExtremePts[0], ExtremePts[1]);

                    // we have to clean the cropped image to prevent any overlapping object to be segmented
                    for (int Pix = 0; Pix < TmpIm.ImageSize; Pix++)
                    {
                        if ((TmpIm.SingleChannelImage[0].Data[Pix] > 0) && (TmpIm.SingleChannelImage[0].Data[Pix] != IdxObj)) TmpIm.SingleChannelImage[0].Data[Pix] = 0;
                    }

                    // update the position of the object
                    cPoint3D NewPos = ExtremePts[0]*SourceImage.Resolution;

                    c3DMeshObject MyMesh = new c3DMeshObject(TmpIm.SingleChannelImage[0], 0.5);
                    MyMesh.Create(Color.FromArgb(RD.Next(255), RD.Next(255), RD.Next(255)), NewPos);

                    MyMesh.SetName(MyMesh.GetName() + "_" + IdxObj);
                    MyMesh.AssociatedConnectedComponent = item;
                    ListObjects.AddObject(MyMesh);

                    IdxObj++;
                }

            }
            return base.FeedBackMessage;
        }
Exemplo n.º 2
0
        private void ToolStripMenuItem_SegmentationThreshold(object sender, EventArgs e)
        {
            cDisplaySingleImage NewView = new cDisplaySingleImage();

            cImageSegmentationThreshold ME = new cImageSegmentationThreshold();
            ME.SetInputData(this.AssociatedImage);
            ME.ListProperties.FindByName("Threshold").SetNewValue((double)100);
            ME.ListProperties.FindByName("Threshold").IsGUIforValue = true;
            ME.IsInvert = true;
            ME.Run();
            NewView.SetInputData(ME.GetOutPut());

            NewView.Run();
        }
Exemplo n.º 3
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (DensityMaps.GetNumChannels() > cGlobalInfo.ListCellularPhenotypes.Count - 2)
            {
                MessageBox.Show("This process cannot manage more than " + (cGlobalInfo.ListCellularPhenotypes.Count - 2) + " different classes !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cImageSegmentationThreshold ST = new cImageSegmentationThreshold();
            ST.SetInputData(DensityMaps);
            ST.ListProperties.UpdateValueByName("Threshold", (double)this.numericUpDown1.Value);
            ST.MaxValue = 1;
            ST.Run();

            cImage SegmentedImages = ST.GetOutPut();

            // let's create an image containing the different non overlapping populations

            // Values:
            // 0 : outliers
            // 1 : Overlapping population
            // then population specific areas
            ResultingImage = new cImage(SegmentedImages.Width, SegmentedImages.Height, SegmentedImages.Depth, 1);
            ResultingImage.Name = "Overlapping Populations Analysis";

            for (int i = 0; i < ResultingImage.Width * ResultingImage.Height * ResultingImage.Depth; i++)
            {
                int IdxPop = 0;
                float PixTotal = 0;
                float CurrentValue = 0;
                for (int IdxChannel = 0; IdxChannel < SegmentedImages.GetNumChannels(); IdxChannel++)
                {
                    CurrentValue = SegmentedImages.SingleChannelImage[IdxChannel].Data[i];
                    PixTotal += CurrentValue;
                    if (CurrentValue == 1)
                        IdxPop = IdxChannel;

                }

                if (PixTotal > 1)
                    ResultingImage.SingleChannelImage[0].Data[i] = 1;
                else if (PixTotal == 1)
                {
                    ResultingImage.SingleChannelImage[0].Data[i] = IdxPop + 2;
                }

                //float Value0 = SegmentedImages.SingleChannelImage[PositiveBand].Data[i];
                //float Value1 = SegmentedImages.SingleChannelImage[NegativeBand].Data[i];

                //if ((Value0 > 0) && (Value1 > 0))  // overlapping
                //    ResultingImage.SingleChannelImage[0].Data[i] = 1;
                //else if ((Value0 > 0) && (Value1 <= 0))
                //    ResultingImage.SingleChannelImage[0].Data[i] = 2;// DensityMaps.SingleChannelImage[PositiveBand].Data[i];
                //else if ((Value0 <= 0) && (Value1 > 0))
                //    ResultingImage.SingleChannelImage[0].Data[i] = 3;// -DensityMaps.SingleChannelImage[NegativeBand].Data[i];

            }

            if (checkBoxUpdatePhenotypeName.Checked)
            {
                cGlobalInfo.ListCellularPhenotypes[0].Name = "Outliers";
                cGlobalInfo.ListCellularPhenotypes[1].Name = "Overlapping Populations";

                for (int IdxChannel = 0; IdxChannel < DensityMaps.GetNumChannels(); IdxChannel++)
                {
                    cGlobalInfo.ListCellularPhenotypes[IdxChannel + 2].Name = DensityMaps.SingleChannelImage[IdxChannel].Name + " Specific";
                }
            }

            if (checkBoxDisplayResultingImage.Checked)
            {
                //  cImageViewer IV2 = new cImageViewer();
                //  IV2.SetImage(ResultingImage/*SegmentedImages*/);
                //  IV2.Show();
                List<byte[][]> ListLUTs = new List<byte[][]>();
                cLUT LUT = new cLUT();
                ListLUTs.Add(LUT.LUT_FIRE);

                pictureBoxForImage.Image = ResultingImage.GetBitmap(1, null, ListLUTs);
            }
            //   return;

            // now apply the result to the points
            for (int j = 0; j < Parent.InputTable[0].Count/* dt.Rows.Count*/; j++)
            {

                double TmpValueX = (ImageWidth * (ListX[j] - MinX)) / (MaxX - MinX);
                double TmpValueY = ImageHeight - (ImageHeight * (ListY[j] - MinY)) / (MaxY - MinY);

                int PosX = (int)TmpValueX;
                int PosY = (int)TmpValueY;

                if (PosX >= ResultingImage.Width) PosX = ResultingImage.Width - 1;
                if (PosY >= ResultingImage.Height) PosY = ResultingImage.Height - 1;
                if (PosX < 0) PosX = 0;
                if (PosY < 0) PosY = 0;

                double Value = ResultingImage.SingleChannelImage[0].Data[PosX + PosY * ResultingImage.Width];
                if (Value > 0)
                {
                    Parent.MachineLearning.Classes[j] = Value;
                }
                else
                    Parent.MachineLearning.Classes[j] = 0;

                //double currentClass = MachineLearning.Classes[j];

                //ListX.Add(double.Parse(dt.Rows[j][this.comboBoxAxeX.SelectedIndex].ToString()));
                //ListY.Add(double.Parse(dt.Rows[j][this.comboBoxAxeY.SelectedIndex].ToString()));
            }
            Parent.MachineLearning.UpDateNumberOfCluster();
            Parent.ReDraw();
            //(int)MachineLearning.Classes[j]
        }