Python 2.7 创造额外的星星,最有效的方法来摆脱它们?
我已经创建了一个程序来从BW图片中定位恒星,但不幸的是,在长时间曝光后,恒星变得模糊,导致程序在恒星旁边创建了一个重复的恒星(见图)。去除不需要的星星的最好方法是什么 这是我正在使用的当前代码:Python 2.7 创造额外的星星,最有效的方法来摆脱它们?,python-2.7,astronomy,Python 2.7,Astronomy,我已经创建了一个程序来从BW图片中定位恒星,但不幸的是,在长时间曝光后,恒星变得模糊,导致程序在恒星旁边创建了一个重复的恒星(见图)。去除不需要的星星的最好方法是什么 这是我正在使用的当前代码: def starfinder(filename) : f=pyfits.open(filename) image_data=snd.median_filter(f[0].data,3) #gets rid of the hot pixels
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]
图片pic1;//你的形象
常数DWORD cl_星=0x008C0000;
常量DWORD cl_空间=0x00FFFFFF;
常数int涂抹_max=30;//最大拖影大小[像素]
int i,j,x,y,r=3,dx0,dx1,dy0,dy1;
德沃德c;
列表xy;//星形(x,y)
int hisx[涂抹最大值];//星dx距离直方图
int hisy[涂抹最大值];//星间距离直方图
//获取恒星坐标
对于(y=0;yCanvas->Pen->Width=1;
我使用自己的图片类处理图像,因此一些成员是:
xs,ys
是以像素为单位的图像大小
p[y][x].dd
是位于(x,y)
位置的32位整数类型的像素
clear(color)
使用color
调整大小(xs,ys)
将图像调整为新分辨率
bmp
是VCL封装的GDI位图,具有Canvas
访问权限
pf
保存图像的实际像素格式:
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
};
颜色和像素编码如下:
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,
};
我还使用我的动态列表模板,以便:
列表xxx;
与双xxx[]相同;
xxx.添加(5);
在列表末尾添加5
xxx[7]
访问数组元素(安全)
xxx.dat[7]
访问数组元素(不安全但快速的直接访问)
xxx.num
是数组的实际使用大小
xxx.reset()
清除数组并设置xxx.num=0
xxx.分配(100)
为100
项目预先分配空间
此处预览结果:
红点是从绘图图像中检测到的星星,蓝线显示哪些星星被链接/检测为涂抹