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

Home » Public Forums » archive » Re: creating a 2D mask for image filtering
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: creating a 2D mask for image filtering [message #77211] Wed, 17 August 2011 06:12 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

Whoops, this line:

> maxRadius = Max(s)/2

Should be this:

maxRadius = Min(s)/2

Cheers,

David

--
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.")
Re: creating a 2D mask for image filtering [message #77212 is a reply to message #77211] Wed, 17 August 2011 06:11 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dave Higgins writes:

> I need to create a 2D mask to filter data in the frequency domain
> (apodization). I would like to leave 0.8 of the centre-to-edge of the
> data untouched (i.e. a circle of untouched data), and then a Hanning-
> type shape to smooth down to zero at the edges. (Think of an upside-
> down frying pan, kinda.) I can apply a Hanning filter with
>
> apod_fn = HANNING(kx_res, ky_res, alpha=0.5)
>
> but of course the centre area which I would like to have untouched
> doesn't exist, and the filter is too aggressive. I'd go without the
> Hanning shape requirement if I could get more-or-less the right shape.
> I see also DIGITAL_FILTER, but can't seem to widen the filter with my
> changes to it's arguments.
>
> Thanks for any pointers.

I would construct your filter something like this:

s = Size(image, /Dimensions)
hf = Hanning(s[0], s[1], ALPHA=0.5)
thisDevice = !D.Name
Set_Plot, 'Z'
Device, SET_RESOLUTION=s, SET_PIXEL_DEPTH=8, DECOMPOSED=0
Erase, COLOR=0
maxRadius = Max(s)/2
TVCircle, maxRadius*0.8, s[0]/2, s[1]/2, COLOR=1, /FILL
circleMask = TVRD()
Set_Plot, thisDevice
indices = Where(circleMask EQ 1)
hf[indices] = 1
cgSurface, hf
END

Cheers,

David
--
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.")
Re: creating a 2D mask for image filtering [message #77299 is a reply to message #77211] Wed, 17 August 2011 09:44 Go to previous message
David Higgins is currently offline  David Higgins
Messages: 13
Registered: August 2009
Junior Member
Thanks for the advice, very much appreciated. I followed your general method as follows, but actually it's not the filter shape I want:

FUNCTION CIRCLE, xcenter, ycenter, radius
points = (2 * !PI / 99.0) * FINDGEN(100)
x = xcenter + radius * COS(points )
y = ycenter + radius * SIN(points )
RETURN, TRANSPOSE([[x],[y]])
END

PRO apod_filter
image = dist(512)
WINDOW, 0, TITLE = 'Test data before filtering'
SHADE_SURF, image
s = Size(image, /Dimensions)
hf = Hanning(s[0], s[1], ALPHA=0.5)
maxRadius = Min(s)/2;
WINDOW, 1, TITLE = 'temporary window', xsize=s[0], ysize=s[1]
; Use of data coords for "circle" ok since data extent may not be square
POLYFILL, CIRCLE(s[0]/2-1, s[1]/2-1, 0.8*maxRadius), color=1
circleMask = TVRD()
WDELETE, 1
indices = Where(circleMask EQ 1)
hf[indices] = 1
WINDOW, 2, TITLE = 'Filter to be applied'
SHADE_SURF, hf
WINDOW, 3, TITLE = 'Apodized image'
SHADE_SURF, hf*image
WDELETE, 0, 3
END

This produces a step down at the edge of the circle, to where the Hanning window was before the circleMask was applied. But this step-down causes Gibbs ringing in a FT of the data.
I was aiming for a smooth "S" shaped (or similar) reduction of the filter values from the edge of the circle to the edge of the data.
I was wondering if I applied some sort of smoothing to circleMask, it would blur the edge of the circle and achieve the smooth decent at the circle edge:

PRO apod_filter
image = dist(512)
WINDOW, 0, TITLE = 'Test data before filtering'
SHADE_SURF, image
s = Size(image, /Dimensions)
maxRadius = Min(s)/2;
WINDOW, 1, TITLE = 'temporary window', xsize=s[0], ysize=s[1]
; Use of data coords for "circle" ok since data extent may not be square
POLYFILL, CIRCLE(s[0]/2-1, s[1]/2-1, 0.8*maxRadius), color=1
circleMask = float(TVRD())
WDELETE, 1
help, circlemask
circleMask = SMOOTH(circleMask, 100, /EDGE_TRUNCATE, MISSING=0.0)
indices = Where(circleMask GT 0.01)
filter = fltarr(s[0], s[1])
filter[indices] = circleMask[indices]
WINDOW, 2, TITLE = 'Filter to be applied'
SHADE_SURF, filter
WINDOW, 3, TITLE = 'Apodized image'
SHADE_SURF, filter*image
WDELETE, 0, 3
END

...but this smoothing eats back into my leave-it-alone circle of data; I'd like to start the descent to zero at the edge of the originally defined circleMask.

Thanks for any further help.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Unable to get GRIDDATA Function to Work Properly
Next Topic: difficulty using "linterp" command - need help making loop to exclude a value yet average others

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

Current Time: Wed Oct 08 15:22:10 PDT 2025

Total time taken to generate the page: 0.00476 seconds