public Bitmap konwertujObraz(Image obraz1, int przekroj = 0) { uint r = obraz1.GetWidth(); // VectorUInt32 w = new VectorUInt32(new[] { r, 512, 4 + 1 }); VectorInt32 start = new VectorInt32(new[] { 0, 0, 0 }); VectorInt32 size1 = new VectorInt32(new[] { 512, 512, 1 }); obraz1 = WybierzPrzekroj(obraz1, przekroj); IntensityWindowingImageFilter normalize = new IntensityWindowingImageFilter(); normalize.SetOutputMinimum(0); normalize.SetOutputMaximum(255); obraz1 = normalize.Execute(obraz1); PixelIDValueEnum u = PixelIDValueEnum.sitkFloat32; int len = 1; Image input = SimpleITK.Cast(obraz1, u); VectorUInt32 size = input.GetSize(); for (int dim = 0; dim < input.GetDimension(); dim++) { len *= (int)size[dim]; } IntPtr buffer = input.GetBufferAsFloat(); float bufferPtr = (float)buffer.ToInt32(); float[] bufferAsArray = new float[len]; float[,] newData = new float[size[0], size[1]]; Marshal.Copy(buffer, bufferAsArray, 0, len); obrazBitmap = new Bitmap(Convert.ToInt32(size[0]), Convert.ToInt32(size[1])); for (int j = 0; j < size[1]; j++) { for (int i = 0; i < size[0]; i++) { var bur = bufferAsArray[j * size[1] + i]; System.Drawing.Color newColor = System.Drawing.Color.FromArgb((int)bur, 0, 0, 0); obrazBitmap.SetPixel(j, i, newColor); } } Color s = obrazBitmap.GetPixel(34, 56); return(obrazBitmap); }
public Bitmap konwertujObraz(Image obraz1, int przekroj = 0) { uint r = obraz1.GetWidth(); // VectorUInt32 w = new VectorUInt32(new[] { r, 512, 4 + 1 }); VectorInt32 start = new VectorInt32(new[]{ 0, 0, 0 }); VectorInt32 size1 = new VectorInt32(new[]{ 512, 512, 1 }); obraz1 = WybierzPrzekroj(obraz1, przekroj); IntensityWindowingImageFilter normalize = new IntensityWindowingImageFilter(); normalize.SetOutputMinimum(0); normalize.SetOutputMaximum(255); obraz1 = normalize.Execute(obraz1); PixelIDValueEnum u = PixelIDValueEnum.sitkFloat32; int len = 1; Image input= SimpleITK.Cast(obraz1, u); VectorUInt32 size = input.GetSize(); for (int dim = 0; dim < input.GetDimension(); dim++) { len *= (int)size[dim]; } IntPtr buffer = input.GetBufferAsFloat(); float bufferPtr = (float)buffer.ToInt32(); float[] bufferAsArray = new float[len]; float[,] newData = new float[size[0], size[1]]; Marshal.Copy(buffer, bufferAsArray, 0, len); obrazBitmap = new Bitmap(Convert.ToInt32(size[0]), Convert.ToInt32(size[1])); for (int j = 0; j < size[1]; j++) { for (int i = 0; i < size[0]; i++) { var bur = bufferAsArray[j * size[1] + i]; System.Drawing.Color newColor = System.Drawing.Color.FromArgb((int)bur, 0, 0, 0); obrazBitmap.SetPixel(j, i, newColor); } } Color s= obrazBitmap.GetPixel(34, 56); return obrazBitmap; }