| [mmbggmodel] [Up] [mmropen] | Additional Toolbox functions |
Implemented in Python.
| f | mmIMAGE. |
| type | mmSTRING. Disk family: 'OCTAGON', 'CHESSBOARD', 'CITY-BLOCK', 'LINEAR-V', 'LINEAR-H', 'LINEAR-45R', 'LINEAR-45L', 'USER'. Default:
|
| n | mmDOUBLE. Maximum disk radii. Default:
|
| Bc | mmSE. Connectivity for the reconstructive opening. Used if '-REC' suffix is appended in the 'type' string. Default:
|
| Buser | mmSE. User disk, used if 'type' is 'USER'. Default:
|
| h | mmIMAGE. |
| y | mmIMAGE. |
Compute the local granulometry given by the mean radius around a moving windows. The window is specified by a convolution kernel. The disk sequence must satisfy the following: if r > s, rB is sB-open, i.e. rB open by sB is equal rB. Non-flat disks can be generated if the suffix -NF is appended to the disk family name.
from handson import *
f = mmbinary([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 1, 0, 1, 1, 1, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0]]);
h,y = mmlgranul( f, 'city-block')
processing r= 0 processing r= 1 processing r= 2
print h
[ 0.26666667 0.73333333]
print y
[[0 0 0 0 0 0 0 0] [0 0 1 2 2 2 0 0] [0 0 2 2 2 2 2 0] [0 1 0 2 2 2 0 0] [1 1 0 0 0 0 0 0]]
h,y = mmlgranul( f, 'linear-h')
processing r= 0 processing r= 1 processing r= 2 processing r= 3
print h
[ 0.06666667 0.6 0.33333333]
print y
[[0 0 0 0 0 0 0 0] [0 0 2 2 2 2 0 0] [0 0 3 3 3 3 3 0] [0 1 0 2 2 2 0 0] [2 2 0 0 0 0 0 0]]
h,y = mmlgranul( f, 'linear-45r')
processing r= 0 processing r= 1 processing r= 2 processing r= 3 processing r= 4
print h
[ 0.53333333 0.2 0. 0.26666667]
print y
[[0 0 0 0 0 0 0 0] [0 0 1 4 1 2 0 0] [0 0 4 1 2 1 1 0] [0 4 0 2 1 1 0 0] [4 1 0 0 0 0 0 0]]
h,y = mmlgranul( f, 'user',10,mmsecross(),mmimg2se(mmbinary([0,1,1])))
processing r= 0 processing r= 1 processing r= 2 processing r= 3 processing r= 4 processing r= 5
print h
[ 0.06666667 0.13333333 0.2 0.26666667 0.33333333]
print y
[[0 0 0 0 0 0 0 0] [0 0 4 4 4 4 0 0] [0 0 5 5 5 5 5 0] [0 1 0 3 3 3 0 0] [2 2 0 0 0 0 0 0]]
h,y = mmlgranul( mmgray(f), 'city-block-nf')
processing r= 0 processing r= 1 processing r= 2
print h
[ 0.50704225 0.49295775]
print y
[[ 0 0 0 0 0 0 0 0] [ 0 0 255 510 510 510 0 0] [ 0 0 510 510 510 510 510 0] [ 0 255 0 510 510 510 0 0] [255 255 0 0 0 0 0 0]]
def mmlgranul(f, type='OCTAGON', n=65535, Bc=None, Buser=None):
from string import upper, index
from Numeric import shape, zeros, sum, concatenate, reshape, ravel
from morph import mmsecross, mmintersec, uint8, int32, mmbinary, mmgray, mmskelmrec, mmimg2se, mmstats, mmopen, mmsedisk, mmsesum, mmsubm
if Bc is None: Bc = mmsecross()
if Buser is None: Buser = mmsecross()
type = upper(type);
try:
ii=index(type,'-NF');
nonflat = 'NON-FLAT';
type = type[:ii]; # remove the -NF suffix
except:
nonflat = 'FLAT';
if (type == 'OCTAGON' or
type == 'CHESSBOARD' or
type == 'CITY-BLOCK' ):
flag = 0;
n = min(n,max(shape(f)));
elif type == 'LINEAR-H':
se = mmimg2se(mmbinary([1,1,1]));
n = min(n,shape(f)[1]);
flag = 1;
elif type == 'LINEAR-V':
se = mmimg2se(mmbinary([[1],[1],[1]]));
n = min(n,shape(f)[0]);
flag = 1;
elif type == 'LINEAR-45R':
se = mmimg2se(mmbinary([[0,0,1],[0,1,0],[1,0,0]]));
n = min(n,min(shape(f)));
flag = 1;
elif type == 'LINEAR-45L':
se = mmimg2se(mmbinary([[1,0,0],[0,1,0],[0,0,1]]));
n = min(n,min(shape(f)));
flag = 1;
elif type == 'USER':
se = Buser;
n = min(n,max(shape(f)));
flag = 1;
else:
print 'Error: only accepts OCTAGON, CHESSBOARD, CITY-BLOCK, LINEAR-H, LINEAR-V, LINEAR-45R, LINEAR-45L, or USER as type, or with suffix -NF.'
return
k=0;
a=mmbinary([1]);
z=mmbinary([0]);
a_old = f;
h = int32([]);
y = zeros(shape(f));
while not(mmstats(a,'max')==0 or (k>=n)):
print 'processing r=',k
if flag:
a=mmopen(f,mmsesum(se,k));
else:
a=mmopen(f,mmsedisk(k,'2D',type,nonflat));
res = mmsubm(a_old,a);
y = y + k * res;
k = k + 1;
h = concatenate((h,reshape(sum(ravel(res)),(1,))))
a_old = a;
h = h[1:];
h = (h+0.)/sum(h); # pattern spectrum
return h, y
| [mmbggmodel] [Up] [mmropen] | |