public void SetInputData(cSingleChannelImage InputImage) { this.Input = InputImage; base.Title += ": " + Input.Name; this.InputVolume = new cVolumeRendering3D(InputImage, new Classes._3D.cPoint3D(0, 0, 0),null, null); }
public UserControlSingleLUT(cImagePanel CurrentFormForImageDisplay, cSingleChannelImage AssociatedImageBand, int InitialIdx) { this.AssociatedImageBand = AssociatedImageBand; this.CurrentFormForImageDisplay = CurrentFormForImageDisplay; this.GlobalInfo = CurrentFormForImageDisplay.GlobalInfo; this.SelectedLUT = ListLUT.LUT_LINEAR; InitializeComponent(); if (InitialIdx == 0) { this.MaxColorForLinear = Color.FromArgb(255, 255, 0, 0); } else if (InitialIdx == 1) { this.MaxColorForLinear = Color.FromArgb(255, 0, 255, 0); } else if (InitialIdx == 2) { this.MaxColorForLinear = Color.FromArgb(255, 0, 0, 255); } else { this.MaxColorForLinear = Color.FromArgb(255, 255, 0, 0); } UpDateLinearLUT(); comboBoxForLUT.Text = "Linear "; UpDateColorSampleImage(); AssociatedImageBand.UpDateMin(); AssociatedImageBand.UpDateMax(); // this.numericUpDownMinValue.ValueChanged -= new EventHandler(numericUpDownMinValue_ValueChanged); this.numericUpDownMinValue.Value = (decimal)AssociatedImageBand.Min; this.numericUpDownMinValue.ValueChanged += new EventHandler(numericUpDownMinValue_ValueChanged); // this.numericUpDownMaxValue.ValueChanged -= new EventHandler(numericUpDownMaxValue_ValueChanged); this.numericUpDownMaxValue.Value = (decimal)AssociatedImageBand.Max; this.numericUpDownMaxValue.ValueChanged += new EventHandler(numericUpDownMaxValue_ValueChanged); this.trackBarOpacity.ValueChanged += new System.EventHandler(this.trackBarOpacity_ValueChanged); this.checkBoxIsActive.CheckedChanged += new System.EventHandler(this.checkBoxIsActive_CheckedChanged); this.comboBoxForLUT.SelectedIndexChanged += new System.EventHandler(this.comboBoxForLUT_SelectedIndexChanged); this.trackBarGamma.ValueChanged += new System.EventHandler(this.trackBarGamma_ValueChanged); this.comboBoxForLUT.SelectedValueChanged += new System.EventHandler(this.comboBoxForLUT_SelectedValueChanged); this.pictureBoxForColorSample.DoubleClick += new System.EventHandler(this.pictureBoxForColorSample_DoubleClick); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.UserControlSingleLUT_MouseDown); this.toolStripMenuItemGammaDefault.Click += new System.EventHandler(this.toolStripMenuItemGammaDefault_Click); this.textBoxForName.TextChanged += new System.EventHandler(this.textBoxForName_TextChanged); this.BringToFront(); }
public void SetInputData(cSingleChannelImage Input) { this.Input = Input; }
void LoadFromPath(/*string Path, string FileName*/List<cImageMetaInfo> ListImageMetaInfo) { if (ListImageMetaInfo == null) return; int ChannelStart = 0; for (int IdxName = 0; IdxName < ListImageMetaInfo.Count; IdxName++) { string CurrentName = ListImageMetaInfo[IdxName].FileName; if (CurrentName == "") continue; if (CurrentName.Contains("http://")) { try { using (WebClient Client = new WebClient()) { string[] ListForExt = CurrentName.Split('.'); Client.DownloadFile(CurrentName, "Tmp." + ListForExt[ListForExt.Length - 1]); CurrentName = "Tmp." + ListForExt[ListForExt.Length - 1]; } } catch (Exception) { continue; } } if ((File.Exists(CurrentName) == false)) continue; string[] ListSplits = CurrentName.Split('.'); string Extension = ListSplits[ListSplits.Length - 1].ToLower(); byte[] rgbValues = null; int NumBytePerPixel = 0; int NumBitsPerPixel = 0; int NumChannels = 0; object ResMeta = null; switch (Extension) { #region Cellomics c01 - BioFormats case "c01": [email protected] MyCellomicsReader = new [email protected](); MyCellomicsReader.setId(CurrentName); int SerieCurr = -1; for (int IdxSerie = 0; IdxSerie < MyCellomicsReader.getSeriesUsedFiles().Count(); IdxSerie++) { if (MyCellomicsReader.getSeriesUsedFiles()[IdxSerie] == CurrentName) { SerieCurr = IdxSerie; break; } } MyCellomicsReader.setSeries(SerieCurr); rgbValues = MyCellomicsReader.openBytes(0); //int ImC = MyCellomicsReader.getImageCount(); this.Width = MyCellomicsReader.getSizeX(); // ImageProcessorReader r = new ImageProcessorReader( //new ChannelSeparator(LociPrefs.makeImageReader())); this.Height = MyCellomicsReader.getSizeY(); this.Depth = MyCellomicsReader.getSizeZ(); NumChannels = MyCellomicsReader.getSizeC(); NumBitsPerPixel = MyCellomicsReader.getBitsPerPixel(); MyCellomicsReader.close(); break; #endregion #region tiff - BioFormats case "tiff": [email protected] MyTiffReader = new [email protected](); MyTiffReader.setId(CurrentName); rgbValues = MyTiffReader.openBytes(0); this.Width = MyTiffReader.getSizeX(); this.Height = MyTiffReader.getSizeY(); this.Depth = MyTiffReader.getSizeZ(); NumChannels = MyTiffReader.getSizeC(); NumBitsPerPixel = MyTiffReader.getBitsPerPixel(); MyTiffReader.close(); break; #endregion #region LSM - BioFormats case "lsm": [email protected] MyLSMReader = new [email protected](); MyLSMReader.setId(CurrentName); this.Width = MyLSMReader.getSizeX(); this.Height = MyLSMReader.getSizeY(); NumChannels = MyLSMReader.getSizeC(); this.Depth = MyLSMReader.getSizeZ(); this.Name = CurrentName; this.SliceSize = this.Width * this.Height; this.ImageSize = SliceSize * Depth; if (IdxName == 0) this.SingleChannelImage = new cListSingleChannelImage(); #region GetMetaData ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeX"); if (ResMeta == null) this.Resolution.X = 1; else this.Resolution.X = ((java.lang.Double)ResMeta).doubleValue(); ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeY"); if (ResMeta == null) this.Resolution.X = 1; else this.Resolution.Y = ((java.lang.Double)ResMeta).doubleValue(); ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeZ"); if (ResMeta == null) this.Resolution.Z = 1; else this.Resolution.Z = ((java.lang.Double)ResMeta).doubleValue(); #endregion for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++) this.SingleChannelImage.Add(new cSingleChannelImage(this.Width, this.Height, this.Depth, new cPoint3D(this.Resolution))); float TmpValue = 0; byte[] TmpTable; for (int IdxZ = 0; IdxZ < this.Depth; IdxZ++) { for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++) { TmpTable = MyLSMReader.openBytes(IdxZ * NumChannels + IdxChannel); for (int IdxY = 0; IdxY < this.Height; IdxY++) for (int IdxX = 0; IdxX < this.Width; IdxX++) { TmpValue = TmpTable[IdxX + IdxY * this.Width]; this.SingleChannelImage[IdxChannel + ChannelStart].Data[IdxX + IdxY * this.Width + IdxZ * this.SliceSize] = TmpValue; } } } NumBitsPerPixel = MyLSMReader.getBitsPerPixel(); // if the meta data are ok, take the name for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++) { ResMeta = MyLSMReader.getSeriesMetadataValue("DataChannel #" + (IdxChannel + 1) + " Name"); if (ResMeta != null) this.SingleChannelImage[IdxChannel + ChannelStart].Name = (string)ResMeta; } goto NEXTLOOP; #endregion #region tif - FreeImage case "tif": //Image<Gray, Single> myImage = new Image<Gray, Single>(@CurrentName); //var watch = Stopwatch.StartNew(); int PageCount = 1; this.Depth = PageCount; NumChannels = 1; Mat myImage = new Mat(CurrentName, Emgu.CV.CvEnum.LoadImageType.AnyDepth); //watch.Stop(); //cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("Opencv = " + watch.ElapsedMilliseconds + "\n"); for (int IDxPlane = 0; IDxPlane < PageCount; IDxPlane++) { if (IDxPlane == 0) { this.Width = myImage.Width; this.Height = myImage.Height; this.Resolution.X = 1; this.Resolution.Y = 1; NumBitsPerPixel = 16; for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++) { cSingleChannelImage TmpChannelImage = new cSingleChannelImage(this.Width, this.Height, this.Depth, new cPoint3D(1, 1, 1)); if (ListImageMetaInfo[IdxName].Name != "") TmpChannelImage.Name = ListImageMetaInfo[IdxName].Name; if (ListImageMetaInfo[IdxChannel].ResolutionX != -1) this.Resolution.X = ListImageMetaInfo[IdxChannel].ResolutionX; if (ListImageMetaInfo[IdxChannel].ResolutionY != -1) this.Resolution.Y = ListImageMetaInfo[IdxChannel].ResolutionY; if (ListImageMetaInfo[IdxChannel].ResolutionZ != -1) this.Resolution.Z = ListImageMetaInfo[IdxChannel].ResolutionZ; Image<Gray, float> myImage2 = myImage.ToImage<Gray, float>(); //var watch2 = Stopwatch.StartNew(); TmpChannelImage.SetNewDataFromOpenCV(myImage2); //watch2.Stop(); //cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("Convert = " + watch2.ElapsedMilliseconds + "\n"); this.SingleChannelImage.Add(TmpChannelImage); } } } this.Name = CurrentName; this.SliceSize = this.Width * this.Height; this.ImageSize = SliceSize * Depth; //goto NEXTLOOP; break; } #endregion #endregion NEXTLOOP:; ChannelStart += NumChannels; } }
public cImage(cSingleChannelImage Source, bool CopyData) { // this.NumChannels = 1; this.Width = Source.Width; this.Height = Source.Height; this.Depth = Source.Depth; this.Resolution = new cPoint3D(Source.Resolution); this.SliceSize = this.Height * this.Width; this.ImageSize = SliceSize * Depth; if (CopyData == true) { this.SingleChannelImage = new cListSingleChannelImage(); this.SingleChannelImage.Add(new cSingleChannelImage(Source.Width, Source.Height, Source.Depth, Source.Resolution)); this.SingleChannelImage[0].Name = Source.Name; this.SingleChannelImage[0].Data = new float[Source.Data.Length]; Array.Copy(Source.Data, this.SingleChannelImage[0].Data, Source.Data.Length); } else { this.SingleChannelImage.Add(Source); } this.Name = Source.Name; }
public cVolumeRendering3D(cSingleChannelImage SingleChannelImage, cPoint3D Pos, byte[][] NewLUT, c3DNewWorld AssociatedWorld) { if (SingleChannelImage.Data == null) return; baseInit(AssociatedWorld); this.SetName("Volume 3D [" + SingleChannelImage.Name + "]"); this.LUT = NewLUT; vtk_volume = vtkVolume.New(); vtkImageData imageData = vtkImageData.New(); vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); voi = vtkExtractVOI.New(); ColorTransferFunction = vtkColorTransferFunction.New(); for (int i = 0; i < SingleChannelImage.Width * SingleChannelImage.Height * SingleChannelImage.Depth; i++) { UshortArray.InsertTuple1(i, (ushort)SingleChannelImage.Data[i]); // data are converted to UShort } imageData = vtkImageData.New(); imageData.SetDimensions(SingleChannelImage.Width, SingleChannelImage.Height, SingleChannelImage.Depth); imageData.SetOrigin(0, 0, 0); if ((SingleChannelImage.Resolution.X == 0) || (SingleChannelImage.Resolution.Y == 0) || (SingleChannelImage.Resolution.Z == 0)) imageData.SetSpacing(1.0, 1.0, 1.0); else imageData.SetSpacing(SingleChannelImage.Resolution.X, SingleChannelImage.Resolution.Y, SingleChannelImage.Resolution.Z); imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, SingleChannelImage.Width - 1, 0, SingleChannelImage.Height - 1, 0, SingleChannelImage.Depth - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(range[0], 0.0); opacityTransferFunction.AddPoint(range[1], 0.3); //opacityTransferFunction.AddPoint(2000, 0.1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); if (LUT == null) { //cLUT MyLut = new cLUT(); //LUT = MyLut.LUT_JET; ColorTransferFunction.AddRGBPoint(0, 0 , 0, 0); ColorTransferFunction.AddRGBPoint(1, 1, 1, 1); } //double LUTSize = LUT[0].Length; //for (int i = 0; i < (int)LUTSize; i++) //{ // colorTransferFunction.AddRGBPoint(i, LUT[0][i] / LUTSize, LUT[1][i] / LUTSize, LUT[2][i] / LUTSize); //} ColorTransferFunction.Build(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(ColorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToNearest(); volumeProperty.ShadeOff(); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOn(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }
public cVolumeRendering3D(cSingleChannelImage SingleChannelImage, cPoint3D Pos, byte[][] NewLUT) { this.LUT = NewLUT; vtk_volume = vtkVolume.New(); vtk_volume.PickableOn(); vtkImageData imageData = vtkImageData.New(); vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); vtkExtractVOI voi = vtkExtractVOI.New(); vtkPiecewiseFunction opacityTransferFunction = vtkPiecewiseFunction.New(); vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New(); vtkVolumeProperty volumeProperty = vtkVolumeProperty.New(); for (int i = 0; i < SingleChannelImage.Width * SingleChannelImage.Height * SingleChannelImage.Depth; i++) { UshortArray.InsertTuple1(i, (ushort)SingleChannelImage.Data[i]); } imageData = vtkImageData.New(); imageData.SetDimensions(SingleChannelImage.Width, SingleChannelImage.Height, SingleChannelImage.Depth); imageData.SetOrigin(0, 0, 0); if ((SingleChannelImage.Resolution.X == 0) || (SingleChannelImage.Resolution.Y == 0) || (SingleChannelImage.Resolution.Z == 0)) imageData.SetSpacing(1.0, 1.0, 1.0); else imageData.SetSpacing(SingleChannelImage.Resolution.X, SingleChannelImage.Resolution.Y, SingleChannelImage.Resolution.Z); imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, SingleChannelImage.Width - 1, 0, SingleChannelImage.Height - 1, 0, SingleChannelImage.Depth - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(0, 0.0); opacityTransferFunction.AddPoint(255, 1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); if (LUT == null) { cLUT MyLut = new cLUT(); LUT = MyLut.LUT_JET; } double LUTSize = LUT[0].Length; for (int i = 0; i < (int)LUTSize - 1; i++) { colorTransferFunction.AddRGBPoint(i, this.LUT[0][i] / LUTSize, this.LUT[1][i] / LUTSize, this.LUT[2][i] / LUTSize); } colorTransferFunction.Build(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(colorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); volumeProperty.ShadeOff(); volumeProperty.SetAmbient(0.6); volumeProperty.SetDiffuse(0.6); volumeProperty.SetSpecular(0.1); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOn(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }