Pixel positions passing trough a curve [message #93733] |
Tue, 11 October 2016 05:36  |
Miguel
Messages: 18 Registered: April 2015
|
Junior Member |
|
|
Hi everyone,
I am trying to construct a program that produces a position-velocity diagram whose shape can be fitted by a certain equation (and plotted).
I wanted to know if it was possible to obtain somehow the pixels position trough a path I choose. For example, I draw a line (in ds9) from (0,0) to (10,0) and I want to know which pixels represent the line. In this case, the program would give (0,0), (1,0), (2,0),...,(10,0). The thing is that I want to draw an arbitrary path (not necesarily in ds9) and get automatically the points.
For the moment, I put a circle, in ds9, in each pixel of the path and obtain the list of pixel positions and saving the region in xy format. I use this catalogue as an input of my program.
If there is a way to do it automatically (or some ideas) or an already existing program, I would like to know more.
Thank you,
Miguel
|
|
|
Re: Pixel positions passing trough a curve [message #93734 is a reply to message #93733] |
Tue, 11 October 2016 06:05   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Tuesday, October 11, 2016 at 2:36:44 PM UTC+2, miguelfigue...@gmail.com wrote:
> Hi everyone,
>
> I am trying to construct a program that produces a position-velocity diagram whose shape can be fitted by a certain equation (and plotted).
>
> I wanted to know if it was possible to obtain somehow the pixels position trough a path I choose. For example, I draw a line (in ds9) from (0,0) to (10,0) and I want to know which pixels represent the line. In this case, the program would give (0,0), (1,0), (2,0),...,(10,0). The thing is that I want to draw an arbitrary path (not necesarily in ds9) and get automatically the points.
>
> For the moment, I put a circle, in ds9, in each pixel of the path and obtain the list of pixel positions and saving the region in xy format. I use this catalogue as an input of my program.
> If there is a way to do it automatically (or some ideas) or an already existing program, I would like to know more.
>
> Thank you,
> Miguel
A counter-question: if going from (0,0) to (10,10), would you want:
(a) (0,0), (1,1), (2,2),...,(9,9),(10,10)
(b) (0,0), (1*cos(45),1*sin(45)), (2*cos(45),2*sin(45)), ...
That said, as you can see, it's all about trigonometry and getting the details right. I've done this quite a few time using approach (b). If you wish, I can clean this up a bit and send it to your private email. Be aware that I've added a small degree of complexity by averaging along the perpendicular of x-pixel width (smoothens out the signal a bit).
cheers, Helder
|
|
|
Re: Pixel positions passing trough a curve [message #93735 is a reply to message #93734] |
Tue, 11 October 2016 07:01   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Tuesday, October 11, 2016 at 3:06:01 PM UTC+2, Helder wrote:
> On Tuesday, October 11, 2016 at 2:36:44 PM UTC+2, miguelfigue...@gmail.com wrote:
>> Hi everyone,
>>
>> I am trying to construct a program that produces a position-velocity diagram whose shape can be fitted by a certain equation (and plotted).
>>
>> I wanted to know if it was possible to obtain somehow the pixels position trough a path I choose. For example, I draw a line (in ds9) from (0,0) to (10,0) and I want to know which pixels represent the line. In this case, the program would give (0,0), (1,0), (2,0),...,(10,0). The thing is that I want to draw an arbitrary path (not necesarily in ds9) and get automatically the points.
>>
>> For the moment, I put a circle, in ds9, in each pixel of the path and obtain the list of pixel positions and saving the region in xy format. I use this catalogue as an input of my program.
>> If there is a way to do it automatically (or some ideas) or an already existing program, I would like to know more.
>>
>> Thank you,
>> Miguel
>
> A counter-question: if going from (0,0) to (10,10), would you want:
> (a) (0,0), (1,1), (2,2),...,(9,9),(10,10)
> (b) (0,0), (1*cos(45),1*sin(45)), (2*cos(45),2*sin(45)), ...
>
> That said, as you can see, it's all about trigonometry and getting the details right. I've done this quite a few time using approach (b). If you wish, I can clean this up a bit and send it to your private email. Be aware that I've added a small degree of complexity by averaging along the perpendicular of x-pixel width (smoothens out the signal a bit).
>
> cheers, Helder
Ok, so I just put all the code online. Notice that I follow solution (b).
You can find the code in the post:
http://idl.marchetto.de/getting-line-profiles/
Let me know if you can recommend any improvements of any type or if you find any bugs. I haven't really made any checks to make sure the point are inside or are not too close to one another and so on...
Cheers,
Helder
PS: if you want to use a circle, you can obviously calculate the points as [2,n] array, however it is quite important to get the n value right, otherwise things don't work so well...
|
|
|
|
Re: Pixel positions passing trough a curve [message #93737 is a reply to message #93736] |
Tue, 11 October 2016 07:43   |
Markus Schmassmann
Messages: 129 Registered: April 2016
|
Senior Member |
|
|
On 10/11/2016 04:30 PM, miguelfigueirasebastiao@gmail.com wrote:
> On 10/11/2016 02:36 PM, miguelfigueirasebastiao@gmail.com wrote:
>> I am trying to construct a program that produces a
>> position-velocity diagram whose shape can be fitted by a certain
>> equation (and plotted).
>>
>> I wanted to know if it was possible to obtain somehow the pixels
>> position trough a path I choose. For example, I draw a line (in
>> ds9) from (0,0) to (10,0) and I want to know which pixels represent
>> the line. In this case, the program would give (0,0), (1,0),
>> (2,0),...,(10,0). The thing is that I want to draw an arbitrary
>> path (not necesarily in ds9) and get automatically the points.
>>
>> For the moment, I put a circle, in ds9, in each pixel of the path
>> and obtain the list of pixel positions and saving the region in xy
>> format.
>> I use this catalogue as an input of my program. If there is
>> a way to do it automatically (or some ideas) or an already existing
>> program, I would like to know more.
> Thank you for your answer but maybe it is not completely what I want
> (except if I use very simple path)
>
> In your program, I have to give the coordinates of the beginning and
> end of the segments but if my path is complicated (ellipsis or
> multi-segment path) it seems to be better to make directly the list
> on ds9.
>
> In other words, is it possible to draw a curved line and obtain the
> pixels passing through this curve ?
brute force approach:
- export the curve into a graphic (pixels not vector) without axes
(either plot a line or use sufficient dots to cover the line)
- import into an IDL array
IDL> w=where(array ne 0)
IDL> ari=array_indices(array,w)
|
|
|
Re: Pixel positions passing trough a curve [message #93738 is a reply to message #93736] |
Tue, 11 October 2016 07:55   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Tuesday, October 11, 2016 at 4:30:40 PM UTC+2, miguelfigue...@gmail.com wrote:
> Thank you for your answer but maybe it is not completely what I want (except if I use very simple path)
>
> In your program, I have to give the coordinates of the beginning and end of the segments but if my path is complicated (ellipsis or multi-segment path) it seems to be better to make directly the list on ds9.
>
> In other words, is it possible to draw a curved line and obtain the pixels passing through this curve ?
>
> Miguel
If I understand correctly, your problem can be subdivided in three parts:
(1) draw a path on an image
(2) extract from the drawn path cardinal points defining subsegments
(3) calculate the profile along the segments
I think that the code mentioned solves point (3). However, you need to solve the first two, so:
(1) Try xroi (http://www.harrisgeospatial.com/docs/XROI.html). You may eventually modify or rewrite the code to satisfy your needs.
(2) this is a bit tricky because you want enough points, but not too many. I would completely skip this in a first attempt and then check if the result is what you expect. If not, you might have to take care to reduce the number of curve points so that the arc is always 1 pixel.
There is another thing to mention. If you define masks or areas, you may get the boundary of the area using David's Find_Boundary function (http://www.idlcoyote.com/ip_tips/boundary.html).
I hope this helps.
Cheers,
Helder
|
|
|
|