我有两个要与C#程序结合的WFC3拟合图像。当我尝试合并多张图像时,我认为我从x / y坐标获取的值(根据Right Ascension / Declination计算)不正确。我期望最终图像的宽度与两个图像的合并宽度相同,但结果却是相同的宽度和高度的两倍。我知道最终图像应该大约是单个图像宽度的两倍,因为我在photoshop中手动组合了图像,并且最终图像的宽度大约是两个原始图像中任何一个的两倍。
注意:当我说“图像”时,它们适合图像,因此它们只是文件中的一堆单个值,因此要合并它们,我创建了一个新文件并初始化正确数量的单个值(宽度*高度) )设为零,然后从我要合并的图像中填充值。它们不是jpg,tif或png。
我正在使用以下公式将世界坐标系更改为笛卡尔坐标: 公式是(因为距离对于所有事物都是相同的): x = cos(十进制)* cos(ra) y = cos(dec)* sin(ra)
我从fits文件的标题中得到正确的提升和偏斜。
对于最终图像尺寸,我计算x1和x2之间的距离,并创建一个新图像,该图像为1/2图像1宽度+距离+ 1/2图像2宽度。对于最终高度,我对y和图像高度进行了类似的计算。
图像也确实具有旋转分量,但是我忽略了这两个图像共享相同的旋转。这可能是我问题的一部分。
public const double PixelsPerArcSecond = .039; // per WFC3 spec from Nasa
public static ImageDataModel Combine(List<ImageDataModel> inputImages)
{
// Right ascension is CRVAL1
// Declination is CRVAL2
// formula is (since distance is the same for everything):
// x = cos(dec) * cos(ra)
// y = cos(dec) * sin(ra)
ImageDataModel returnImage = new ImageDataModel();
ImageDataModel bm = inputImages[0];
double x1, y1, x2, y2;
x1 = Math.Cos(bm.CRVAL2) * Math.Cos(bm.CRVAL1);
y1 = Math.Cos(bm.CRVAL2) * Math.Sin(bm.CRVAL1);
int mult = 4; // todo: set this based off of the bitpix of the incoming images.
for (int i = 1; i < inputImages.Count; i++)
{
ImageDataModel cm = inputImages[i];
x2 = Math.Cos(cm.CRVAL2) * Math.Cos(cm.CRVAL1);
y2 = Math.Cos(cm.CRVAL2) * Math.Sin(cm.CRVAL1);
double dx = x1 - x2;
double dy = y1 - y2;
int distX = (int)((dx * 3600) / PixelsPerArcSecond);
int distY = (int)((dy * 3600) / PixelsPerArcSecond);
// This is what I expect to be wider than tall, but the converse is true.
int w = Math.Abs(distX) + (bm.ImageWidth / 2) + (cm.ImageWidth / 2);
int h = Math.Abs(distY) + (bm.ImageHeight / 2) + (cm.ImageHeight / 2);
// This is where the two images are combined into the final image.
ImageDataModel imd = CombineTwoImages(bm, cm, i, w, h, mult);
bm = imd;
}
return returnImage;
}
我期待的图像看起来像这样:
http://wierdling.net/stack-overflow-images/ManuallyCombined.png
但是得到这个:
http://wierdling.net/stack-overflow-images/CombinedTest.png
第一张图片的统计数据为:宽度= 4139,高度= 4535,RA = 350.1584456860353(CRVAL1),DEC = 61.16155335032816(CRVAL2),ORIENTAT = -125
第二张图片的统计信息是:宽度= 4139,高度= 4535,RA = 350.1159150008405(CRVAL1),DEC = 61.19543100394401(CRVAL2),ORIENTAT = -125
最终的预期宽度接近7733,高度接近4773。
最终的实际宽度为4284,高度为7662。
有人知道我在做什么错吗?
可以从https://bitbucket.org/wierdling/fitscombiner/src/master/
下载该程序的完整源代码。当前仅适用于WFC3数据,该程序正在进行中。
答案 0 :(得分:0)
我认为您的图片程序已经可以旋转了,您也应该这样做。
如果将您计算的坐标旋转125度,然后计算坐标x1与左侧的距离,对于x2和y坐标,则得到的宽度为6725,高度为6166。
并不完美,但我认为它朝着正确的方向发展。
希望有帮助。
public static ImageDataModel Combine(List<ImageDataModel> inputImages)
{
// Right ascension is CRVAL1
// Declination is CRVAL2
// formula is (since distance is the same for everything):
// x = cos(dec) * cos(ra)
// y = cos(dec) * sin(ra)
ImageDataModel returnImage = new ImageDataModel();
ImageDataModel bm = inputImages[0];
double x1, y1, x2, y2;
x1 = Math.Cos(bm.CRVAL2) * Math.Cos(bm.CRVAL1);
y1 = Math.Cos(bm.CRVAL2) * Math.Sin(bm.CRVAL1);
var values = Rotate(0 - bm.Orientation, x1, y1);
x1 = values.x;
y1 = values.y;
int mult = 4; // todo: set this based off of the bitpix of the incoming images.
for (int i = 1; i < inputImages.Count; i++)
{
ImageDataModel cm = inputImages[i];
x2 = Math.Cos(cm.CRVAL2) * Math.Cos(cm.CRVAL1);
y2 = Math.Cos(cm.CRVAL2) * Math.Sin(cm.CRVAL1);
var values2 = Rotate(0 - bm.Orientation, x2, y2);
x2 = values2.x;
y2 = values2.y;
double dx = x1 - x2;
double dy = y1 - y2;
int distX = (int)((dx * 3600) / PixelsPerArcSecond);
int distY = (int)((dy * 3600) / PixelsPerArcSecond);
double width = (1.0 + x1) * (bm.ImageWidth / 2) + (1.0 - x2) * (cm.ImageWidth / 2) + Math.Abs(distX);
double height = (1.0 + y1) * (bm.ImageHeight / 2) + (1.0 - y2) * (cm.ImageHeight / 2) + Math.Abs(distY);
// This is what I expect to be wider than tall, but the converse is true.
int w = Math.Abs(distX) + (bm.ImageWidth / 2) + (cm.ImageWidth / 2);
int h = Math.Abs(distY) + (bm.ImageHeight / 2) + (cm.ImageHeight / 2);
// This is where the two images are combined into the final image.
ImageDataModel imd = CombineTwoImages(bm, cm, i, w, h, mult);
bm = imd;
}
return returnImage;
}
private static (double x, double y) Rotate(int angle, double x, double y)
{
double rad = Math.PI * angle / 180.0;
return (x * Math.Cos(rad) - y * Math.Sin(rad), x * Math.Sin(rad) + y * Math.Cos(rad));
}