void ShowFrame(string fileName) { var filemgr = application_.FileManager; if (filemgr != null) { IImageDataSet dataSet = filemgr.OpenFile(fileName, FileAccess.Read); IImageData d = dataSet.GetFrame(0, 0); // Convert IImageData To Bitmap System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(d.Width, d.Height); ushort[] data = new ushort[bmp.Width * bmp.Height]; // convert them all to the smallest (simple example for now) var pixels = bmp.Width * bmp.Height; switch (d.Format) { case ImageDataFormat.MonochromeFloating32: { float[] ptr = (float[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; case ImageDataFormat.MonochromeUnsigned16: { ushort[] ptr = (ushort[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; case ImageDataFormat.MonochromeUnsigned32: { uint[] ptr = (uint[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; } short rgb_value = 0; int i = 0; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { rgb_value = (short)((ushort)data[i] / (ushort)256); bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(rgb_value, rgb_value, rgb_value)); i++; } } // Convert To WPF Bitmap System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); // Set the source image1.Source = bitmapSource; // Show the image in a new display viewer viewer_.DisplayViewer.Display("Sample Display", dataSet); } }
/////////////////////////////////////////////////////////////////////// // Perform the actual transformation /////////////////////////////////////////////////////////////////////// public void Transform(IImageData data, int roi) { // Hint use locals (accessing on Interface forces boundary crossing) // that will be unbearably slow. int dW = data.Width; // Boundary Crossing int dH = data.Height; // Boundary Crossing switch (data.Format) { case ImageDataFormat.MonochromeUnsigned16: { ushort[] ptr = (ushort[])data.GetData(); // Input Data // Loop Width & Height(Quick and Dirty Padding Of 2) // This Avoids a lot of boundary checking or reflection and increases speed for (int xx = 2; xx < dW - 2; xx++) { for (int yy = 2; yy < dH - 2; yy++) { double GY = 0, GX = 0; // Compute the X and Y Components for (int i = 0; i < 9; i++) { int idx = indexBuffers_[roi][xx, yy, i]; GY += ptr[idx] * gy[i]; GX += ptr[idx] * gx[i]; } // Magnitude double G = Math.Sqrt(GX * GX + GY * GY); // Put the Magnitude into the output buffer retDataUs_[roi][yy * dW + xx] = (ushort)G; } } // Write the output buffer to the IImageData // Boundary Crossing data.SetData(retDataUs_[roi]); } break; case ImageDataFormat.MonochromeUnsigned32: { uint[] ptr = (uint[])data.GetData(); // Input Data // Loop Width & Height(Quick and Dirty Padding Of 2) // This Avoids a lot of boundary checking or reflection and increases speed for (int xx = 2; xx < dW - 2; xx++) { for (int yy = 2; yy < dH - 2; yy++) { double GY = 0, GX = 0; // Compute the X and Y Components for (int i = 0; i < 9; i++) { int idx = indexBuffers_[roi][xx, yy, i]; GY += ptr[idx] * gy[i]; GX += ptr[idx] * gx[i]; } // Magnitude double G = Math.Sqrt(GX * GX + GY * GY); // Put the Magnitude into the output buffer retDataI_[roi][yy * dW + xx] = (uint)G; } } // Write the output buffer to the IImageData // Boundary Crossing data.SetData(retDataI_[roi]); } break; case ImageDataFormat.MonochromeFloating32: { float[] ptr = (float[])data.GetData(); // Input Data // Loop Width & Height(Quick and Dirty Padding Of 2) // This Avoids a lot of boundary checking or reflection and increases speed for (int xx = 2; xx < dW - 2; xx++) { for (int yy = 2; yy < dH - 2; yy++) { double GY = 0, GX = 0; // Compute the X and Y Components for (int i = 0; i < 9; i++) { int idx = indexBuffers_[roi][xx, yy, i]; GY += ptr[idx] * gy[i]; GX += ptr[idx] * gx[i]; } // Magnitude double G = Math.Sqrt(GX * GX + GY * GY); // Put the Magnitude into the output buffer retDataF_[roi][yy * dW + xx] = (float)G; } } // Write the output buffer to the IImageData // Boundary Crossing data.SetData(retDataF_[roi]); } break; } }