创造了额外的星星,摆脱它们的最有效方法是什么? [英] Extra stars created, most efficient way to get rid of them?

查看:64
本文介绍了创造了额外的星星,摆脱它们的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个程序来从 BW 照片中定位星星,但不幸的是,在长时间曝光时,星星变得模糊,导致程序在星星旁边创建了一个重复的星星(见图).去除不需要的星星的最佳方法是什么?

I have created a program to locate stars from a BW picture, but unfortunately on long exposure times the star becomes smeared causing the program to create a duplicate star next to the star (see image). What is the best way to remove the unwanted star?

这是我当前使用的代码:

This is the current code i am using:

def starfinder(filename) :

f=pyfits.open(filename)
image_data=snd.median_filter(f[0].data,3)                              #gets rid of the hot pixels
thld = image_data.mean() + 2*image_data.std()                          #limits the pixel value of bright stars
labels, number = snd.label(image_data > thld, np.ones((3,3)))          #turns any values over the threshold into a 3x3 array of ones
centres = snd.center_of_mass(image_data, labels, range(1,number+1))    #center of mass finds the centre of the 3x3 array

star_centres = np.around(centres, decimals=0)
y = np.array(star_centres)[:,0]
x = np.array(star_centres)[:,1]
np.savetxt("star_positions.txt",star_centres)

#plt.plot(x,y,"ro")
plt.scatter(x, y, marker='o', c='r', s=5, label='the data')

return len(x)[enter image description here][1]

推荐答案

  1. 定义拖尾偏移

手动或根据星距直方图测量.最常见的偏移是涂抹.

Either manualy, or measure it from histogram of star distances. The most ocurent offset is the smear.

每颗星

检查smear offset 附近是否有smeared star 如果是,则将两者合并为一个.这取决于数据属性.例如,您可以使用平均星位、涂抹开始或结束时的星位等..

check if there is not a smeared star nearby smear offset If yes merge the two into single one. How that depends on the data properties. For example you can use average star position, star position that is in start of thesmear or end, etc ..

这里是如何执行此操作的小型 C++ 示例:

Here small C++ example of how to do this:

picture pic1; // your image
const DWORD cl_star =0x008C0000;
const DWORD cl_space=0x00FFFFFF;
const int smear_max=30; // max smear size [pixels]
int i,j,x,y,r=3,dx0,dx1,dy0,dy1;
DWORD c;

List<int> xy;           // star (x,y)
int hisx[smear_max];    // histogram of star dx distances
int hisy[smear_max];    // histogram of star dy distances

// get star coordinates
for (y=0;y<pic1.ys-1;y++)
 for (x=0;x<pic1.xs-1;x++)
  if (pic1.p[y][x].dd==cl_star)
    {
    xy.add(x);
    xy.add(y);
    x++; if (pic1.p[y][x].dd==cl_star) pic1.p[y][x].dd=cl_space;
    y++; if (pic1.p[y][x].dd==cl_star) pic1.p[y][x].dd=cl_space;
    x--; if (pic1.p[y][x].dd==cl_star) pic1.p[y][x].dd=cl_space;
    y--;                               pic1.p[y][x].dd=cl_space;
    }
// compute hisogram of star |dx|,|dy| distance
for (i=0;i<smear_max;i++) hisx[i]=0;
for (i=0;i<smear_max;i++) hisy[i]=0;
for (i=0;i<xy.num;i+=2)
 for (j=i+2;j<xy.num;j+=2)
    {
    x=xy[i+0]-xy[j+0]; if (x<0) x=-x; if (x<smear_max) hisx[x]++;
    y=xy[i+1]-xy[j+1]; if (y<0) y=-y; if (y<smear_max) hisy[y]++;
    }
// find most common ones
for (i=0,j=0;i<smear_max;i++) if (hisx[j]<hisx[i]) j=i; dx0=j-1; dx1=j+1;
for (i=0,j=0;i<smear_max;i++) if (hisy[j]<hisy[i]) j=i; dy0=j-1; dy1=j+1;
// render found stars
pic1.bmp->Canvas->Pen->Color=clBlack;
pic1.bmp->Canvas->Brush->Color=clRed;
for (i=0;i<xy.num;)
    {
    x=xy[i]; i++;
    y=xy[i]; i++;
    pic1.bmp->Canvas->Ellipse(x-r,y-r,x+r,y+r);
    }
// find smeared stars and render join line
pic1.bmp->Canvas->Pen->Color=clBlue;
pic1.bmp->Canvas->Pen->Width=2;
for (i=0;i<xy.num;i+=2)
 for (j=i+2;j<xy.num;j+=2)
    {
    x=xy[i+0]-xy[j+0]; if (x<0) x=-x;
    y=xy[i+1]-xy[j+1]; if (y<0) y=-y;
    if ((x>=dx0)&&(x<=dx1))
     if ((y>=dy0)&&(y<=dy1))
        {
        pic1.bmp->Canvas->MoveTo(xy[i+0],xy[i+1]);
        pic1.bmp->Canvas->LineTo(xy[j+0],xy[j+1]);
        // here you can merge the stars i,j together instead.
        }
    }
pic1.bmp->Canvas->Pen->Width=1;

我使用自己的图片类来处理图像,因此一些成员是:


xs,ys 是以像素为单位的图像大小
p[y][x].dd(x,y) 位置的像素,为 32 位整数类型
clear(color) 使用 color 清除整个图像
resize(xs,ys) 将图像调整为新的分辨率
bmpVCL 封装的 GDI 位图,具有 Canvas 访问权限
pf 保存图像的实际像素格式:


xs,ys is size of image in pixels
p[y][x].dd is pixel at (x,y) position as 32 bit integer type
clear(color) clears entire image with color
resize(xs,ys) resizes image to new resolution
bmp is VCL encapsulated GDI Bitmap with Canvas access
pf holds actual pixel format of the image:

enum _pixel_format_enum
    {
    _pf_none=0, // undefined
    _pf_rgba,   // 32 bit RGBA
    _pf_s,      // 32 bit signed int
    _pf_u,      // 32 bit unsigned int
    _pf_ss,     // 2x16 bit signed int
    _pf_uu,     // 2x16 bit unsigned int
    _pixel_format_enum_end
    };


color 和像素的编码方式如下:


color and pixels are encoded like this:

union color
    {
    DWORD dd; WORD dw[2]; byte db[4];
    int i; short int ii[2];
    color(){}; color(color& a){ *this=a; }; ~color(){}; color* operator = (const color *a) { dd=a->dd; return this; }; /*color* operator = (const color &a) { ...copy... return this; };*/
    };


乐队是:

enum{
    _x=0,   // dw
    _y=1,

    _b=0,   // db
    _g=1,
    _r=2,
    _a=3,

    _v=0,   // db
    _s=1,
    _h=2,
    };

我也使用我的动态列表模板,所以:

I also use mine dynamic list template so:


Listxxx; 等同于 double xxx[];
xxx.add(5);5 添加到列表末尾
xxx[7] 访问数组元素(安全)
xxx.dat[7] 访问数组元素(不安全但快速的直接访问)
xxx.num 是数组实际使用的大小
xxx.reset() 清空数组并设置 xxx.num=0
xxx.allocate(100)100 个项目预分配空间


List<double> xxx; is the same as double xxx[];
xxx.add(5); adds 5 to end of the list
xxx[7] access array element (safe)
xxx.dat[7] access array element (unsafe but fast direct access)
xxx.num is the actual used size of the array
xxx.reset() clears the array and set xxx.num=0
xxx.allocate(100) preallocate space for 100 items

这里预览结果:

红点是从您的绘图图像中检测到的星星,蓝线显示哪些星星被链接/检测为涂污.

Red dots are detected stars from your plot image and blue lines shows which stars are linked/detected as smeared.

这篇关于创造了额外的星星,摆脱它们的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆