public cDisplayTable(string Title, string[] ColumnNames, List<string[]> Values, cGlobalInfo GlobalInfo, bool IsMINE) { this.Text = Title; this.TableValues = new DataTable(); this.dataGridViewForTable.Columns.Clear(); foreach (string Name in ColumnNames) { this.TableValues.Columns.Add(new DataColumn(Name, typeof(string))); } //this.TableValues.Columns.Add(new DataColumn("", typeof(string))); //double[] Mins = new double[IsDisplayColorMap.Count]; //double[] Maxs = new double[IsDisplayColorMap.Count]; //for (int idx = 0; idx < Mins.Length; idx++) //{ // Mins[idx] = double.MaxValue; // Maxs[idx] = double.MinValue; //} for (int Row = 0; Row < Values.Count; Row++) { this.TableValues.Rows.Add(); for (int idxString = 0; idxString < Values[Row].Length; idxString++) { string CurrentString = Values[Row][idxString]; this.TableValues.Rows[Row][idxString] = CurrentString; } } this.dataGridViewForTable.DataSource = this.TableValues; this.Show(); if (IsMINE) { cLUT LUT = new cLUT(); for (int Row = 0; Row < Values.Count; Row++) { for (int idxString = 0; idxString < Values[Row].Length; idxString++) { string CurrentString = Values[Row][idxString]; if ((idxString == 2) || (idxString == 7)) { int ConvertedValue = (int)((LUT.LUT_GREEN_TO_RED[0].Length - 1) * Math.Abs(double.Parse(CurrentString))); Color Coul = Color.FromArgb(LUT.LUT_GREEN_TO_RED[0][ConvertedValue], LUT.LUT_GREEN_TO_RED[1][ConvertedValue], LUT.LUT_GREEN_TO_RED[2][ConvertedValue]); this.dataGridViewForTable.Rows[Row].Cells[idxString].Style.BackColor = Coul; this.dataGridViewForTable.Rows[Row].Cells[idxString].Style.ForeColor = Color.White; } } } } }
/// <summary> /// Build a BITMAP from a cImage /// </summary> /// <param name="ZoomFactor"></param> /// <param name="ListMin">Minimum values for each band (if NULL then automatically computed)</param> /// <param name="ListMax">Maximum values for each band (if NULL then automatically computed)</param> /// <param name="ListLUTs">use cLUT ListLUT = new cLUT() to build your LUT</param> /// <returns></returns> public Bitmap GetBitmap(float ZoomFactor, cImageDisplayProperties ImageDisplayProperties, List<byte[][]> ListLUTs) { if ((this.Width == 0) || (this.Height == 0)) return null; if (ListLUTs == null) { ListLUTs = new List<byte[][]>(); cLUT LUT = new cLUT(); if (this.GetNumChannels() == 1) { ListLUTs.Add(LUT.LUT_LINEAR); } else if (this.GetNumChannels() == 2) { ListLUTs.Add(LUT.LUT_LINEAR_RED); ListLUTs.Add(LUT.LUT_LINEAR_GREEN); } else if (this.GetNumChannels() == 3) { ListLUTs.Add(LUT.LUT_LINEAR_RED); ListLUTs.Add(LUT.LUT_LINEAR_GREEN); ListLUTs.Add(LUT.LUT_LINEAR_BLUE); } else { ListLUTs.Add(LUT.LUT_LINEAR_RED); ListLUTs.Add(LUT.LUT_LINEAR_GREEN); ListLUTs.Add(LUT.LUT_LINEAR_BLUE); for (int i = 0; i < this.GetNumChannels() - 3; i++) { ListLUTs.Add(LUT.LUT_LINEAR); } } } List<double> ListMax = new List<double>(); List<double> ListMin = new List<double>(); if (ImageDisplayProperties != null) { if (ImageDisplayProperties.ListMax == null) { for (int i = 0; i < this.GetNumChannels(); i++) { this.SingleChannelImage[i].UpDateMax(); ListMax.Add(this.SingleChannelImage[i].Max); } } else ListMax = ImageDisplayProperties.ListMax; if (ImageDisplayProperties.ListMin == null) { for (int i = 0; i < this.GetNumChannels(); i++) { this.SingleChannelImage[i].UpDateMin(); ListMin.Add(this.SingleChannelImage[i].Min); } } else ListMin = ImageDisplayProperties.ListMin; } else { for (int i = 0; i < this.GetNumChannels(); i++) { this.SingleChannelImage[i].UpDateMax(); ListMax.Add(this.SingleChannelImage[i].Max); } for (int i = 0; i < this.GetNumChannels(); i++) { this.SingleChannelImage[i].UpDateMin(); ListMin.Add(this.SingleChannelImage[i].Min); } } List<bool> ListActive = null; if ((ImageDisplayProperties == null) || (ImageDisplayProperties.ListActive == null)) { ListActive = new List<bool>(); for (int i = 0; i < this.GetNumChannels(); i++) { ListActive.Add(true); } } else ListActive = ImageDisplayProperties.ListActive; int NewWidth = (int)(this.Width * ZoomFactor); int NewHeight = (int)(this.Height * ZoomFactor); Bitmap BMPToBeReturned = 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 = BMPToBeReturned.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, BMPToBeReturned.PixelFormat); // Get the address of the first line. IntPtr ptr = bmpData.Scan0; int scanline = Math.Abs(bmpData.Stride); int bytes = scanline * NewHeight; byte[] rgbValues = new byte[bytes]; byte CurrentRed; byte CurrentGreen; byte CurrentBlue; int RealX; int RealY; // Copy the RGB values into the array. System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); for (int IdxChannel = 0; IdxChannel < this.GetNumChannels(); IdxChannel++) { if (!ListActive[IdxChannel]) continue; byte[][] CurrentLUT = ListLUTs[IdxChannel]; for (int FullY = 0; FullY < NewHeight; FullY++) { RealY = (int)(FullY / ZoomFactor); if (RealY >= this.Height) RealY = this.Height - 1; for (int FullX = 0; FullX < NewWidth; FullX++) { RealX = (int)(FullX / ZoomFactor); if (RealX >= this.Width) RealX = this.Width - 1; float Value = this.SingleChannelImage[IdxChannel].Data[RealX + RealY * this.Width]; int ConvertedValue = (int)((((CurrentLUT[0].Length - 1) * (Value - ListMin[IdxChannel])) / (ListMax[IdxChannel] - ListMin[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. BMPToBeReturned.UnlockBits(bmpData); return BMPToBeReturned; }
public FormToDisplayDistanceMap(cPlate CurrentPlate) { // this.CurrentScreening = CompleteScreening; cLUT TmpLUT = new cLUT(); this.LUT = TmpLUT.LUT_FIRE; this.AssociatedPlate = CurrentPlate; bool ResMiss = false; //this.MouseDoubleClick += new MouseEventHandler(this.FormToDisplayPlate_MouseDoubleClick); this.MouseClick += new MouseEventHandler(this.FormToDisplayDistanceMap_MouseClick); ValuesMatrix = new double[CurrentPlate.ListActiveWells.Count][]; for (int i = 0; i < ValuesMatrix.Length; i++) ValuesMatrix[i] = new double[CurrentPlate.ListActiveWells.Count]; RecomputeDistances(eDistances.EUCLIDEAN); this.SetNewCellSize(2); }
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] }