Shape to raster [message #78139] |
Wed, 26 October 2011 09:52  |
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 #78174 is a reply to message #78139] |
Mon, 31 October 2011 09:09  |
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  |
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  |
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.")
|
|
|