plim.dream...@gmail.com wrote:
>> I don't think this is the right approach to the problem.
>> What I would do is to get a regularly gridded array
>> for rho first (for instance with trigrid, but there may
>> be other possibilities).
>> Once you have that, it is easy to produce an input array
>> suitable for fit_ellipse (just set all points higher (or lower)
>> than a threshold to 0, and the others to 1).
>>
>> Try something like:
>>
>> TRIANGULATE, x, y, Triangles
>> Result = TRIGRID( x,y,rho, Triangles,[dx,dy],[minx,miny,maxx,maxy]] )
>>
>> where dx and dy is the spacing of the regular grid and minx etc. are
>> the boundaries.
>>
>> Cheers,
>> Paolo>
>
> Hi Paolo,
> I understand that it would be simpler to use a regular gridded array
> but that is changing the whole situation.
> Part of the study I am doing is based on the fact that it isn't a
> regular gridded array with defined spacings dx and dy.
Exactly, so I was suggesting you *transform* your irregularly gridded
data into a regular grid (which is probably what contour is doing
behind
the curtains anyway, only is a bit harder to know and control what
contour is doing)!
Try this code:
np=1000
;creates irregular grid
x=randomu(seed,np)*4-2
y=randomu(seed,np)*4-2
;creates some mock data
a=2
b=3
z=1-sqrt((x/a)^2+(y/b)^2)
z=z+randomn(seed,np)*z*0.1
;this is the data the way contour sees it
contour,z,x,y,/irregular,/iso,levels=findgen(11)/10.*1.15
oplot,x,y,psym=6
;put the data into a regular grid
TRIANGULATE, X, Y, Triangles
Result = TRIGRID( X, Y, Z, Triangles,[0.01,0.01],[-3.,-3,3,3] )
;show regularly gridded data
loadct,5
tvscl,result
;fit ellipse to points above 0.5
ind=where(result GT 0.5)
ell=result*0
ell[ind]=1
data=fit_ellipse(ind,xsize=602,ysize=602)
;show data & best-fit ellipse
tvscl,ell
plots,data[0,*],data[1,*],color=128,/device,thick=2
I think this pretty much does what you want, right?
Paolo
> It seems we are straying from the problem which would be to fit an
> ellipse to a contour and obtain its parameters given the x and y
> positions of the contour. I'm getting amazed at how hard it is to fit
> an ellipse to it!
> I certainly don't understand why there isn't a fit_ellipse program
> that works with the x,y array of the contour vertices instead of the
> pixel indices of the image of a contour (I wish I knew how to make one
> myself).
> B
|