/// <summary> /// Add a new image to the montage /// </summary> /// <param name="NewIm">New image to be integrated</param> /// <param name="IsForceInconsistencies">if set to TRUE then we'll try to force the image integration within the montage even if there are some inconsistencies with the last image (resolution, number of channels)</param> public bool Add(cImage NewIm, bool IsForceInconsistencies) { if (ListImage == null) { ListImage = new List<cImage>(); ListImage.Add(NewIm); } if ((ListImage[ListImage.Count - 1].GetNumChannels() != NewIm.GetNumChannels()) && (!IsForceInconsistencies)) { return false; } else { if (this.NumberOfChannels < NewIm.GetNumChannels()) this.NumberOfChannels = NewIm.GetNumChannels(); this.ListImage.Add(NewIm); } if (((ListImage[ListImage.Count - 1].Resolution.X != NewIm.Resolution.X) && (!IsForceInconsistencies)) || ((ListImage[ListImage.Count - 1].Resolution.Y != NewIm.Resolution.Y) && (!IsForceInconsistencies)) || ((ListImage[ListImage.Count - 1].Resolution.Z != NewIm.Resolution.Z) && (!IsForceInconsistencies))) { return false; } else { this.Resolution.X = NewIm.Resolution.X; this.Resolution.Y = NewIm.Resolution.Y; this.Resolution.Z = NewIm.Resolution.Z; this.ListImage.Add(NewIm); } return true; }
private void AnalyseSequence(cImage SeqToAnalyse) { // //FormForThumbnails WindThumbnail = new FormForThumbnails(); // //for (int k = 0; k < ListFormForControl.Count; k++) // //{ // // FormForControl Obj = ListFormForControl.ElementAt(ListFormForControl.Count - k-1); // // Obj.DisplayThumbnail(WindThumbnail); // //} // //WindThumbnail.Show(); // //return; #region initialization if (SeqToAnalyse == null) return; // create World if (Current3DWorld == null) { Current3DWorld = new c3DNewWorld(new cPoint3D(SeqToAnalyse.Width, SeqToAnalyse.Height, SeqToAnalyse.Depth), new cPoint3D(SeqToAnalyse.Resolution)); } else { // // Current3DWorld.ren1. // Current3DWorld.Terminate(); Current3DWorld = null; Current3DWorld = new c3DNewWorld(new cPoint3D(SeqToAnalyse.Width, SeqToAnalyse.Height, SeqToAnalyse.Depth), new cPoint3D(SeqToAnalyse.Resolution)); } for (int k = 0; k < ListFormForControl.Count; k++) { FormForControl Obj = ListFormForControl.ElementAt(ListFormForControl.Count - k-1); if (Obj.numericUpDownChannel.Value >= SeqToAnalyse.GetNumChannels()) { MessageBox.Show("Wrong number of channels", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // // Current3DWorld.ListObjControl = ListFormForControl; // // dataGridViewForClassif.DataSource = CurrentTable; // if (DataGrid == null) // { // DataGrid = new FormForDataGridView(); // DataGrid.Show(); // } // Current3DWorld.SetLinkToDataGridView(DataGrid.dataGridViewForResults); Current3DWorld.ListMetaObjectList = new List<cMetaBiologicalObjectList>(); cMetaBiologicalObjectList ListMetacells = new cMetaBiologicalObjectList("List Meta Objects"); Current3DWorld.ListMetaObjectList.Add(ListMetacells); #endregion #region Detection for (int k = 0; k < ListFormForControl.Count; k++) { FormForControl Obj = ListFormForControl.ElementAt(ListFormForControl.Count - k -1); if (Obj.radioButtonIsVolume.Checked) // we have to detect a volume ! { cVolumeDetection Detection = new cVolumeDetection(SeqToAnalyse, (int)Obj.numericUpDownChannel.Value, Obj.WindowForVolumeDetection.checkBoxIsBorderKill.Checked); Detection.SetShift(new cPoint3D((float)Obj.WindowForPreProcessing.numericUpDownShiftX.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftY.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftZ.Value)); if ((Obj.checkBoxPreProcessings.Checked == false) || (Obj.WindowForPreProcessing.checkBoxMedianIsDisabled.Checked)) { Detection.SetMedian(-1); Detection.SetShift(new cPoint3D(0, 0, 0)); } else { Detection.SetMedian((int)Obj.WindowForPreProcessing.numericUpDownMedianKernel.Value); Detection.SetShift(new cPoint3D((float)Obj.WindowForPreProcessing.numericUpDownShiftX.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftY.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftZ.Value)); } if (Obj.WindowForVolumeDetection.checkBoxVolumeSmooth.Checked) Detection.MeshSmoother = new cMeshSmoother((int)Obj.WindowForVolumeDetection.numericUpDownSmoothIterations.Value); if ((Obj.comboBoxContainer.SelectedItem !=null) && (Obj.comboBoxContainer.SelectedItem.ToString() != "")) { Detection.SetContainers(Current3DWorld.GetListBiologicalObjectsOfType(Obj.comboBoxContainer.Items[0].ToString())); if (Obj.InOrOut.radioButtonIn.Checked) Detection.SetContainersMode(0); else Detection.SetContainersMode(1); } else Detection.SetContainers(null); if (Obj.WindowForVolumeDetection.checkBoxIsRegionGrowing.Checked == false) // no region growing direct detection { Obj.AssociatedBiologicalObjectList = Detection.IntensityThreshold((float)Obj.WindowForVolumeDetection.numericUpDownIntensityThreshold.Value, (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMinVol.Value, (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMaxVol.Value); } else // region growing { if (Obj.WindowForVolumeDetection.radioButtonRegionsBased.Checked) // start from a segmentation { if (Obj.WindowForVolumeDetection.radioButtonVolumeDetectionNew.Checked) // a new segmentation has to be performed { // // Image3D CurrentPatch = new Image3D(2 * Radius, 2 * Radius, 1, CurrentImageToProcess.NumBands); cImage CurrentBinary = new cImage(SeqToAnalyse.Width, SeqToAnalyse.Height, SeqToAnalyse.Depth, 1); for (int i = 0; i < CurrentBinary.ImageSize; i++) { if (SeqToAnalyse.SingleChannelImage[(int)Obj.numericUpDownChannel.Value].Data[i] >= (float)Obj.WindowForVolumeDetection.numericUpDownIntensityThreshold.Value) CurrentBinary.SingleChannelImage[0].Data[i] = 1; } eConnectivity CurrentConnectivity = eConnectivity.TWOD_4; if (CurrentBinary.Depth > 1) CurrentConnectivity = eConnectivity.THREED_6; ConnectedComponentSet OFNucleus = new ConnectedComponentSet(CurrentBinary, null, null, 0, CurrentConnectivity, (int)Obj.WindowForVolumeDetection.numericUpDownRegionBasedMinArea.Value, (int)Obj.WindowForVolumeDetection.numericUpDownRegionBasedMaxArea.Value); // // RegionGrowing = new cRegionGrowing(OFNucleus, NewSeq[0], (int)numericUpDownChannelForRegionGrowing.Value, (float)numericUpDownIntensityForRegionGrowing.Value, (int)numericUpDownMaxNucleusArea.Value); int NumIterations = -1; if (Obj.WindowForVolumeDetection.checkBoxIsConvergence.Checked == false) NumIterations = (int)Obj.WindowForVolumeDetection.numericUpDownIterationNumber.Value; float MergingRatio = (float)((Obj.WindowForVolumeDetection.trackBarMergingStrength.Maximum - Obj.WindowForVolumeDetection.trackBarMergingStrength.Value) / 100.0); Obj.AssociatedBiologicalObjectList = Detection.RegionGrowing(OFNucleus, (float)Obj.WindowForVolumeDetection.numericUpDownIntensityForRegionGrowing.Value, (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMinVol.Value, (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMaxVol.Value, NumIterations, MergingRatio); } // else // { // throw new System.ArgumentException("Not implemented", "Error"); // } // } // else // start from seeds points // { // // first gather the seeds // if (Obj.WindowForVolumeDetection.comboBoxExistingSpotsDetected.Items.Count == 0) break; // List<cBiological3DObject> ListSeeds = Current3DWorld.GetListBiologicalObjectsOfType(Obj.WindowForVolumeDetection.comboBoxExistingSpotsDetected.Items[0].ToString()); // int NumIterations = -1; // if (Obj.WindowForVolumeDetection.checkBoxIsConvergence.Checked == false) NumIterations = (int)Obj.WindowForVolumeDetection.numericUpDownIterationNumber.Value; // float MergingRatio = (float)((Obj.WindowForVolumeDetection.trackBarMergingStrength.Maximum - Obj.WindowForVolumeDetection.trackBarMergingStrength.Value) / 100.0); // Obj.AssociatedBiologicalObjectList = Detection.RegionGrowing(ListSeeds, // (float)Obj.WindowForVolumeDetection.numericUpDownIntensityForRegionGrowing.Value, // (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMinVol.Value, // (float)Obj.WindowForVolumeDetection.numericUpDownVolumeMaxVol.Value, NumIterations, MergingRatio); } } if (Obj.AssociatedBiologicalObjectList != null) { Obj.richTextBoxInfo.AppendText(Obj.AssociatedBiologicalObjectList.Count + " objects detected."); for (int i = 0; i < Obj.AssociatedBiologicalObjectList.Count; i++) { cBiological3DVolume TmpVol = (cBiological3DVolume)Obj.AssociatedBiologicalObjectList[i]; Obj.AssociatedBiologicalObjectList[i].SetType(Obj.textBoxName.Text); // TmpVol.ThumbnailnewImage = imageListForThumbnail.Images[Obj.AssociatedBiologicalObjectList[i].GetType() + ".jpg"]; Obj.AssociatedBiologicalObjectList[i].Name = Obj.textBoxName.Text + " " + i; // Obj.AssociatedBiologicalObjectList[i].IsMaster = Obj.IsMasterObject(); // List<double> Res = TmpVol.Information.GetInformation(); if (Obj.checkBoxIsDisplayName.Checked) { cGeometric3DObject AssociatedText = TmpVol.AttachText(TmpVol.Name, 10, Color.White); AssociatedText.IsStayInFrontOfCamera = true; Current3DWorld.AddGeometric3DObject(AssociatedText); // TmpVol.AddText(TmpVol.Name, Current3DWorld, (double)Obj.ForText.numericUpDownArrowScale.Value, Obj.ForText.buttonChangeColorPositive.BackColor); } if (Obj.checkIsBoxPointingArrow.Checked) { cGeometric3DObject AssociatedArrow = TmpVol.AttachPointingArrow((double)Obj.ForArrow.numericUpDownArrowScale.Value, Obj.ForArrow.buttonChangeColorPositive.BackColor); Current3DWorld.AddGeometric3DObject(AssociatedArrow); } Obj.AssociatedBiologicalObjectList[i].SetOpacity((double)Obj.ColorOpacity.numericUpDownValue.Value); // if the object it the Master then create a meta-object and put it inside if (Obj.IsMasterObject()) { cMetaBiologicalObject Cell = new cMetaBiologicalObject(Obj.WindowForMaster.textBoxName.Text + i, Current3DWorld.ListMetaObjectList[0], Obj.AssociatedBiologicalObjectList[i]); // // Cell.AddObject(Obj.AssociatedBiologicalObjectList[i]); Current3DWorld.ListMetaObjectList[0].Add(Cell); } } if (Obj.radioButtonColorSingle.Checked) Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Regular); else if (Obj.radioButtonColorRandom.Checked) Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Random); else if (Obj.radioButtonColorIndexed.Checked) Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Indexed); } } else if (Obj.RadioButtonIsSpot.Checked) { cSpotDetection Detection = new cSpotDetection(SeqToAnalyse, (int)Obj.numericUpDownChannel.Value); if ((Obj.checkBoxPreProcessings.Checked == false) || (Obj.WindowForPreProcessing.checkBoxMedianIsDisabled.Checked)) { Detection.SetMedian(-1); Detection.SetShift(new cPoint3D(0, 0, 0)); } else { Detection.SetMedian((int)Obj.WindowForPreProcessing.numericUpDownMedianKernel.Value); Detection.SetShift(new cPoint3D((float)Obj.WindowForPreProcessing.numericUpDownShiftX.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftY.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftZ.Value)); } if ((Obj.comboBoxContainer.Items.Count > 0) && (Obj.comboBoxContainer.SelectedItem != null)) { Detection.SetContainers(Current3DWorld.GetListBiologicalObjectsOfType(Obj.comboBoxContainer.SelectedItem.ToString())); if (Obj.InOrOut.radioButtonIn.Checked) Detection.SetContainersMode(0); else Detection.SetContainersMode(1); } Obj.AssociatedBiologicalObjectList = Detection.HessianDetection((float)Obj.WindowForSpotDetection.numericUpDownSpotRadius.Value, (float)Obj.WindowForSpotDetection.numericUpDownIntensityThreshold.Value, (int)Obj.WindowForSpotDetection.numericUpDownSpotLocality.Value, (double)Obj.WindowForSpotDetection.numericUpDownSphereDisplayRadius.Value); Obj.richTextBoxInfo.AppendText(Obj.AssociatedBiologicalObjectList.Count + " objects detected."); for (int i = 0; i < Obj.AssociatedBiologicalObjectList.Count; i++) { cBiologicalSpot TmpSpot = (cBiologicalSpot)Obj.AssociatedBiologicalObjectList[i]; TmpSpot.Name = Obj.textBoxName.Text + " " + i; TmpSpot.SetType(Obj.textBoxName.Text); // TmpSpot.ThumbnailnewImage = imageListForThumbnail.Images[Obj.AssociatedBiologicalObjectList[i].GetType() + ".jpg"]; // if (Obj.checkBoxIsDisplayName.Checked) // TmpSpot.AddText(TmpSpot.Name, Current3DWorld, (double)Obj.ForText.numericUpDownArrowScale.Value, Obj.ForText.buttonChangeColorPositive.BackColor); if (Obj.checkIsBoxPointingArrow.Checked) { cGeometric3DObject AssociatedArrow = TmpSpot.AttachPointingArrow((double)Obj.ForArrow.numericUpDownArrowScale.Value, Obj.ForArrow.buttonChangeColorPositive.BackColor); Current3DWorld.AddGeometric3DObject(AssociatedArrow); } // TmpSpot.SetOpacity((double)Obj.ColorOpacity.numericUpDownValue.Value); // // if the object it the Master then create a meta-object and put it inside if (Obj.IsMasterObject()) { cMetaBiologicalObject Cell = new cMetaBiologicalObject("Cell " + i, Current3DWorld.ListMetaObjectList[0], Obj.AssociatedBiologicalObjectList[i]); // // Cell.AddObject(Obj.AssociatedBiologicalObjectList[i]); Current3DWorld.ListMetaObjectList[0].Add(Cell); } // /*cMetaBiologicalObject Cell = */ // //Current3DWorld.ListMetaObjectList[0].AssociateWith(Current3DWorld.ListMetaObjectList[0].FindTheClosestVolumeFrom(TmpSpot.GetCentroid(), 20), TmpSpot); } // if (Obj.radioButtonColorSingle.Checked) // Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Regular); // else if (Obj.radioButtonColorRandom.Checked) // Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Random); // else if (Obj.radioButtonColorIndexed.Checked) // Current3DWorld.AddBiological3DObjects(Obj.AssociatedBiologicalObjectList, Obj.buttonChangeColorPositive.BackColor, eColorMode.Indexed); } else if (Obj.radioButtonIsVolumeRendering.Checked) { Current3DWorld.AddVolume3D(new cVolumeRendering3D(this.AssociatedImage.SingleChannelImage[(int)Obj.numericUpDownChannel.Value], new cPoint3D((float)Obj.WindowForPreProcessing.numericUpDownShiftX.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftY.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftZ.Value), null, Current3DWorld)); // cVolume3D Volume = new cVolume3D(SeqToAnalyse, (int)Obj.numericUpDownChannel.Value, new cPoint3D((float)Obj.WindowForPreProcessing.numericUpDownShiftX.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftY.Value, (float)Obj.WindowForPreProcessing.numericUpDownShiftZ.Value)); // Current3DWorld.AddVolume3D(Volume, Color.Black, Obj.buttonChangeColorPositive.BackColor); } // Thread oThread = new Thread(new ThreadStart(Obj.DisplayDone)); } #endregion #region Objects Association cMetaBiologicalObjectList MetaCellList = Current3DWorld.ListMetaObjectList[0]; // let's associate the objects for (int k = 0; k < ListFormForControl.Count; k++) { FormForControl Obj = ListFormForControl.ElementAt(ListFormForControl.Count - k -1); // that's a volume rendering ... no connection if (Obj.radioButtonIsVolumeRendering.Checked) continue; // the object is the master if (Obj.IsMasterObject()) continue; // this object has not connections ... is not associated to the master if (Obj.comboBoxLinkToTheMaster.SelectedIndex == 0) continue; cPoint3D ClosestPt = new cPoint3D(0, 0, 0); foreach (cBiological3DVolume CurrentSubObj in Obj.AssociatedBiologicalObjectList) { cBiological3DVolume ObjectToIdentify = null; switch (Obj.comboBoxLinkToTheMaster.SelectedIndex) { case 1: // association by distance to the master centroid ObjectToIdentify = MetaCellList.FindTheClosestVolumeCentroidFrom(CurrentSubObj.GetCentroid(), (double)Obj.WindowDistanceToMaster.numericUpDownDistanceMaxToMaster.Value); break; case 2: // //cBiological3DVolume CurrentVolume ObjectToIdentify = MetaCellList.FindTheClosestVolumeFrom(CurrentSubObj, (double)Obj.WindowDistanceToMaster.numericUpDownDistanceMaxToMaster.Value, out ClosestPt); break; default: break; } if (ObjectToIdentify == null) continue; cMetaBiologicalObject Cell = MetaCellList.AssociateWith(ObjectToIdentify, CurrentSubObj); // // -------------- draw information and links between the objects --------------------- if (Obj.WindowDistanceToMaster.checkBoxDrawLinkToMasterCenter.Checked) { c3DLine CurrLine = new c3DLine(CurrentSubObj.GetCentroid(), ObjectToIdentify.GetCentroid()); Current3DWorld.AddGeometric3DObject(CurrLine); //if (Obj.WindowDistanceToMaster.checkBoxDisplayBranchToCenterDistance.Checked) // CurrLine.DisplayLenght(Current3DWorld, 0.4); } // // -------------- draw information and links between the objects --------------------- if (Obj.WindowDistanceToMaster.checkBoxDrawLinkToMasterEdges.Checked) { c3DLine CurrLine1 = new c3DLine(CurrentSubObj.GetCentroid(), ClosestPt); Current3DWorld.AddGeometric3DObject(CurrLine1); //if(Obj.WindowDistanceToMaster.checkBoxDisplayBranchToEdgesDistance.Checked) // CurrLine1.DisplayLenght(Current3DWorld, 0.4); } } } #endregion #region Post Processings for (int k = 0; k < ListFormForControl.Count; k++) { FormForControl Obj = ListFormForControl.ElementAt(ListFormForControl.Count - k - 1); // the object is the master // // if (!Obj.IsMasterObject()) continue; if (!Obj.WindowForMaster.checkBoxDrawAssociatedDelaunay.Checked) continue; foreach (cMetaBiologicalObject CurrentMeta in MetaCellList) { Current3DWorld.AddGeometric3DObject(CurrentMeta.GenerateDelaunay(2.0f,true)); } } if (PostProcessWindow.checkBoxRemoveUnAssociatedObjects.Checked) { int RemovedObjects = Current3DWorld.RemoveNonAssociatedObjects(); Console.WriteLine(RemovedObjects + " objects removed."); } // if (PostProcessWindow.checkBoxExportMetaObjectSignatures.Checked) // { // if (CurrentTable == null) // { // CurrentTable = new DataTable(); // if (CurrentExperiment == null) // CurrentTable.Columns.Add(new DataColumn("Image Idx", typeof(int))); // else // { // CurrentTable.Columns.Add(new DataColumn("Image Col.", typeof(int))); // CurrentTable.Columns.Add(new DataColumn("Image Row", typeof(int))); // } // CurrentTable.Columns.Add(new DataColumn("Meta Object Name", typeof(string))); // foreach (string DescName in MetaCellList[0].GetSignatureNames()) // CurrentTable.Columns.Add(new DataColumn(DescName, typeof(double))); // CurrentTable.Columns.Add(new DataColumn("Class", typeof(double))); // } // foreach (cMetaBiologicalObject CurrentMeta in MetaCellList) // { // List<double> CurrentSignature = CurrentMeta.GetSignature(); // CurrentTable.Rows.Add(); // if (CurrentExperiment == null) // { // CurrentTable.Rows[CurrentTable.Rows.Count - 1][0] = IdxImageProcessed; // CurrentTable.Rows[CurrentTable.Rows.Count - 1][1] = CurrentMeta.Name; // for (int Idx = 0; Idx < CurrentSignature.Count; Idx++) // CurrentTable.Rows[CurrentTable.Rows.Count - 1][Idx + 2] = CurrentSignature[Idx]; // } // else // { // CurrentTable.Rows[CurrentTable.Rows.Count - 1][0] = CurrentExperiment.Column; // CurrentTable.Rows[CurrentTable.Rows.Count - 1][1] = CurrentExperiment.Row; // CurrentTable.Rows[CurrentTable.Rows.Count - 1][2] = CurrentMeta.Name; // for (int Idx = 0; Idx < CurrentSignature.Count; Idx++) // CurrentTable.Rows[CurrentTable.Rows.Count - 1][Idx + 3] = CurrentSignature[Idx]; // } // // Current3DWorld.CopyMetaObjectSignatureToTable(CurrentMeta, 0); // } // if (DataGrid != null) // { // DataGrid.dataGridViewForResults.DataSource = CurrentTable; // DataGrid.Update(); // IdxImageProcessed++; // } // } #endregion // //CurrentTable = new DataTable(); // if (CurrentExperiment == null) // { // if (PostProcessWindow.checkBoxDisplayBottomPlate.Checked) Current3DWorld.DisplayBottom(Color.FromArgb(255, 255, 255)); // Current3DWorld.SetBackgroundColor(PostProcessWindow.buttonChangeColorPositive.BackColor); // Current3DWorld.Render(); // } // // Current3DWorld.SetLinkToDataGridView(dataGridViewForClassif); cViewer3D V3D = new cViewer3D(); V3D.SetInputData(Current3DWorld); V3D.Run(); cDisplayToWindow DTW = new cDisplayToWindow(); DTW.SetInputData(V3D.GetOutPut()); DTW.Run(); DTW.Display(); }
//public void DrawPic() //{ // if (this.LUTManager == null) return; // if (this.ZNavigator == null) return; // int ZPos = ZNavigator.trackBarForZPos.Value; // ThisGraph = this.CreateGraphics(); // float ZoomFactor = Zoom / 100.0f; // int NewWidth = (int)(AssociatedImage.Width * ZoomFactor); // int NewHeight = (int)(AssociatedImage.Height * ZoomFactor); // this.Width = NewWidth; // this.Height = NewHeight; // if ((NewHeight == 0) || (NewWidth == 0)) return; // int PosViewX = (this.Width - NewWidth) / 2; // int PosViewY = (this.Height - NewHeight) / 2; // // this.Location = new Point(PosViewX,PosViewY); // BT = new Bitmap(NewWidth, NewHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // // Lock the bitmap's bits. // Rectangle rect = new Rectangle(0, 0, NewWidth, NewHeight); // System.Drawing.Imaging.BitmapData bmpData = BT.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, BT.PixelFormat); // // Get the address of the first line. // IntPtr ptr = bmpData.Scan0; // int scanline = Math.Abs(bmpData.Stride); // byte CurrentRed; // byte CurrentGreen; // byte CurrentBlue; // int RealX; // int RealY; // int NewStartX = (int)(this.StartViewX / ZoomFactor); // int NewStartY = (int)(this.StartViewY / ZoomFactor); // List<float> Min = new List<float>(); // List<float> Max = new List<float>(); // List<double> GammaList = new List<double>(); // for (int IdxChannel = 0; IdxChannel < this.AssociatedImage.GetNumChannels(); IdxChannel++) // { // if (this.LUTManager != null) // { // UserControlSingleLUT SingleLUT = (UserControlSingleLUT)this.LUTManager.panelForLUTS.Controls[IdxChannel]; // Min.Add((float)SingleLUT.numericUpDownMinValue.Value); // Max.Add((float)SingleLUT.numericUpDownMaxValue.Value); // GammaList.Add((double)SingleLUT.trackBarGamma.Value / 100.0); // } // } // #region Obsolete // // test for new display // //List<byte[][]> ListLut = new List<byte[][]>(); // //for (int IdxChannel = 0; IdxChannel < this.AssociatedImage.NumChannels; IdxChannel++) // //{ // // UserControlSingleLUT SingleLUT = (UserControlSingleLUT)this.LUTManager.panelForLUTS.Controls[IdxChannel]; // // if (SingleLUT.checkBoxIsActive.Checked == false) continue; // // ListLut.Add(SingleLUT.SelectedLUT); // //} // //ConvertImageFloatToRGB(AssociatedImage, 0, 255, ListLut, 0); // #endregion // // Declare an array to hold the bytes of the bitmap. // int bytes = scanline * NewHeight; // byte[] rgbValues = new byte[bytes]; // // Copy the RGB values into the array. // System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); // for (int IdxChannel = 0; IdxChannel < this.AssociatedImage.GetNumChannels(); IdxChannel++) // { // UserControlSingleLUT SingleLUT = (UserControlSingleLUT)this.LUTManager.panelForLUTS.Controls[IdxChannel]; // if (SingleLUT.checkBoxIsActive.Checked == false) continue; // byte[][] CurrentLUT = SingleLUT.SelectedLUT; // //ConvertImageFloatToRGB(AssociatedImage, 0, 255, SingleLUT.SelectedLUT, 0); // if (GammaList[IdxChannel] != 1) // { // for (int FullY = 0; FullY < NewHeight; FullY++) // { // RealY = (int)(FullY / ZoomFactor) + NewStartY; // if (RealY >= AssociatedImage.Height) RealY = AssociatedImage.Height - 1; // for (int FullX = 0; FullX < NewWidth; FullX++) // { // RealX = (int)(FullX / ZoomFactor) + NewStartX; // if (RealX >= AssociatedImage.Width) RealX = AssociatedImage.Width - 1; // float Value = AssociatedImage.SingleChannelImage[IdxChannel].Data[RealX + RealY * AssociatedImage.Width + ZPos * AssociatedImage.SliceSize]; // Value = (float)Math.Pow(Value, GammaList[IdxChannel]); // int ConvertedValue = (int)((((CurrentLUT[0].Length - 1) * (Value - Min[IdxChannel])) / (Max[IdxChannel] - Min[IdxChannel]))); // if (ConvertedValue < 0) ConvertedValue = 0; // if (ConvertedValue >= CurrentLUT[0].Length) ConvertedValue = CurrentLUT[0].Length - 1; // CurrentRed = (byte)CurrentLUT[0][ConvertedValue]; // CurrentGreen = (byte)CurrentLUT[1][ConvertedValue]; // CurrentBlue = (byte)CurrentLUT[2][ConvertedValue]; // double NewValue = rgbValues[3 * FullX + FullY * scanline] + CurrentBlue; // if (NewValue > 255) // rgbValues[3 * FullX + FullY * scanline] = 255; // else // rgbValues[3 * FullX + FullY * scanline] += CurrentBlue; // NewValue = rgbValues[3 * FullX + 1 + FullY * scanline] + CurrentGreen; // if (NewValue > 255) // rgbValues[3 * FullX + 1 + FullY * scanline] = 255; // else // rgbValues[3 * FullX + 1 + FullY * scanline] += CurrentGreen; // NewValue = rgbValues[3 * FullX + 2 + FullY * scanline] + CurrentRed; // if (NewValue > 255) // rgbValues[3 * FullX + 2 + FullY * scanline] = 255; // else // rgbValues[3 * FullX + 2 + FullY * scanline] += CurrentRed; // } // } // } // else // { // for (int FullY = 0; FullY < NewHeight; FullY++) // { // RealY = (int)(FullY / ZoomFactor) + NewStartY; // if (RealY >= AssociatedImage.Height) RealY = AssociatedImage.Height - 1; // for (int FullX = 0; FullX < NewWidth; FullX++) // { // RealX = (int)(FullX / ZoomFactor) + NewStartX; // if (RealX >= AssociatedImage.Width) RealX = AssociatedImage.Width - 1; // float Value = AssociatedImage.SingleChannelImage[IdxChannel].Data[RealX + RealY * AssociatedImage.Width + ZPos * AssociatedImage.SliceSize]; // int ConvertedValue = (int)((((CurrentLUT[0].Length - 1) * (Value - Min[IdxChannel])) / (Max[IdxChannel] - Min[IdxChannel]))); // if (ConvertedValue < 0) ConvertedValue = 0; // if (ConvertedValue >= CurrentLUT[0].Length) ConvertedValue = CurrentLUT[0].Length - 1; // CurrentRed = (byte)CurrentLUT[0][ConvertedValue]; // CurrentGreen = (byte)CurrentLUT[1][ConvertedValue]; // CurrentBlue = (byte)CurrentLUT[2][ConvertedValue]; // double NewValue = rgbValues[3 * FullX + FullY * scanline] + CurrentBlue; // if (NewValue > 255) // rgbValues[3 * FullX + FullY * scanline] = 255; // else // rgbValues[3 * FullX + FullY * scanline] += CurrentBlue; // NewValue = rgbValues[3 * FullX + 1 + FullY * scanline] + CurrentGreen; // if (NewValue > 255) // rgbValues[3 * FullX + 1 + FullY * scanline] = 255; // else // rgbValues[3 * FullX + 1 + FullY * scanline] += CurrentGreen; // NewValue = rgbValues[3 * FullX + 2 + FullY * scanline] + CurrentRed; // if (NewValue > 255) // rgbValues[3 * FullX + 2 + FullY * scanline] = 255; // else // rgbValues[3 * FullX + 2 + FullY * scanline] += CurrentRed; // } // } // } // } // // Copy the RGB values back to the bitmap // System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); // // Unlock the bits. // BT.UnlockBits(bmpData); // // Draw the modified image. // ThisGraph.DrawImage(BT, this.StartViewX, this.StartViewY); // DrawLayers(ZoomFactor); //} public Bitmap ConvertImageFloatToRGB(cImage ImageFloat, float Min, float Max, List<byte[][]> ListSelectedLUTs, int Z) { Bitmap BMP = new Bitmap(ImageFloat.Width, ImageFloat.Height, PixelFormat.Format24bppRgb); BitmapData bData = BMP.LockBits(new Rectangle(0, 0, ImageFloat.Width, ImageFloat.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); /*the size of the image in bytes */ int size = bData.Stride * bData.Height; /*Allocate buffer for image*/ byte[] ConvertedValues = new byte[size]; int Zpos = Z * ImageFloat.Width * ImageFloat.Height; int Ypos; float MAXMIN = Max - Min; double NewValue; byte CurrentRed; byte CurrentGreen; byte CurrentBlue; for (int Channel = 0; Channel < ImageFloat.GetNumChannels(); Channel++) { byte[][] SelectedLUT = ListSelectedLUTs[Channel]; int LUTLength = SelectedLUT[0].Length - 1; for (int j = 0; j < ImageFloat.Height; j++) { Ypos = j * AssociatedImage.Width; for (int i = 0; i < ImageFloat.Width; i++) { float Value = ImageFloat.SingleChannelImage[Channel].Data[i + Ypos + Zpos]; int ConvertedValue = (int)((LUTLength * (Value - Min)) / MAXMIN); if (ConvertedValue < 0) ConvertedValue = 0; else if (ConvertedValue > LUTLength) ConvertedValue = LUTLength; CurrentRed = (byte)SelectedLUT[0][ConvertedValue]; CurrentGreen = (byte)SelectedLUT[1][ConvertedValue]; CurrentBlue = (byte)SelectedLUT[2][ConvertedValue]; NewValue = ConvertedValues[i * 3 + j * bData.Stride] + CurrentBlue; if (NewValue > 255) ConvertedValues[i * 3 + j * bData.Stride] = 255; else ConvertedValues[i * 3 + j * bData.Stride] += CurrentBlue; NewValue = ConvertedValues[i * 3 + j * bData.Stride + 1] + CurrentGreen; if (NewValue > 255) ConvertedValues[i * 3 + j * bData.Stride + 1] = 255; else ConvertedValues[i * 3 + j * bData.Stride + 1] += CurrentGreen; NewValue = ConvertedValues[i * 3 + j * bData.Stride + 2] + CurrentRed; if (NewValue > 255) ConvertedValues[i * 3 + j * bData.Stride + 2] = 255; else ConvertedValues[i * 3 + j * bData.Stride + 2] += CurrentRed; //for (int RGBIdx = 0; RGBIdx < 3; RGBIdx++) //{ // NewValue = (ConvertedValues[i * 3 + j * bData.Stride + RGBIdx] + ConvertedValue); // if (NewValue >= LUTLength) NewValue = LUTLength - 1; // // now go through the LUT // //ConvertedValues[i * 3 + j * bData.Stride + 0] = SelectedLUT[2][NewValue]; // //ConvertedValues[i * 3 + j * bData.Stride + 1] = SelectedLUT[1][NewValue]; // ConvertedValues[i * 3 + j * bData.Stride + RGBIdx] = SelectedLUT[RGBIdx][NewValue]; //} //ConvertedValues[i * 3 + j * bData.Stride + Channel] = (byte)NewValue; } } } //for (int j = 0; j < ImageFloat.Height; j++) //{ // Ypos = j * AssociatedImage.Width; // for (int i = 0; i < ImageFloat.Width; i++) // { // BMP.SetPixel(i, j, Color.FromArgb(SelectedLUT[0][ConvertedValues[i+Ypos]], // SelectedLUT[1][ConvertedValues[i + Ypos]], // SelectedLUT[2][ConvertedValues[i + Ypos]])); // } //} /*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/ //System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, ConvertedValues, 0, size); //for (int i = 0; i < size; i += bitsPerPixel / 8) //{ // double magnitude = 1 / 3d * (ConvertedValues[i] + ConvertedValues[i + 1] + ConvertedValues[i + 2]); // //data[i] is the first of 3 bytes of color //} /* This override copies the data back into the location specified */ System.Runtime.InteropServices.Marshal.Copy(ConvertedValues, 0, bData.Scan0, ConvertedValues.Length); BMP.UnlockBits(bData); Form1 F = new Form1(); F.pictureBox1.Image = BMP; F.ShowDialog(); return BMP; }
public void AddInto(cImage SubImage, int Dest_PosX, int Dest_PosY, int Dest_PosZ, int Dest_Channel) { if (SubImage.GetNumChannels() > 1) return; for (int Z = 0; Z < SubImage.Depth; Z++) { int OriginalPosZ = Dest_PosZ + Z; if ((OriginalPosZ < 0) || (OriginalPosZ > this.Depth - 1)) continue; for (int Y = 0; Y < SubImage.Height; Y++) { int OriginalPosY = Dest_PosY + Y; if ((OriginalPosY < 0) || (OriginalPosY > this.Height - 1)) continue; for (int X = 0; X < SubImage.Width; X++) { int OriginalPosX = Dest_PosX + X; if ((OriginalPosX < 0) || (OriginalPosX > this.Width - 1)) continue; this.SingleChannelImage[Dest_Channel].Data[OriginalPosX + OriginalPosY * this.Width + OriginalPosZ * this.SliceSize] += SubImage.SingleChannelImage[0].Data[X + Y * SubImage.Width + Z * SubImage.SliceSize]; } } } }
public cImage(cImage Source, bool IsCopyData) { //Source.GetNumChannels(); this.Width = Source.Width; this.Height = Source.Height; this.Depth = Source.Depth; this.SliceSize = this.Height * this.Width; this.ImageSize = SliceSize * Depth; this.Resolution = new cPoint3D(Source.Resolution); this.SingleChannelImage = new cListSingleChannelImage(); for (int IdxChannel = 0; IdxChannel < Source.GetNumChannels(); IdxChannel++) { this.SingleChannelImage.Add(new cSingleChannelImage(Source.Width, Source.Height, Source.Depth, new cPoint3D(Source.Resolution))); this.SingleChannelImage[IdxChannel].Name = Source.SingleChannelImage[IdxChannel].Name; this.SingleChannelImage[IdxChannel].Data = new float[Source.SingleChannelImage[IdxChannel].Data.Length]; if (IsCopyData) Array.Copy(Source.SingleChannelImage[IdxChannel].Data, this.SingleChannelImage[IdxChannel].Data, Source.SingleChannelImage[IdxChannel].Data.Length); } }
protected VoxelList(int label, cImage labeledImage, cImage image, eConnectivity connectivity) { this.label = label; surfacePoints = new List<int[]>(); points = new List<int[]>(); indices = new List<int>(); values = new List<float[]>(); this.labeledImage = labeledImage; this.labeledImageData = labeledImage.SingleChannelImage[0].Data; this.image = image; if (image != null) { int NumChannels = image.GetNumChannels(); this.numBands = NumChannels; this.intensity = new float[NumChannels]; this.surfaceIntensity = new float[NumChannels]; this.maxIntensity = new float[NumChannels]; this.minIntensity = new float[NumChannels]; for (int b = 0; b < NumChannels; b++) { maxIntensity[b] = float.MinValue; minIntensity[b] = float.MaxValue; } } this.imageWidth = labeledImage.Width; this.imageHeight = labeledImage.Height; this.imageDepth = labeledImage.Depth; this.scanSliceSize = labeledImage.SliceSize; this.connectivity = connectivity; }
/// <summary> 3D connected components detector /// Computes various information on the detected objects /// </summary> /// <param name="labeledInputimage">Gray level input image (background value must be 0)</param> /// <param name="labeledOutputImage">Empty input image of same size that labeledInput image (can be null)</param> /// <param name="image">Original greyscale image (can be null)</param> /// <param name="band">the image band</param> /// <param name="connectivity">Connectivity. MUST be 6 or 26</param> /// <param name="minVolume">Minimum object volume to consider</param> /// <param name="maxVolume">Maximum object volume to consider</param> public ConnectedComponentSet(cImage labeledInputimage, cImage labeledOutputImage, cImage image, int band, eConnectivity connectivity, float minVolume, float maxVolume) { if (image != null && (image.Width != labeledInputimage.Width || image.Height != labeledInputimage.Height || image.Depth != labeledInputimage.Depth)) { if (connectivity == eConnectivity.THREED_6 || connectivity == eConnectivity.THREED_26) { // throw new DescriptorException("Uncompatible Image sizes"); } } if (labeledOutputImage != null && (labeledOutputImage.Width != labeledInputimage.Width || labeledOutputImage.Height != labeledInputimage.Height || labeledOutputImage.Depth != labeledInputimage.Depth)) { if (connectivity == eConnectivity.THREED_6 || connectivity == eConnectivity.THREED_26) { // throw new DescriptorException("Uncompatible Image sizes"); } if (labeledOutputImage.GetNumChannels() != 1) { // throw new DescriptorException("Output label image must be single band"); } } if (labeledInputimage.Depth == 1) { if (connectivity == eConnectivity.THREED_6 || connectivity == eConnectivity.THREED_26) { // throw new DescriptorException("Given connectivity is incompatible with the image depth"); } } else if (connectivity == eConnectivity.TWOD_4 || connectivity == eConnectivity.TWOD_8 || connectivity == eConnectivity.TWOD_24) { // throw new DescriptorException("Given connectivity is incompatible with the image depth"); } this.min = minVolume; this.max = maxVolume; this.connectivity = connectivity; this.width = labeledInputimage.Width; this.height = labeledInputimage.Height; this.depth = labeledInputimage.Depth; this.scanSliceSize = width * height; this.twoTimesWidth = 2 * width; if (labeledOutputImage == null) { this.labeledOutputImage = new cImage(labeledInputimage.Width, labeledInputimage.Height, labeledInputimage.Depth, 1); } else { this.labeledOutputImage = labeledOutputImage; } this.labeledOutput = this.labeledOutputImage.SingleChannelImage[0].Data; this.labeledInputimage = labeledInputimage; this.labeledInput = labeledInputimage.SingleChannelImage[band].Data; this.image = image; FindConnectedComponents(); }
private void buttonProcess_Click(object sender, EventArgs e) { ImageWidth = (int)numericUpDownMapWidth.Value; ImageHeight = (int)numericUpDownMapHeight.Value; if (this.radioButton2D.Checked) ImageDepth = 1; else ImageDepth = (int)numericUpDownMapDepth.Value; //GlobalInfo.ListCellularPhenotypes[(int)MachineLearning.Classes[j]] cImageDrawKernel GK = new cImageDrawKernel(); GK.sigma_x = (int)numericUpDownKernelSize.Value; GK.sigma_y = (int)numericUpDownKernelSize.Value; GK.sigma_z = (int)numericUpDownKernelSize.Value; GK.Run(); cImage K = GK.GetOutPut(); if (Parent.comboBoxAxeY.SelectedIndex == -1) return; if (Parent.comboBoxVolume.SelectedIndex == -1) return; cExtendedList ListVolumes = new cExtendedList(); ListX.Clear(); ListY.Clear(); ListZ.Clear(); cExtendedTable TableForDataToBeAnalyzed = Parent.GetActiveSignatures(false); for (int j = 0; j < TableForDataToBeAnalyzed[0].Count; j++) { ListX.Add(TableForDataToBeAnalyzed[Parent.comboBoxAxeX.SelectedIndex][j]); ListY.Add(TableForDataToBeAnalyzed[Parent.comboBoxAxeY.SelectedIndex][j]); } //MaxX = ListX.Max(); //MinX = ListX.Min(); //MaxY = ListY.Max(); //MinY = ListY.Min(); MaxX = Parent.chartForPoints.ChartAreas[0].AxisX.Maximum; MinX = Parent.chartForPoints.ChartAreas[0].AxisX.Minimum; MaxY = Parent.chartForPoints.ChartAreas[0].AxisY.Maximum; MinY = Parent.chartForPoints.ChartAreas[0].AxisY.Minimum; //MaxY = Parent.MaxY; //MinY = Parent.MinY; if (this.radioButton3D.Checked) { for (int j = 0; j < TableForDataToBeAnalyzed[0].Count; j++) { ListZ.Add(TableForDataToBeAnalyzed[Parent.comboBoxVolume.SelectedIndex][j]); } MaxZ = ListZ.Max(); MinZ = ListZ.Min(); } DensityMaps = new cImage(ImageWidth, ImageHeight, ImageDepth, cGlobalInfo.ListCellularPhenotypes.Count); int[] ClassPopulations = new int[cGlobalInfo.ListCellularPhenotypes.Count]; if (this.radioButton3D.Checked) { int Idx = 0; for (int j = 0; j < Parent.InputTable[0].Count; j++) { if (Parent.PanelPhenotypeSelection.GetListSelectedClass()[(int)Parent.MachineLearning.Classes[j]]) { double TmpValueX = (ImageWidth * (ListX[Idx] - MinX)) / (MaxX - MinX) - K.Width / 2; double TmpValueY = ImageHeight - (ImageHeight * (ListY[Idx] - MinY)) / (MaxY - MinY) - K.Height / 2; double TmpValueZ = ImageDepth - (ImageDepth * (ListZ[Idx] - MinZ)) / (MaxZ - MinZ) - K.Depth / 2; DensityMaps.AddInto(K, (int)TmpValueX, (int)TmpValueY, (int)TmpValueZ, (int)Parent.MachineLearning.Classes[j]); ClassPopulations[(int)Parent.MachineLearning.Classes[j]]++; Idx++; } } } else { int Idx = 0; for (int j = 0; j < Parent.InputTable[0].Count; j++) { if (Parent.PanelPhenotypeSelection.GetListSelectedClass()[(int)Parent.MachineLearning.Classes[j]]) { double TmpValueX = (ImageWidth * (ListX[Idx] - MinX)) / (MaxX - MinX) - K.Width / 2; double TmpValueY = ImageHeight - (ImageHeight * (ListY[Idx] - MinY)) / (MaxY - MinY) - K.Height / 2; DensityMaps.AddInto(K, (int)TmpValueX, (int)TmpValueY, 0, (int)Parent.MachineLearning.Classes[j]); ClassPopulations[(int)Parent.MachineLearning.Classes[j]]++; Idx++; } } } cListExtendedTable TablesForDensity = new cListExtendedTable(DensityMaps); for (int idxChannel = 0; idxChannel < DensityMaps.GetNumChannels(); idxChannel++) { DensityMaps.SingleChannelImage[idxChannel].Name = cGlobalInfo.ListCellularPhenotypes[idxChannel].Name; float Sum = 1; if (checkBoxNormalized.Checked) { Sum = (float)TablesForDensity[idxChannel].Sum(); if (Sum <= 0.0) continue; for (int i = 0; i < DensityMaps.SingleChannelImage[idxChannel].Data.Length; i++) { //if (ClassPopulations[idxChannel] > 0) DensityMaps.SingleChannelImage[idxChannel].Data[i] = (100 * DensityMaps.SingleChannelImage[idxChannel].Data[i]) / Sum; } } else { for (int i = 0; i < DensityMaps.SingleChannelImage[idxChannel].Data.Length; i++) { // if (ClassPopulations[idxChannel] > 0) DensityMaps.SingleChannelImage[idxChannel].Data[i] = DensityMaps.SingleChannelImage[idxChannel].Data[i]; } } } cDisplaySingleImage IV = new cDisplaySingleImage(); DensityMaps.Name = "Density Maps. K["+ this.numericUpDownKernelSize.Value +"]"; if (this.checkBoxModifyColors.Checked) IV.ListLinearMaxColor = new List<Color>(); int RealIdxChannel = 0; for (int idxChannel = 0; idxChannel < ClassPopulations.Length; idxChannel++) { if (ClassPopulations[idxChannel] == 0) DensityMaps.SingleChannelImage.RemoveAt(RealIdxChannel--); else { if (this.checkBoxModifyColors.Checked) IV.ListLinearMaxColor.Add(cGlobalInfo.ListCellularPhenotypes[idxChannel].ColourForDisplay); } RealIdxChannel++; } IV.SetInputData(DensityMaps); IV.Run(); this.buttonApply.Enabled = true; }