public void Write() { // Read our minimal Nifti file var nifti = new NiftiFloat32(); nifti.ReadNifti(_minimalNiftiPath); // Write the minimal Nifti file. nifti.WriteNifti(_outfile); // Check that we've written something. Assert.IsTrue(File.Exists(_outfile), "Nifti file does not exist"); // Read our nifti file back in. var nifti2 = new NiftiFloat32(); nifti2.ReadNifti(_outfile); // Delete the old file. File.Delete(_outfile); Assert.IsFalse(File.Exists(_outfile), "Nifti file could not be deleted."); // Check that the dimensions match the expected Nifti file. nifti.GetDimensions(SliceType.Axial, out var width, out var height, out var nSlices); Assert.AreEqual(height, 64); Assert.AreEqual(width, 64); Assert.AreEqual(nSlices, 10); }
static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); if (args.Length < 2) { System.Console.WriteLine("Open-Vistarsier requires at least 2 NiftiFiles as input."); System.Console.WriteLine("Usage: vt [prior nifti] [current nifti] [output-prefix](optional)"); return; } var prior = args[0]; var current = args[1]; var outputPrefix = ""; if (args.Length > 2) { outputPrefix = args[2]; } if (!Path.IsPathRooted(prior)) { prior = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, prior)); } if (!Path.IsPathRooted(current)) { current = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, current)); } // Create an MS pipeline. var pipeline = new MSPipeline( current, prior, current, true, true, true, new string[] { outputPrefix + "vt-increase.nii", outputPrefix + "vt-decrease.nii" }, outputPrefix + "vt-prior.nii"); var metrics = pipeline.Process(); // Hack(ish), there's all sorts of to-ing and fro-ing with BMP encoding going on under the hood. // If we don't do this step the nifti will blue itself. var nii = new NiftiFloat32().ReadNifti(outputPrefix + "vt-increase.nii"); for (int i = 0; i < nii.Voxels.Length; ++i) { nii.Voxels[i] = ToBgr((int)nii.Voxels[i]); } nii.WriteNifti(outputPrefix + "vt-increase.nii"); System.Console.WriteLine("Complete:"); System.Console.WriteLine($"Initial brain match : {metrics.BrainMatch}"); System.Console.WriteLine($"Union brain match : {metrics.CorrectedBrainMatch}"); System.Console.WriteLine($"Successful : {metrics.Passed}"); System.Console.WriteLine($"Time to complete : {sw.Elapsed}"); }
public void WriteRgb() { if (File.Exists(_rgbfile)) { File.Delete(_rgbfile); } var nifti = new NiftiFloat32(); nifti.ReadNifti(_minimalNiftiPath); // Read pixdim from sample file nifti.ReadNiftiHeader(_minimalNiftiHdrPath); // set dimensions for new file nifti.ConvertHeaderToRgb(); nifti.Header.cal_min = 0; nifti.Header.cal_max = uint.MaxValue * (3 / 4); // write voxels //var voxelsSize = nifti.Header.dim[1] * nifti.Header.dim[2] * nifti.Header.dim[3]; //var bytepix = nifti.Header.bitpix / 8; //nifti.VoxelsBytes = new byte[voxelsSize * bytepix]; const int r = 255; const int g = 51; const int b = 204; for (var x = 0; x < nifti.Header.dim[1]; x++) { for (var y = 0; y < nifti.Header.dim[2]; y++) { for (var z = 0; z < nifti.Header.dim[3]; z++) { nifti.SetPixelRgb(x, y, z, SliceType.Axial, r, g, b); } } } if (File.Exists(_rgbfile)) { File.Delete(_rgbfile); } nifti.WriteNifti(_rgbfile); Assert.IsTrue(File.Exists(_rgbfile)); //TODO: More meaningful asserts File.Delete(_rgbfile); }
public void WriteRgba() // TODO: This is currently unsupported (technically RGBA doesn't seem to be part // of the NifTI 1.1 format, so it will throw an error on the datatype { var nifti = new NiftiFloat32(); nifti.ReadNifti(_minimalNiftiPath); nifti.ConvertHeaderToRgba(); // Read pixdim from sample file // set dimensions for new file nifti.Header.dim[1] = 100; nifti.Header.dim[2] = 80; nifti.Header.dim[3] = 50; nifti.Header.cal_min = 0; nifti.Header.cal_max = uint.MaxValue; // write voxels var voxelsSize = nifti.Header.dim[1] * nifti.Header.dim[2] * nifti.Header.dim[3]; nifti.Voxels = new float[voxelsSize]; for (var i = 0; i < voxelsSize; i++) { nifti.Voxels[i] = 255; } if (File.Exists(_rgbafile)) { File.Delete(_rgbafile); } nifti.WriteNifti(_rgbafile); Assert.IsTrue(File.Exists(_rgbafile)); //TODO more meaningful asserts. File.Delete(_rgbafile); }