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

Home » Public Forums » archive » Re: MORPH_XYZ and values keyword
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: MORPH_XYZ and values keyword [message #35522] Wed, 25 June 2003 00:10 Go to next message
Karsten Rodenacker is currently offline  Karsten Rodenacker
Messages: 98
Registered: July 1997
Member
Hallo, maybe some information concerning VALUE keywords. Let ste the
structuring element and val the values array.
1. Only val*(ste ne 0) is of importance!
2. As far as I know are the val values subtracted or added from the
input data befor the max or min according erode or dilate is performed.
Hence, flat value arrays do not make sense.
3. I attach two routines (for 1-d morphological filtering) for
illustration. gen_sphere to generate the value array and mm_filter to
apply a sequence of increasing filter steps. Unluckily the routines are
not documented. Maybe they are comprehensible without further words.

Regards
Karsten

Ben Tupper schrieb:
> Hello,
>
> I completely mystified by the VALUES keyword to the MORPH_XYZ (like
> MORPH_TOPHAT) routines. I think I understand the meaning of VALUES for
> DILATE and ERODE-like routines - but I can't make sense of the MORPH_XYZ
> routines.
>
> Here's the description of the so-called structuring element that these
> rotuine accept...it gives the shape and 'on-off'-ness of each pixel.
>
> A one-, two-, or three-dimensional array to be used as the structuring
> element. The elements are interpreted as binary values � either zero or
> nonzero. The structuring element must have the same number of dimensions
> as the Image argument.
>
>
>
> Now here's the decription of the VALUES keyword...
>
> An array of the same dimensions as the Structure argument providing the
> values of the structuring element. If the VALUES keyword is not present,
> all elements of the structuring element are 0.
>
>
> What the heck does that mean?
>
> I thought providing the VALUES was like
> providing a weighting to the structuring element.
>
>
> Here's an example using the MORPH_TOPHAT routine... if here's a
> structure with a narrow brim - any peaks detected that fit within the 1s
> is a keeper.
>
> 0 0 0 1 0 0 0
> 0 1 1 1 1 1 0
> 0 1 1 1 1 1 0
> 1 1 1 1 1 1 1
> 0 1 1 1 1 1 0
> 0 1 1 1 1 1 0
> 0 0 0 1 0 0 0
>
> Now if I am working with a grayscale image... I want to make sure the
> peak is tall (bright) enough so, I weight the structuring element with
> some kind of a height - like I want the peak to be at least 5 whatevers
> above the brim values. So I set VALUES equal to...
>
> 0 0 0 5 0 0 0
> 0 5 5 5 5 5 0
> 0 5 5 5 5 5 0
> 5 5 5 5 5 5 5
> 0 5 5 5 5 5 0
> 0 5 5 5 5 5 0
> 0 0 0 5 0 0 0
>
>
> I can't see any difference between the results when I do and do not
> provide the VALUES. Which, of course, means I don't understand it at all.
>
> Stumped and grateful for any help,
>
> Ben
>


function mm_filter,vt,start,ende,LINEAR=linear,ST_TYPE=typ,FIRST=firs t
;
; Ouverture und Fermeture nach Sternberg (Morphological filters ?)
;
if keyword_set(linear) then stern=0 else stern=1
if not keyword_set(typ) then typ=0 ;dreieck
if not keyword_set(first) then first=0 ;ouverture am Anfang
svt=size(vt)
xvt=[vt[svt[1]-indgen(svt[1])-1],vt,vt[svt[1]-indgen(svt[1]) -1]]
low=xvt
upp=xvt
for l=start,ende do begin
kerg=gen_sphere(l,typ=typ)
if not first then begin
if stern then begin
low=dilate(erode(low,kerg ge 0,val=kerg),kerg gt 0,val=kerg)
upp=erode(dilate(upp,kerg ge 0,val=kerg),kerg gt 0,val=kerg)
endif else begin
low=dilate(erode(low,kerg ge 0,/gr),kerg ge 0,/gr)
upp=erode(dilate(upp,kerg ge 0,/gr),kerg ge 0,/gr)
endelse
endif else begin
if stern then begin
low=erode(dilate(low,kerg ge 0,val=kerg),kerg ge 0,val=kerg)
upp=dilate(erode(upp,kerg ge 0,val=kerg),kerg ge 0,val=kerg)
endif else begin
low=erode(dilate(low,kerg ge 0,/gr),kerg ge 0,/gr)
upp=dilate(erode(upp,kerg ge 0,/gr),kerg ge 0,/gr)
endelse
endelse
first=(not first) and 1
endfor
return,[[upp[svt[1]:svt[1]*2-1]],[low[svt[1]:svt[1]*2-1]]]
end
res=mm_filter(vt4,1,4,fir=0,st_typ=1)&plot,vt4,col=1,psy m=5,syms=0.25&oplot,res[*,0],col=2&oplot,res[*,1],co l=2&wshow,1
end
function gen_sphere, rad, TYPE=typ

if not keyword_set(typ) then typ=0
case typ of
1:v = sqrt(rad^2-(rad-findgen(rad*2+1))^2)
2:v = rad^2-(rad-findgen(rad*2+1))^2
3:v = 0.05/(1.+sqrt(rad^2-(rad-findgen(rad*2+1))^2))
4:v = 0.05/(1.+rad^2-(rad-findgen(rad*2+1))^2)
5:v = rad-sqrt(rad^2-(rad-findgen(rad*2+1))^2)
6:v = rad^2-(rad-findgen(rad*2+1))^2
-1:v = replicate(1.0,rad*2+1)
else: v = rad-abs(-findgen(rad*2+1)+rad)
ENDCASE
mv = max(v)
IF mv GT (rad+1) THEN v = v/mv*(rad+1)
return, v
end
Re: MORPH_XYZ and values keyword [message #35667 is a reply to message #35522] Wed, 25 June 2003 07:17 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Karsten Rodenacker wrote:
> Hallo, maybe some information concerning VALUE keywords. Let ste the
> structuring element and val the values array.
> 1. Only val*(ste ne 0) is of importance!
> 2. As far as I know are the val values subtracted or added from the
> input data befor the max or min according erode or dilate is performed.
> Hence, flat value arrays do not make sense.
> 3. I attach two routines (for 1-d morphological filtering) for
> illustration. gen_sphere to generate the value array and mm_filter to
> apply a sequence of increasing filter steps. Unluckily the routines are
> not documented. Maybe they are comprehensible without further words.
>


Thanks Karsten,

This helps very much. I'm still not clear on why a flat-topped VALUES
do not make sense. Here's what I get from the online docs for ERODE
and DILATE. They don't look symmetric to me - so it seems like a
flat-topped kernal would have a meaningful effect. But, I'm new at this
and feeling like I'm on pretty thin ice.


Erode... result = min(Image) - VALUE
"Each pixel of the result is the minimum of Image less the corresponding
elements of VALUE."

Dilate... result = max(Image + VALUE)
"Each pixel of the result is the maximum of the sum of the corresponding
elements of VALUE and the Image pixel value. "

The Tophat filter is supposed to be...
result = (Erosion followed by Dilation) - OriginalImage

I have mocked up an 1-d example (below) using your gen_sphere routine.
It looks to me like I might be better off *not* using the VALUES anyway.

Just type morphtest from the command line. The top plot is the tophat
without values specified. The second is with the fat-topped (the VALUES
structure is shown hovering over the plot on the right.) And the last
is using a non-flat-topped structure (also shown at hovering at right.)

Thanks,
Ben


*********begin code
function gen_sphere, rad, TYPE=typ

if not keyword_set(typ) then typ=0
case typ of
1:v = sqrt(rad^2-(rad-findgen(rad*2+1))^2)
2:v = rad^2-(rad-findgen(rad*2+1))^2
3:v = 0.05/(1.+sqrt(rad^2-(rad-findgen(rad*2+1))^2))
4:v = 0.05/(1.+rad^2-(rad-findgen(rad*2+1))^2)
5:v = rad-sqrt(rad^2-(rad-findgen(rad*2+1))^2)
6:v = rad^2-(rad-findgen(rad*2+1))^2
-1:v = replicate(1.0,rad*2+1)
else: v = rad-abs(-findgen(rad*2+1)+rad)
ENDCASE
mv = max(v)
IF mv GT (rad+1) THEN v = v/mv*(rad+1)
return, v
end




Pro MorphTest

x = [19,19,21,23,24,23,22,21,20,19,20,20,19,17,15,$
13,11,11,12,14,17,21,24,25,24,23,21,21,23,26,29,30,27,$
22,17,12,10,10,12,14,16,19,20,21,20,17,12,8,$
4,3,3,6,10,14,19,23,26,27,28,29,29,29,29,27,$
23,19,16,14,14,16,18,19,19,18,15,13,11,7,$
4,1,0,0,3,6,10,12,12,11,8,5,2,1,1,4,7,11,14,17,20,23,27]


n = 10

old_p = !P
!P.CharSize = 2
!P.Multi = [0,1,3]

Dim = get_Screen_Size()
Window, /Free, ys = dim[1]*0.9
plot, x, title = 'orig with simple tophat'
oplot, thick = 2, $
morph_tophat(x, [0, replicate(1,n-1), 0])

plot, x, title = 'orig with tophat values set with flat top'
values = [0, replicate(9,n-1),0]
oplot, thick = 2, $
morph_tophat(x, [0, replicate(1,n-1), 0], values = values )
oplot, Indgen(n+1) + 80, values + 10, thick = 2


plot, x, title = 'orig with tophat values set with rounded top'
values = gen_sphere(n/2)
oplot, thick =2, $
morph_tophat(x, [0, replicate(1,n-1), 0],values =values )
oplot, Indgen(n+1) + 80, values + 10, thick = 2

!P = old_p
End
**********end code
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: register_cursor error, Win 2000
Next Topic: sec : U How to equivalence byte array to defined structures?

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

Current Time: Wed Oct 08 15:53:38 PDT 2025

Total time taken to generate the page: 0.00448 seconds