/////////////////////////////////////////////////////////////////////// private void CreateCalibratedFile(double [] calibration, double [] errors) { // No Calibration So Make Something up if (calibration == null) { calibration = new double[720]; for (int i = 0; i < 720; i++) { calibration[i] = i * 3.0; } } // Size of data passed in ushort[] cosine = new ushort[calibration.Length]; // Generate Curves (Amplitude 100) for (int pix = 0; pix < calibration.Length; pix++) { // Convert To Angle double angle = Math.PI * ((double)pix - 360) / 180.0; // Compute Points cosine[pix] = (ushort)((double)100 * (Math.Cos(angle) + (double)1)); } // Mkae a region of interest (Single Strip) RegionOfInterest roi = new RegionOfInterest(0, 0, calibration.Length, 1, 1, 1); // Get the file manager var filemgr = LightFieldApplication.FileManager; if (filemgr != null) { RegionOfInterest[] rois = { roi }; string root = (string)LightFieldApplication.Experiment.GetValue(ExperimentSettings.FileNameGenerationDirectory); IImageDataSet calSampleData = filemgr.CreateFile(root + "\\CalibrationSample.Spe", rois, 1, ImageDataFormat.MonochromeUnsigned16); // Put Data to frame 1 IImageData data1 = calSampleData.GetFrame(0, 0); data1.SetData(cosine); // Update The XML for the new document SetCalibrationAndError(calSampleData, calibration, errors); // Close the file filemgr.CloseFile(calSampleData); } }
/////////////////////////////////////////////////////////////////////// // Change some of the values in the underlying IImageDataSet /////////////////////////////////////////////////////////////////////// void ModifyDataExample(IImageDataSet imageData, int roiIdx) { // Demostrate how to access the data and change it var rois = imageData.Regions; // Get the width & the height int h = rois[roiIdx].Height; int w = rois[roiIdx].Width; // Get sub image arrays from the data set IImageData row = imageData.GetRow(roiIdx, 0, h / 2); IImageData col = imageData.GetColumn(roiIdx, 0, w / 2); IImageData pix = imageData.GetPixel(roiIdx, 0, h / 2, w / 2); // Create new arrays to replace data ushort[] rowData = new ushort[w]; ushort[] colData = new ushort[h]; ushort[] pixData = new ushort[1]; // Build up new data with values for (int x = 0; x < w; x++) { rowData[x] = (ushort)(5000 + x); } for (int y = 0; y < h; y++) { colData[y] = (ushort)(10000 + y); } // bright pixel pixData[0] = 65535; // Push back to original buffer row.SetData(rowData); col.SetData(colData); pix.SetData(pixData); }
/////////////////////////////////////////////////////////////////////// // 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; } }
//////////////////////////////////////////////////////////////////////// // The following routine demonstrates how to create files using the // LightField Addin SDK. // // Create 1 File with 2 Frames and 1 Region (TwoFrameOneRoi.Spe) // Create 1 File with 1 Frames and 2 Regions (OneFrameTwoRoi.Spe) //////////////////////////////////////////////////////////////////////// private void GenerateFiles() { // Get the addin file manager var filemgr = LightFieldApplication.FileManager; if (filemgr != null) { /////////////////////////////////////////////////////////////// // Part 1: Two Frames 1 Region /////////////////////////////////////////////////////////////// int[] w1 = { 100 }; int[] h1 = { 200 }; // Pseudo Frame 1 Region 1, Frame 2 Region 1 ushort[] frame1 = new ushort[100 * 200]; ushort[] frame2 = new ushort[100 * 200]; for (int pix = 0; pix < 100 * 200; pix++) { frame1[pix] = (ushort)pix; frame2[pix] = (ushort)(pix * 2); } // Folder Selector var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Please choose folder for resulting SPE file(s)."; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); // Something bad happened we don't want to write the files. if (result != System.Windows.Forms.DialogResult.OK) { return; } // Local variable containing path string path = dialog.SelectedPath; // Create a file with 2 frames and the proper width and height // The file is initially created as empty and the user must load data to it. RegionOfInterest roi = new RegionOfInterest(0, 0, w1[0], h1[0], 1, 1); RegionOfInterest[] rois = { roi }; IImageDataSet TwoFrameOneRoi = filemgr.CreateFile(path + "\\TwoFrameOneRoi.spe", rois, 2, // Frames ImageDataFormat.MonochromeUnsigned16); // Put Data to frame 1 IImageData data1 = TwoFrameOneRoi.GetFrame(0, 0); data1.SetData(frame1); // Put Data to frame 2 IImageData data2 = TwoFrameOneRoi.GetFrame(0, 1); data2.SetData(frame2); // Finally close this file filemgr.CloseFile(TwoFrameOneRoi); /////////////////////////////////////////////////////////////// // Part 2: 1 Frame 2 Regions /////////////////////////////////////////////////////////////// int[] w2 = { 300, 500 }; int[] h2 = { 400, 600 }; // Pseudo Frame 2 Region 1 ushort[] frame1_roi1 = new ushort[300 * 400]; for (int pix = 0; pix < 300 * 400; pix++) { frame1_roi1[pix] = (ushort)pix; } // Pseudo Frame 2 Region 2 ushort[] frame1_roi2 = new ushort[500 * 600]; for (int pix = 0; pix < 500 * 600; pix++) { frame1_roi2[pix] = (ushort)pix; } // Create a file, get the buffer and fill it in for each region // The file is initially created as empty and the user must load data to it. // The regions can not overlap RegionOfInterest r1 = new RegionOfInterest(0, 0, w2[0], h2[0], 1, 1); RegionOfInterest r2 = new RegionOfInterest(w2[0] + 1, h2[0] + 1, w2[1], h2[1], 1, 1); RegionOfInterest[] rois2 = { r1, r2 }; IImageDataSet OneFrameTwoRoi = filemgr.CreateFile(path + "\\OneFrameTwoRoi.spe", rois2, 1, // Frames ImageDataFormat.MonochromeUnsigned16); // Put Data To Region 1 IImageData data2_roi1 = OneFrameTwoRoi.GetFrame(0, 0); data2_roi1.SetData(frame1_roi1); // Data To Region 2 IImageData data2_roi2 = OneFrameTwoRoi.GetFrame(1, 0); data2_roi2.SetData(frame1_roi2); // Finally close this file filemgr.CloseFile(OneFrameTwoRoi); } }