comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: pixel coordinates of a line
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: pixel coordinates of a line [message #25526] Fri, 29 June 2001 01:45 Go to next message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Thanks to everybody.

Tom's method of course would work,
but I don't like to do such things in IDL 'by hand'.
Even in my case now, speed is not a matter.

Alex method with the polygon was really interesting.
Even I am not sure about the clipping here.
But I ended up using the z buffer method.

The interpolate routine is also a good suggestion,
but also doesn't consider the clipping.

Anyway,
some useful tips for further problems,
thanks again,
:-) marc
Re: pixel coordinates of a line [message #25537 is a reply to message #25526] Thu, 28 June 2001 08:10 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
david@dfanning.com (David Fanning) writes:
>
> Here is an article that describes how to do this
> for another purpose, using the INTERPOLATE function:
>
> http://www.dfanning.com/tips/image_profile.html

I use the INTERPOLATE method quite a bit. It has the advantage that
you get the benefit of immediately nearby points, and you get a smooth
curve with as much resolution as you desire.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: pixel coordinates of a line [message #25539 is a reply to message #25537] Thu, 28 June 2001 07:42 Go to previous messageGo to next message
david[2] is currently offline  david[2]
Messages: 100
Registered: June 2001
Senior Member
Marc Schellens writes:

> I want to extract pixels along a line.
> I know start and endpoint (ie. I draw the line in top of the
> image).
> How to get the pixel values? Do I have to do it 'by hand'?

Here is an article that describes how to do this
for another purpose, using the INTERPOLATE function:

http://www.dfanning.com/tips/image_profile.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: pixel coordinates of a line [message #25543 is a reply to message #25539] Thu, 28 June 2001 06:33 Go to previous messageGo to next message
tam is currently offline  tam
Messages: 48
Registered: February 2000
Member
Marc Schellens wrote:
>
> Oh, I forgot:
> I have the start and endpoint, but they might need to be clipped
> to the images boders...
>
>> I want to extract pixels along a line.
>> I know start and endpoint (ie. I draw the line in top of the
>> image).
>> How to get the pixel values? Do I have to do it 'by hand'?
>>
>> thanks,
>> marc


Working in pixel coordinates you have the endpoints (sx,sy,ex,ey) and the clipping
rectangle (x0,y0, x1, y1), so you should trivially be able to get the equation
of the line

y = m x + b [ m= (ey-sy)/(ex-sx), b = sy - m sx ]


Turn this into IDL...

x = lindgen(x1-x0) + x0
y = floor (m * x + b + 0.5) [add 0.5 to get appropriate rounding]
w = where (y ge y0 and y le y1)
if (w[0] ne -1) then begin
x = x(w)
y = y(w)
endif else begin
.... line is outside clipping rectangle
endelse

Here I'm assuming integral values for x0,x1, y0,y1 but not necessarily the
end points.

There are probably subtleties I've missed but this seems like a reasonable
start. Whether it will exactly match the pixels that IDL will draw on
is hard to say... Guess we'd need to know exactly how IDL draws a line.

Tom McGlynn
NASA/GSFC
tam@lheapop.gsfc.nasa.gov
[Mailed and posted]
Re: pixel coordinates of a line [message #25544 is a reply to message #25543] Thu, 28 June 2001 05:43 Go to previous messageGo to next message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
Marc Schellens wrote:

> I want to extract pixels along a line.
> I know start and endpoint (ie. I draw the line in top of the
> image).
> How to get the pixel values? Do I have to do it 'by hand'?

Good question. I don't know about such a function in IDL, but I think
there should be a routine for that.

What about this:
Your line runs from (x1,y1) to (x2,y2), the image has a size of
dimx*dimy. Let's create a thin, one pixel wide polygon along this line:
index = polyfillv( [x1,x2,x2+1,x1+1], [y1,y2,y2,y1], dimx, dimy )
(This assumes that |x2-x1| lt |y2-y1|).
Your pixel values are image[index] then. Well, nearly.

Another method would be drawing a real line via PLOTS (preferably in the
Z buffer), use TVRD() to get this screen part, use WHERE() to get the
indices of this line, and again image[index] is the information you
seek.

But let's wait a little for other responses, I'm pretty sure J.D. will
come up with another idea involving HISTOGRAM().

Alex
--
Alex Schuster Wonko@planet-interkom.de
alex@pet.mpin-koeln.mpg.de
Re: pixel coordinates of a line [message #25546 is a reply to message #25544] Wed, 27 June 2001 23:35 Go to previous messageGo to next message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Oh, I forgot:
I have the start and endpoint, but they might need to be clipped
to the images boders...

> I want to extract pixels along a line.
> I know start and endpoint (ie. I draw the line in top of the
> image).
> How to get the pixel values? Do I have to do it 'by hand'?
>
> thanks,
> marc
Re: pixel coordinates of a line [message #25619 is a reply to message #25544] Fri, 29 June 2001 06:53 Go to previous message
david[2] is currently offline  david[2]
Messages: 100
Registered: June 2001
Senior Member
Alex Schuster writes:

> Another method would be drawing a real line via PLOTS (preferably in the
> Z buffer), use TVRD() to get this screen part, use WHERE() to get the
> indices of this line, and again image[index] is the information you
> seek.

Oddly, I've had occasion to use this method in the past
week or so and I want to mention one little caveat.
I was trying to quantitate the length of a "contact"
between two adjoining "blobs". The "contact" shows
up (more or less) as a line on an image.

But since I wanted to measure the length of this
line, I needed the pixels in order, from one end
to the other. WHERE doesn't give you this. Nor
does the very useful routine THIN, which has the
wonderful property of identifying the endpoints
of the line for you. (Nor does SEARCH2D return
ordered pixels, which was another non-productive
thought I had.)

So, if you want a line segment, you will have
to write a little routine to sort the pixels
out for yourself. My routine starts at one of
the endpoints and finds the next closest pixel,
etc. It may not be the fastest algorithm, but
it worked well for me.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: pixel coordinates of a line [message #25621 is a reply to message #25526] Fri, 29 June 2001 06:22 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Marc Schellens <m_schellens@hotmail.com> writes:

> The interpolate routine is also a good suggestion,
> but also doesn't consider the clipping.

INTERPOLATE does consider clipping if you use the MISSING keyword.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: volume slicing
Next Topic: Re: Intersecting geometric shapes

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:52:23 PDT 2025

Total time taken to generate the page: 0.00861 seconds