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

Home » Public Forums » archive » contour fill
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
contour fill [message #21378] Fri, 25 August 2000 00:00 Go to next message
so is currently offline  so
Messages: 9
Registered: August 2000
Junior Member
Hi,

I am trying to get IDL to isolate the values contained within a closed
contour of a plotted data array. Basically, I want to perform a
calculation using these values instead of cloouring them in like /fill
does.

Any help would be greatly appreciated!

Cheers, Stephen O'Sullivan

============================================================ ===============
Dr Stephen O'Sullivan | Telephone: +44-113-2335187
Department of Applied Mathematics | Facsimile: +44-113-2429925
University of Leeds | Email : so@amsta.leeds.ac.uk
Leeds LS2 9JT UK | WWW: www.amsta.leeds.ac.uk/applied
============================================================ ===============
Re: contour fill [message #21444 is a reply to message #21378] Sat, 26 August 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> You wondered why a basic threshold wouldn't work. I think his reply
> was that he wanted to select a *particular* contour. When there are
> several peaks in the data then a simple threshold will not work. As I
> pointed out the hardest part in the algorithm I gave is selecting the
> right contour. [And I gave a posible heuristic to decide.]

Oh, I liked your answer well enough. (I always do.)
But I'm leery of the right answer to the wrong
question. I guess that translates to Why?.

How's it going on those other IDL questions I posed? :-)

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: contour fill [message #21445 is a reply to message #21378] Sat, 26 August 2000 00:00 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
davidf@dfanning.com (David Fanning) writes:
> Leaving aside the observation that getting *something*
> to work is not exactly the same as getting the *right*
> thing to work, I'm still concerned that the poor fellow
> is not working on the right thing. :-(
>
> Unless your goal is some kind of pseudo-science, working
> with the representation of the data rather than the data
> itself is rarely a good idea.

He was asking *how?*. You are asking *why?*. Both are fair
questions.

You wondered why a basic threshold wouldn't work. I think his reply
was that he wanted to select a *particular* contour. When there are
several peaks in the data then a simple threshold will not work. As I
pointed out the hardest part in the algorithm I gave is selecting the
right contour. [And I gave a posible heuristic to decide.]

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: contour fill [message #21446 is a reply to message #21378] Sat, 26 August 2000 00:00 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
After some real-world experimentation, it seems that these are the
correct statements:

> c0x = (pxy(0,c0off) - x(0)) / dx + 1 ;; Convert to scan cols & lines
> c0y = (pxy(1,c0off) - y(0)) / dy + 1

Note the "+ 1"'s. I believe there is a goof in the documentation for
the POLYFILLV function which leads to an off-by-one discrepancy. Or
else I don't understand it...

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: contour fill [message #21448 is a reply to message #21378] Sat, 26 August 2000 00:00 Go to previous messageGo to next message
wmc is currently offline  wmc
Messages: 117
Registered: February 1995
Senior Member
Stephen O'Sullivan <so@amsta.leeds.ac.uk> wrote:
> On Fri, 25 Aug 2000, David Fanning wrote:
>> Stephen O'Sullivan (so@amsta.leeds.ac.uk) writes:
>>> I am trying to get IDL to isolate the values contained within a closed
>>> contour of a plotted data array. Basically, I want to perform a
>>> calculation using these values instead of cloouring them in like /fill
>>> does.

> Thanks for your help but the problem that I didn't really make clear is
> that I need all the values contained within the specified closed contour,
> not just those above or below the contour value. In this sense it's a
> geometric thing.

Well.. wen you say *all* the values, you presumably mean te pixels at
a certain resolution, rather tan te infinite number of real points?

If so: wy not contour onto a pixmap, ten read in te pixmap (tvrd) ten

points_i_like=where(pixmap eq cosen_colour)

-W. (posting from a keyboard with a bad "h", you may have noticed...)

--
William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
Re: contour fill [message #21459 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> Wow David you must be trying hard to drum up consulting business :-).

Just the opposite. I have too much to do, and I really
didn't want to get into it. :-)

Thanks for bailing us out.

> I tried it myself, having never had ROI experience before, and got
> something to work in about ten minutes.

Leaving aside the observation that getting *something*
to work is not exactly the same as getting the *right*
thing to work, I'm still concerned that the poor fellow
is not working on the right thing. :-(

Unless your goal is some kind of pseudo-science, working
with the representation of the data rather than the data
itself is rarely a good idea.

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: contour fill [message #21462 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
davidf@dfanning.com (David Fanning) writes:

> Stephen O'Sullivan (so@amsta.leeds.ac.uk) writes:
>
>> Thanks for your help but the problem that I didn't really make clear is
>> that I need all the values contained within the specified closed contour,
>> not just those above or below the contour value. In this sense it's a
>> geometric thing.
>
> Oh, well then, you are in for some work. :-)
>
> You will have to use the Path_Info and Path_XY keywords
> to fish out the contour lines you are concerned with
> ...

Wow David you must be trying hard to drum up consulting business :-).
I tried it myself, having never had ROI experience before, and got
something to work in about ten minutes.

Here is an example of thresholding an image the hard way, using the
technique you just described. The first part (the wordiest) is just
to set up an image to work on. The meat of the function is CONTOUR
and POLYFILLV -- and no graphics are produced. In fact you don't even
need to set up a graphics coordinate system on the screen. The
routines GAUSS2 and PLOTIMAGE are available from my web page
(http://cow.physics.wisc.edu/~craigm/idl/, check the Full Listing).

Once you have the list of pixels (the value of WH below) you can do
anything with it. I did a simple threshold but of course you could do
something harder. Now of course, the *real* problem is deciding
*which* contour to use when there are many of them. Here I have just
taken the first one. If you know there will always be one big one
then you might be able to get away by calculating the area of each
(eg, number of pixels in each) and taking the largest.

Craig

;; Create image using two gaussian functions
nx = 100 & ny = nx
dx = 0.1 & dy = dx
x = findgen(nx)*dx-5. & y = x
xx = rebin(reform(x,nx,1),nx,ny)
yy = rebin(reform(y,1,ny),nx,ny)
im = gauss2(xx, yy, [2.5, -4.2, 2., 50]) + gauss2(xx, yy, [-.5, 3, 4., 30])

;; Extract contour information - in this case everything inside the 20 contour
contour, im, x, y, levels=[20], path_info=pin, path_xy=pxy, $
/path_data, /close

;; Extract the contour of interest
c0off = pin(0).offset + lindgen( pin(0).n )
c0x = (pxy(0,c0off) - x(0)) / dx ;; Convert to scan cols & lines
c0y = (pxy(1,c0off) - y(0)) / dy

;; Use POLYFILLV to create a region of interest, and hence a mask
wh = polyfillv(c0x, c0y, nx, ny)
mask = (im*0)
mask(wh) = 1

;; Plot the masked image for verification
imgx = [-5.05, 4.95] & imgy = imgx
plotimage, im*mask, range=[0,52], imgxrange=imgx, imgyrange=imgy


Good luck,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: contour fill [message #21468 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Stephen O'Sullivan (so@amsta.leeds.ac.uk) writes:

> Sounds like a nightmare!

I think you are beginning to get into the spirit
of IDL contours! :-)

> The reason I'm doing it is that I need some self-consistent way of
> defining a closed region in a fluid flow problem. It doesn't matter if
> it's ad hoc just so long as it's consistent.

For a closed contour, this is really not so bad. Er, well,
once you figure out how the Path_Info and Path_XY keywords
work. But PolyFillV is self-consistent if you take some
care in how you create your contour plot. For example,
always use the same size window, always position the contour
plot with the Position keyword, don't allow axis autoscaling,
create your own contour levels, etc. etc. All the normal
Contour things. :-)

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: contour fill [message #21469 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
so is currently offline  so
Messages: 9
Registered: August 2000
Junior Member
On Fri, 25 Aug 2000, David Fanning wrote:

> Oh, well then, you are in for some work. :-)
>
> You will have to use the Path_Info and Path_XY keywords
> to fish out the contour lines you are concerned with
> (lower and upper contour). You will have to use this
> information to come up with some kind of polygon. (You
> may have to use several polygons, depending upon how
> complex this contour really is.) You can use the polygon
> with PolyfillV to find all the indices in the image on
> the display that meet the criteria but...
>
> What good is it going to do you? Those geometric
> indices describe the *representation* of the data,
> not the data itself.
>
> I think you are right back to where I put you before. :-)
>

Sounds like a nightmare! I thought there might be some clever way
of tweaking the fill routine in contour (I'm a bit of an IDL novice). I
may have to write my own script to do this instead.

The reason I'm doing it is that I need some self-consistent way of
defining a closed region in a fluid flow problem. It doesn't matter if
it's ad hoc just so long as it's consistent.

Thank you for your help,
Steve

============================================================ ===============
Dr Stephen O'Sullivan | Telephone: +44-113-2335187
Department of Applied Mathematics | Facsimile: +44-113-2429925
University of Leeds | Email : so@amsta.leeds.ac.uk
Leeds LS2 9JT UK | WWW: www.amsta.leeds.ac.uk/applied
============================================================ ===============
Re: contour fill [message #21472 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Stephen O'Sullivan (so@amsta.leeds.ac.uk) writes:

> Thanks for your help but the problem that I didn't really make clear is
> that I need all the values contained within the specified closed contour,
> not just those above or below the contour value. In this sense it's a
> geometric thing.

Oh, well then, you are in for some work. :-)

You will have to use the Path_Info and Path_XY keywords
to fish out the contour lines you are concerned with
(lower and upper contour). You will have to use this
information to come up with some kind of polygon. (You
may have to use several polygons, depending upon how
complex this contour really is.) You can use the polygon
with PolyfillV to find all the indices in the image on
the display that meet the criteria but...

What good is it going to do you? Those geometric
indices describe the *representation* of the data,
not the data itself.

I think you are right back to where I put you before. :-)

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: contour fill [message #21474 is a reply to message #21378] Fri, 25 August 2000 00:00 Go to previous messageGo to next message
so is currently offline  so
Messages: 9
Registered: August 2000
Junior Member
On Fri, 25 Aug 2000, David Fanning wrote:

> Stephen O'Sullivan (so@amsta.leeds.ac.uk) writes:
>
>> I am trying to get IDL to isolate the values contained within a closed
>> contour of a plotted data array. Basically, I want to perform a
>> calculation using these values instead of cloouring them in like /fill
>> does.
>>
>> Any help would be greatly appreciated!
>
> valuesIwant = Where(dataArray GE lowContourLevel $
> AND dataArray LE highContourLevel)
> result = Mean(dataArray[valuesIwant])
>

Thanks for your help but the problem that I didn't really make clear is
that I need all the values contained within the specified closed contour,
not just those above or below the contour value. In this sense it's a
geometric thing.

Cheers, Steve

============================================================ ===============
Dr Stephen O'Sullivan | Telephone: +44-113-2335187
Department of Applied Mathematics | Facsimile: +44-113-2429925
University of Leeds | Email : so@amsta.leeds.ac.uk
Leeds LS2 9JT UK | WWW: www.amsta.leeds.ac.uk/applied
============================================================ ===============
Re: contour fill [message #21533 is a reply to message #21378] Thu, 31 August 2000 03:46 Go to previous message
so is currently offline  so
Messages: 9
Registered: August 2000
Junior Member
On 26 Aug 2000, Craig Markwardt wrote:

>
> davidf@dfanning.com (David Fanning) writes:
>> Leaving aside the observation that getting *something*
>> to work is not exactly the same as getting the *right*
>> thing to work, I'm still concerned that the poor fellow
>> is not working on the right thing. :-(
>>
>> Unless your goal is some kind of pseudo-science, working
>> with the representation of the data rather than the data
>> itself is rarely a good idea.
>
> He was asking *how?*. You are asking *why?*. Both are fair
> questions.
>
> You wondered why a basic threshold wouldn't work. I think his reply
> was that he wanted to select a *particular* contour. When there are
> several peaks in the data then a simple threshold will not work. As I
> pointed out the hardest part in the algorithm I gave is selecting the
> right contour. [And I gave a posible heuristic to decide.]
>
> Craig
>
> --
> ------------------------------------------------------------ --------------
> Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> ------------------------------------------------------------ --------------
>
>

That's right. I need a particular contour which is well defined and there
is a well rigorous physical meaning to what I am trying to do. It is
of course the representation of the data which I am manipulating and the I
fully understand that interpretation of this representation is important
if proper physical sense is to be made.

I haven't tried the suggestions which have been posted but when I have
I'll let you know how they work compared to a C program I have written to
do the job.

Cheers, Stephen


============================================================ ===============
Dr Stephen O'Sullivan | Telephone: +44-113-2335187
Department of Applied Mathematics | Facsimile: +44-113-2429925
University of Leeds | Email : so@amsta.leeds.ac.uk
Leeds LS2 9JT UK | WWW: www.amsta.leeds.ac.uk/applied
============================================================ ===============
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL EPA Exam Test Question
Next Topic: Re: reading dem

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

Current Time: Wed Oct 08 17:36:59 PDT 2025

Total time taken to generate the page: 0.00844 seconds