
我正在编写一个程序来计算星系的表面亮度,作为椭圆半径的函数.这首先涉及读取.fits文件,该文件存储在numpy数组中,使得array [x] [y]将返回该(x,y)像素处的表面亮度值.
为了计算表面亮度,我需要能够以一定的最小尺寸将椭圆拟合到星系,并找到该椭圆内的中间表面亮度,然后增加椭圆的大小并找到每个环的表面亮度.将环绕不同尺寸的环形,直到表面亮度下降到与背景噪声的一定比率之下.
问题
给定椭圆的参数包括位置角度,x和y像素的中心坐标以及B / A的比率.
我无法找到任何一种允许我将椭圆拟合成一个数组阵列的方法.请帮忙??
from xml.etree.cElementTree import parseimport numpy as npfrom os import Listdir,getcwdfrom scipy import ndimageimport h5pyimport multiprocessingimport time#from dicttoxml import dicttoxml#from xml.dom.minIDom import parseStringimport sysimport cPickle as picklefrom threading import Threadfrom skimage.measure import momentsdef fitEllipse(data): ''' Returns the length of the long and short axis and the angle measure of the long axis to the horizontal of the best fit ellipsebased on image moments. usage: longAxis,shortAxis,angle = fitEllipse(N_by_M_image_as_array) ''' # source: # KIEran F. Mulchrone,Kingshuk Roy Choudhury,# Fitting an ellipse to an arbitrary shape: # implications for strain analysis,Journal of # Structural Geology,Volume 26,Issue 1,# January 2004,Pages 143-153,ISSN 0191-8141,# <http://dx.doi.org/10.1016/S0191-8141(03)00093-2.> # Lourena Rocha,Luiz Velho,Paulo Cezar P. Carvalho # Image Moments-Based Structuring and Tracking of # Objects,IMPA-Instituto Nacional de Matematica Pura # e Aplicada. EsTrada Dona Castorina,110,22460 # Rio de Janeiro,RJ,Brasil,# <http://IEeexplore.IEee.org/stamp/stamp.Jsp?tp=&arnumber=1167130> m = moments(data,2) # super fast compated to anything in pure python xc = m[1,0] / m[0,0] yc = m[0,1] / m[0,0] a = (m[2,0]) - (xc**2) b = 2 * ((m[1,0]) - (xc * yc)) c = (m[0,2] / m[0,0]) - (yc**2) theta = .5 * (np.arctan2(b,(a - c))) w = np.sqrt(6 * (a + c - np.sqrt(b**2 + (a-c)**2))) l = np.sqrt(6 * (a + c + np.sqrt(b**2 + (a-c)**2))) return l,w,theta
我只是把它扔在一起,以防它与你想要的类似.如果您需要更多解释,请随时发表评论.我使用的来源(数学)在评论中.
总结以上是内存溢出为你收集整理的python – 从numpy数组中计算Ellipse中的像素全部内容,希望文章能够帮你解决python – 从numpy数组中计算Ellipse中的像素所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)