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

Home » Public Forums » archive » Shape to raster
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
Shape to raster [message #78139] Wed, 26 October 2011 09:52 Go to next message
Fabzou is currently offline  Fabzou
Messages: 76
Registered: November 2010
Member
Dear IDLers,

My apologies if this question has been posted before.

I have a polygon vector file from which I know the coordinates within a
grid (subpixel precision) and I would like to make a mask from this
information (within the polygon = 1, outside = 0).

The only idea I have to make this would be to use the polyfill command
and use the produced image as a mask. This would be easy to do, but I am
worried about the precision I would reach by doing so (I am concerned
about the line thickness, for example, and all the things that make of
POLYFILL and DRAW_ROI a plot routine and not a "shape to raster" routine).

Maybe there is an IDL equivalent to the ENVI "Build mask from a ROI" tool?

Thanks for your help!

Fabz
Re: Shape to raster [message #78173 is a reply to message #78139] Mon, 31 October 2011 09:17 Go to previous message
Fabzou is currently offline  Fabzou
Messages: 76
Registered: November 2010
Member
Hi,

On 10/31/2011 05:09 PM, ben.bighair wrote:

> I think the PIXEL_CENTER keyword is going to provide you with control
> over this issue.
>
> http://idlastro.gsfc.nasa.gov/idl_html_help/IDLanROIComputeM ask.html#wp1003888
>
> Cheers,
> Ben

Funny enough, the PIXEL_CENTER is not mentioned in the IDLanROIGroup
documentation!

http://idlastro.gsfc.nasa.gov/idl_html_help/IDLanROIGroupCom puteMask.html

Thanks for the hint,

Fab
Re: Shape to raster [message #78174 is a reply to message #78139] Mon, 31 October 2011 09:09 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
Hi,

On Oct 31, 10:54 am, David Fanning <n...@dfanning.com> wrote:
> Fabzou writes:
>> I have an other question though. How will the IDLanROI object
>> "understand" the XY coordinates [0.5,0.5]? In my conception, these
>> coordinates correspond to the center of the first down left pixel, but
>> my first tests tend to show that this may not be the case...
>
> Oh, my gosh! I just spent a week worrying about this
> in conjunction with an update of my Active Contouring
> software! I don't use an IDLanROI object there, because
> I want to do this myself and completely understand what
> I am doing. In *my* ROI, the [0.5,0.5] location would
> indeed be the center of the first pixel. I don't know
> off-hand what the IDLanROI object will do.

I think the PIXEL_CENTER keyword is going to provide you with control
over this issue.

http://idlastro.gsfc.nasa.gov/idl_html_help/IDLanROIComputeM ask.html#wp1003888

Cheers,
Ben
Re: Shape to raster [message #78175 is a reply to message #78139] Mon, 31 October 2011 09:07 Go to previous message
Fabzou is currently offline  Fabzou
Messages: 76
Registered: November 2010
Member
Ok, it seems that [0,0] is the center point of the pixel (quite in
contradiction with polyfill, actually).

The following tests help to understand its behavior:

IDL> xs = [-0.05,-0.05,0.05,0.05,-0.05]
IDL> ys = [-0.05,0.05,0.05,-0.05,-0.05]
IDL> roi = OBJ_NEW('IDLanROI', xs, ys)
IDL> mask = roi->ComputeMask(DIMENSIONS=[3,3])
IDL> print, mask
255 0 0
0 0 0
0 0 0
IDL> OBJ_DESTROY, roi
IDL> xs = [-0.05,-0.05,0.05,0.05,-0.05]
IDL> ys = [-0.05,0.05,0.05,-0.05,-0.05]
IDL> roi = OBJ_NEW('IDLanROI', xs, ys)
IDL> mask = roi->ComputeMask(DIMENSIONS=[3,3], MASK_RULE=1)
IDL> print, mask
0 0 0
0 0 0
0 0 0
IDL> OBJ_DESTROY, roi
IDL> xs = [0.45,0.45,1.55,1.55,0.45]
IDL> ys = [0.45,1.55,1.55,0.45,0.45]
IDL> roi = OBJ_NEW('IDLanROI', xs, ys)
IDL> mask = roi->ComputeMask(DIMENSIONS=[3,3], MASK_RULE=1)
IDL> print, mask
0 0 0
0 255 0
0 0 0
IDL> OBJ_DESTROY, roi
IDL> xs = [0.45,0.45,1.55,1.55,0.45]
IDL> ys = [0.45,1.55,1.55,0.45,0.45]
IDL> roi = OBJ_NEW('IDLanROI', xs, ys)
IDL> mask = roi->ComputeMask(DIMENSIONS=[3,3])
IDL> print, mask
255 255 255
255 255 255
255 255 255
IDL> OBJ_DESTROY, roi

There is no possibility to generate a mask based on how many percent of
the pixel surface is covered by the polygon, but some trick can allow
this (generate a mask on an image 10 times larger and aggregate it
afterwards, for example)


Fab



On 10/31/2011 03:54 PM, David Fanning wrote:
> Fabzou writes:
>
>> I have an other question though. How will the IDLanROI object
>> "understand" the XY coordinates [0.5,0.5]? In my conception, these
>> coordinates correspond to the center of the first down left pixel, but
>> my first tests tend to show that this may not be the case...
>
> Oh, my gosh! I just spent a week worrying about this
> in conjunction with an update of my Active Contouring
> software! I don't use an IDLanROI object there, because
> I want to do this myself and completely understand what
> I am doing. In *my* ROI, the [0.5,0.5] location would
> indeed be the center of the first pixel. I don't know
> off-hand what the IDLanROI object will do. And I have
> no compelling interest in looking into it this morning,
> either. It makes my head hurt. :-)
>
> Cheers,
>
> David
>
> P.S. If you are going to test this, however, I would
> test with the values 0.45 and 0.55, not the value 0.5.
> At some point, you are going to have to do some rounding
> if you want image or device coordinates. The question
> you want to answer is how the rounding is done.
>
>
Re: Shape to raster [message #78178 is a reply to message #78139] Mon, 31 October 2011 07:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fabzou writes:

> I have an other question though. How will the IDLanROI object
> "understand" the XY coordinates [0.5,0.5]? In my conception, these
> coordinates correspond to the center of the first down left pixel, but
> my first tests tend to show that this may not be the case...

Oh, my gosh! I just spent a week worrying about this
in conjunction with an update of my Active Contouring
software! I don't use an IDLanROI object there, because
I want to do this myself and completely understand what
I am doing. In *my* ROI, the [0.5,0.5] location would
indeed be the center of the first pixel. I don't know
off-hand what the IDLanROI object will do. And I have
no compelling interest in looking into it this morning,
either. It makes my head hurt. :-)

Cheers,

David

P.S. If you are going to test this, however, I would
test with the values 0.45 and 0.55, not the value 0.5.
At some point, you are going to have to do some rounding
if you want image or device coordinates. The question
you want to answer is how the rounding is done.


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: unable to set time attribute for netCDF in IDL
Next Topic: Re: wind fields on map

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

Current Time: Wed Oct 08 13:47:26 PDT 2025

Total time taken to generate the page: 0.00474 seconds