[Serializable]
class SerializableNifti
{
private ushort[] _data;
public ushort[] Data => _data;
public int[] Dimensions => _dimensions;
private int[] _dimensions;
public SerializableNifti(ushort[] data, int[] dimensions)
{
_data = data;
_dimensions = dimensions;
}
}
namespace NiftiNET
{
class Program
{
public static void JsonSerialize<T>(T c, string path)
{
string jsonString = JsonSerializer.Serialize(c);
if (File.Exists(path))
File.Delete(path);
File.WriteAllText(path, jsonString);
}
public static void SerializeNow<T>(T c, string path) {
if (File.Exists(path))
File.Delete(path);
Stream s = File.Create(path);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, c);
s.Close();
}
public static T DeSerializeNow<T>(string path) {
Stream s = File.OpenRead(path);
BinaryFormatter b = new BinaryFormatter();
var c = (T) b.Deserialize(s);
s.Close();
return c;
}
static void Main(string[] args)
{
string inPath = @"C:\Users\User\Desktop";
if (args.Length > 0)
inPath = args[0];
else
{
Console.WriteLine("Please give path to nii file");
return;
}
Console.WriteLine($"Reading... From {inPath}");
Nifti.NET.Nifti nifti = null;
if (!inPath.EndsWith("ole"))
nifti = NiftiFile.Read(inPath);
Console.WriteLine($"Completed Nifti generation from {inPath}");
var outPath = string.Empty;
if (args.Length >= 2)
outPath = args[1];
var filetype = inPath.Split(".")
.Skip(1)
.Where(s => !int.TryParse(s, out _))
.Aggregate((acc, s) => $"{acc}.{s}");
var filename = inPath.Split("\\/".ToCharArray()).Last().Replace("." + filetype, "");
var jsonPath = $"{outPath}{filename}.json";
if (outPath.EndsWith("json", StringComparison.InvariantCultureIgnoreCase))
jsonPath = outPath;
I try to implement again the old C# .nii(nifti) file source.
But something strange~
string inPath = @"C:\Users\User\Desktop";
if (args.Length > 0)
inPath = args[0];
else
{
Console.WriteLine("Please give path to nii file");
return;
}
For this implement,
string inPath = "C:\Users\User\Desktop";
was default. But after running my code,
surely good .nii (nifti) file exist but...
no matter how I've tried to correct to others..
Just directly go for
else
{
Console.WriteLine("Please give path to nii file");
return;
}
like manually CMD .exe running below output.
C:\Users\User\source\test\NevrolensNiftiTool\bin\x64\Debug\net5.0>NevrolensNiftiTool.exe
Please give path to nii file
C:\Users\User\source\test\NevrolensNiftiTool\bin\x64\Debug\net5.0>NevrolensNiftiTool.exe
Please give path to nii file
What's the problem?
What I have tried:
1. I've tried to change
string inPath = "C:\Users\User\Desktop";
to
var inPath = "C:\Users\User\Desktop";
or
var inPath = @"\\C:\Users\User\Desktop";
string inPath = @"\\C:\Users\User\Desktop";
string inPath = @"\\C:\Users\User\Desktop\xxx.nii";
string inPath = "C:\Users\User\Desktop\xxx.nii";
var inPath = "C:\Users\User\Desktop\xxx.nii";
Verbatim strings~
But failed and same message "Please give path to nii file"