Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CSharpFits:写入FITS文件会导致错误的图像_C#_Fits - Fatal编程技术网

C# CSharpFits:写入FITS文件会导致错误的图像

C# CSharpFits:写入FITS文件会导致错误的图像,c#,fits,C#,Fits,我目前正在进行一个C#项目,以减少echelle光谱,这基本上是FITS格式的2D 16位图像。现在,最终的结果应该是另一个FITS文件,但是是一维的 对于这个任务,我使用CSharpFits库(),一个来自Java实现()的端口,所有文档都位于该端口 我还在这个图书馆的学习阶段。到目前为止,我成功地读取了FITS文件,将其转换为ints数组并处理数据。但是试图写一个FITS文件给了我一个特别的问题,我无法解决这个问题。下面的代码作为一个玩具示例,生成如图所示的结果 private void S

我目前正在进行一个C#项目,以减少echelle光谱,这基本上是FITS格式的2D 16位图像。现在,最终的结果应该是另一个FITS文件,但是是一维的

对于这个任务,我使用CSharpFits库(),一个来自Java实现()的端口,所有文档都位于该端口

我还在这个图书馆的学习阶段。到目前为止,我成功地读取了FITS文件,将其转换为
int
s数组并处理数据。但是试图写一个FITS文件给了我一个特别的问题,我无法解决这个问题。下面的代码作为一个玩具示例,生成如图所示的结果

private void SaveFits()
{
    int[][] array = new int[10][];
    int delta = 65536 / 100;
    for (int i = 0; i < array.Length; i++)
    {
        array[i] = new int[10];
        for (int j = 0; j < array[i].Length; j++)
        {
            array[i][j] = (i + 1) * (j + 1) * delta;
         }
    }
    nom.tam.fits.Fits fits = new nom.tam.fits.Fits();
    nom.tam.fits.BasicHDU hdu = nom.tam.fits.Fits.MakeHDU(array);
    hdu.AddValue("BITPIX", 16, null);  // set bit depth of 16 bit
    hdu.AddValue("NAXIS", 2, null);    // 2D-image
    fits.AddHDU(hdu);                  // Debugging here shows correct HDU-data, i.e. gradient from top left to bottom right
    nom.tam.util.BufferedFile file = new nom.tam.util.BufferedFile(@"D:\test.fits", System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
    fits.Write(file);  
    file.Flush();
    file.Close();
}
然而,在最终图像中(在PixInsight中查看,但任何其他可以显示FITS图像的程序都显示相同),每隔一列仅为值为0的像素,每隔一行重复第一行

到目前为止,我尝试将HDU实际创建为
ImageHDU
,但没有效果。 我还检查了一个正确读取的FITS文件的HDU头字段,并尝试在我的文件中手动设置它们(使用
HDU.AddValue
),但到目前为止没有任何效果。 在这里()可以找到几个使用CSharpFITS编写FITS文件的示例,但是除了我所做的以外,没有其他方法可以使用


非常感谢您的建议。谢谢大家!

根据iGuanauts的评论,将
int
数组更改为
short
数组会得到预期的结果。

我不熟悉这个库,所以我不能肯定地说:您可能会认为,如果显式地将BITPIX头设置为16,可能会将数据转换为正确的类型,但不一定。更有可能的是,如果它的工作原理与pyfits类似,它将根据数据数组的数据类型自动设置BITPIX头。不要使用
int
尝试对数组使用
short
类型,以明确它是16位数据。读取数组似乎遵循相同的“一般原理”,即尽可能隐藏细节。因此,与其设置“结构化”关键字,如
NAXIS
BITPIX
,不如向其传递一个数组,它将根据数组结构/数据类型将这些关键字设置为适当的值。
655   1310  1965  2620  3275  3930  4585  5240  5895  6550
1310  2620  3930  5240  6550  7860  9170 10480 11790 13100
1965  3930  5895  7860  9825 11790 13755 15720 17685 19650
2620  5240  7860 10480 13100 15720 18340 20960 23580 26200
3275  6550  9825 13100 16375 19650 22925 26200 29475 32750
3930  7860 11790 15720 19650 23580 27510 31440 35370 39300
4585  9170 13755 18340 22925 27510 32095 36680 41265 45850
5240 10480 15720 20960 26200 31440 36680 41920 47160 52400
5895 11790 17685 23580 29475 35370 41265 47160 53055 58950
6550 13100 19650 26200 32750 39300 45850 52400 58950 65500