def iacdil(f, g, b=iasecross(), n=1): from iaintersec import iaintersec from iadil import iadil from iaisequal import iaisequal y = iaintersec(f,g) for i in xrange(n): aux = y y = iaintersec( iadil(y,b),g) if iaisequal(y,aux): break return y
def iacdil(f, g, b=iasecross(), n=1): from iaintersec import iaintersec from iadil import iadil from iaisequal import iaisequal y = iaintersec(f, g) for i in range(n): aux = y y = iaintersec(iadil(y, b), g) if iaisequal(y, aux): break return y
def iatoggle(f, f1, f2, OPTION="GRAY"): from iabinary import iabinary from iasubm import iasubm from iagray import iagray from iaunion import iaunion from iaintersec import iaintersec from ianeg import ianeg y = iabinary(iasubm(f, f1), iasubm(f2, f)) if upper(OPTION) == 'GRAY': t = iagray(y) y = iaunion(iaintersec(ianeg(t), f1), iaintersec(t, f2)) return y
def iadil(f, b=None): from iamat2set import iamat2set from ialimits import ialimits from iaisbinary import iaisbinary from iaintersec import iaintersec from iagray import iagray from iaadd4dil import iaadd4dil from iasecross import iasecross if b is None: b = iasecross() if len(f.shape) == 1: f = f[newaxis,:] h,w = f.shape x,v = iamat2set(b) if len(x)==0: y = (ones((h,w)) * ialimits(f)[0]).astype(f.dtype) else: if iaisbinary(v): v = iaintersec( iagray(v,'int32'),0) mh,mw = max(abs(x)[:,0]),max(abs(x)[:,1]) y = (ones((h+2*mh,w+2*mw)) * ialimits(f)[0]).astype(f.dtype) for i in range(x.shape[0]): if v[i] > -2147483647: y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w] = maximum( y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w], iaadd4dil(f,v[i])) y = y[mh:mh+h, mw:mw+w] return y
def iadist(f, Bc=iasecross(), METRIC=None): from iagray import iagray from iaintersec import iaintersec from iaisequal import iaisequal from iaero import iaero from iasebox import iasebox if METRIC is not None: METRIC = METRIC.upper() f = iagray(f, 'uint16') y = iaintersec(f, 0) if (METRIC == 'EUCLIDEAN') or (METRIC == 'EUC2'): f = int32(f) b = int32(zeros((3, 3))) i = 1 while any(f != y): a4, a2 = -4 * i + 2, -2 * i + 1 b = int32([[a4, a2, a4], [a2, 0, a2], [a4, a2, a4]]) y = f i = i + 1 f = iaero(f, b) if METRIC == 'EUCLIDEAN': y = uint16(sqrt(f) + 0.5) else: if iaisequal(Bc, iasecross()): b = int32([[-2147483647, -1, -2147483647], [-1, 0, -1], [-2147483647, -1, -2147483647]]) elif iaisequal(Bc, iasebox()): b = int32([[-1, -1, -1], [-1, 0, -1], [-1, -1, -1]]) else: b = Bc while any(f != y): y = f f = iaero(f, b) return y
def iatoggle(f, f1, f2, OPTION="GRAY"): from iabinary import iabinary from iasubm import iasubm from iagray import iagray from iaunion import iaunion from iaintersec import iaintersec from ianeg import ianeg y=iabinary( iasubm(f,f1),iasubm(f2,f)) if upper(OPTION) == 'GRAY': t=iagray(y) y=iaunion( iaintersec( ianeg(t),f1),iaintersec(t,f2)) return y
def iadil(f, b=None): from iamat2set import iamat2set from ialimits import ialimits from iaisbinary import iaisbinary from iaintersec import iaintersec from iagray import iagray from iaadd4dil import iaadd4dil from iasecross import iasecross if b is None: b = iasecross() if len(f.shape) == 1: f = f[newaxis, :] h, w = f.shape x, v = iamat2set(b) if len(x) == 0: y = (ones((h, w)) * ialimits(f)[0]).astype(f.dtype) else: if iaisbinary(v): v = iaintersec(iagray(v, 'int32'), 0) mh, mw = max(abs(x)[:, 0]), max(abs(x)[:, 1]) y = (ones((h + 2 * mh, w + 2 * mw)) * ialimits(f)[0]).astype(f.dtype) for i in range(x.shape[0]): if v[i] > -2147483647: y[mh + x[i, 0]:mh + x[i, 0] + h, mw + x[i, 1]:mw + x[i, 1] + w] = maximum( y[mh + x[i, 0]:mh + x[i, 0] + h, mw + x[i, 1]:mw + x[i, 1] + w], iaadd4dil(f, v[i])) y = y[mh:mh + h, mw:mw + w] return y
def iaskelm(f, B=iasecross(), option="binary"): from iaisbinary import iaisbinary from ialimits import ialimits from iagray import iagray from iaintersec import iaintersec from iasesum import iasesum from iaero import iaero from iaisequal import iaisequal from iaopenth import iaopenth from iasedil import iasedil from iaunion import iaunion from iabinary import iabinary from iapad import iapad from iaunpad import iaunpad assert iaisbinary(f),'Input binary image only' option = upper(option) f = iapad(f,B) print f k1,k2 = ialimits(f) y = iagray( iaintersec(f, k1),'uint16') iszero = asarray(y) nb = iasesum(B,0) for r in range(1,65535): ero = iaero( f, nb) if iaisequal(ero, iszero): break f1 = iaopenth( ero, B) nb = iasedil(nb, B) y = iaunion(y, iagray(f1,'uint16',r)) if option == 'BINARY': y = iabinary(y) y = iaunpad(y,B) return y
def iaskelm(f, B=iasecross(), option="binary"): from iaisbinary import iaisbinary from ialimits import ialimits from iagray import iagray from iaintersec import iaintersec from iasesum import iasesum from iaero import iaero from iaisequal import iaisequal from iaopenth import iaopenth from iasedil import iasedil from iaunion import iaunion from iabinary import iabinary from iapad import iapad from iaunpad import iaunpad assert iaisbinary(f), 'Input binary image only' option = upper(option) f = iapad(f, B) print f k1, k2 = ialimits(f) y = iagray(iaintersec(f, k1), 'uint16') iszero = asarray(y) nb = iasesum(B, 0) for r in range(1, 65535): ero = iaero(f, nb) if iaisequal(ero, iszero): break f1 = iaopenth(ero, B) nb = iasedil(nb, B) y = iaunion(y, iagray(f1, 'uint16', r)) if option == 'BINARY': y = iabinary(y) y = iaunpad(y, B) return y
def iadist(f, Bc=iasecross(), METRIC=None): from iagray import iagray from iaintersec import iaintersec from iaisequal import iaisequal from iaero import iaero from iasebox import iasebox if METRIC is not None: METRIC = upper(METRIC) f = iagray(f, "uint16") y = iaintersec(f, 0) if (METRIC == "EUCLIDEAN") or (METRIC == "EUC2"): f = int32(f) b = int32(zeros((3, 3))) i = 1 while any(f != y): a4, a2 = -4 * i + 2, -2 * i + 1 b = int32([[a4, a2, a4], [a2, 0, a2], [a4, a2, a4]]) y = f i = i + 1 f = iaero(f, b) if METRIC == "EUCLIDEAN": y = uint16(sqrt(f) + 0.5) else: if iaisequal(Bc, iasecross()): b = int32([[-2147483647, -1, -2147483647], [-1, 0, -1], [-2147483647, -1, -2147483647]]) elif iaisequal(Bc, iasebox()): b = int32([[-1, -1, -1], [-1, 0, -1], [-1, -1, -1]]) else: b = Bc while any(f != y): y = f f = iaero(f, b) return y
def iathick(f, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"): from iaisbinary import iaisbinary from iaintersec import iaintersec from iasupgen import iasupgen from iainterot import iainterot from iaunion import iaunion from iaisequal import iaisequal from iahomothick import iahomothick if Iab is None: Iab = iahomothick() DIRECTION = upper(DIRECTION) assert iaisbinary(f),'f must be binary image' if n == -1: n = product(f.shape) y = f zero = iaintersec(f,0) for i in range(n): aux = zero for t in range(0,360,theta): sup = iasupgen( y, iainterot(Iab, t, DIRECTION)) aux = iaunion( aux, sup) y = iaunion( y, sup) if iaisequal(aux,zero): break return y
def iathick(f, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"): from iaisbinary import iaisbinary from iaintersec import iaintersec from iasupgen import iasupgen from iainterot import iainterot from iaunion import iaunion from iaisequal import iaisequal from iahomothick import iahomothick if Iab is None: Iab = iahomothick() DIRECTION = upper(DIRECTION) assert iaisbinary(f), 'f must be binary image' if n == -1: n = product(f.shape) y = f zero = iaintersec(f, 0) for i in range(n): aux = zero for t in range(0, 360, theta): sup = iasupgen(y, iainterot(Iab, t, DIRECTION)) aux = iaunion(aux, sup) y = iaunion(y, sup) if iaisequal(aux, zero): break return y
def iagshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None): from iaisbinary import iaisbinary from iagray import iagray from iaunion import iaunion from iaintersec import iaintersec from ianeg import ianeg from iaconcat import iaconcat if iaisbinary(X): X = iagray(X,'uint8') r = X g = X b = X if X1 is not None: # red 1 0 0 assert iaisbinary(X1),'X1 must be binary overlay' x1 = iagray(X1,'uint8') r = iaunion(r,x1) g = iaintersec(g,ianeg(x1)) b = iaintersec(b,ianeg(x1)) if X2 is not None: # green 0 1 0 assert iaisbinary(X2),'X2 must be binary overlay' x2 = iagray(X2,'uint8') r = iaintersec(r,ianeg(x2)) g = iaunion(g,x2) b = iaintersec(b,ianeg(x2)) if X3 is not None: # blue 0 0 1 assert iaisbinary(X3),'X3 must be binary overlay' x3 = iagray(X3,'uint8') r = iaintersec(r,ianeg(x3)) g = iaintersec(g,ianeg(x3)) b = iaunion(b,x3) if X4 is not None: # magenta 1 0 1 assert iaisbinary(X4),'X4 must be binary overlay' x4 = iagray(X4,'uint8') r = iaunion(r,x4) g = iaintersec(g,ianeg(x4)) b = iaunion(b,x4) if X5 is not None: # yellow 1 1 0 assert iaisbinary(X5),'X5 must be binary overlay' x5 = iagray(X5,'uint8') r = iaunion(r,x5) g = iaunion(g,x5) b = iaintersec(b,ianeg(x5)) if X6 is not None: # cyan 0 1 1 assert iaisbinary(X6),'X6 must be binary overlay' x6 = iagray(X6,'uint8') r = iaintersec(r,ianeg(x6)) g = iaunion(g,x6) b = iaunion(b,x6) return iaconcat('d',r,g,b) return Y
def iagshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None): from iaisbinary import iaisbinary from iagray import iagray from iaunion import iaunion from iaintersec import iaintersec from ianeg import ianeg from iaconcat import iaconcat if iaisbinary(X): X = iagray(X, 'uint8') r = X g = X b = X if X1 is not None: # red 1 0 0 assert iaisbinary(X1), 'X1 must be binary overlay' x1 = iagray(X1, 'uint8') r = iaunion(r, x1) g = iaintersec(g, ianeg(x1)) b = iaintersec(b, ianeg(x1)) if X2 is not None: # green 0 1 0 assert iaisbinary(X2), 'X2 must be binary overlay' x2 = iagray(X2, 'uint8') r = iaintersec(r, ianeg(x2)) g = iaunion(g, x2) b = iaintersec(b, ianeg(x2)) if X3 is not None: # blue 0 0 1 assert iaisbinary(X3), 'X3 must be binary overlay' x3 = iagray(X3, 'uint8') r = iaintersec(r, ianeg(x3)) g = iaintersec(g, ianeg(x3)) b = iaunion(b, x3) if X4 is not None: # magenta 1 0 1 assert iaisbinary(X4), 'X4 must be binary overlay' x4 = iagray(X4, 'uint8') r = iaunion(r, x4) g = iaintersec(g, ianeg(x4)) b = iaunion(b, x4) if X5 is not None: # yellow 1 1 0 assert iaisbinary(X5), 'X5 must be binary overlay' x5 = iagray(X5, 'uint8') r = iaunion(r, x5) g = iaunion(g, x5) b = iaintersec(b, ianeg(x5)) if X6 is not None: # cyan 0 1 1 assert iaisbinary(X6), 'X6 must be binary overlay' x6 = iagray(X6, 'uint8') r = iaintersec(r, ianeg(x6)) g = iaunion(g, x6) b = iaunion(b, x6) return iaconcat('d', r, g, b) return Y
def iasedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0): from iabinary import iabinary from iasecross import iasecross from iasedil import iasedil from iasesum import iasesum from iasebox import iasebox from iaintersec import iaintersec from iagray import iagray METRIC = upper(METRIC) FLAT = upper(FLAT) assert DIM=='2D','Supports only 2D structuring elements' if FLAT=='FLAT': y = iabinary([1]) else: y = int32([h]) if r==0: return y if METRIC == 'CITY-BLOCK': if FLAT == 'FLAT': b = iasecross(1) else: b = int32([[-2147483647, 0,-2147483647], [ 0, 1, 0], [-2147483647, 0,-2147483647]]) return iasedil(y,iasesum(b,r)) elif METRIC == 'CHESSBOARD': if FLAT == 'FLAT': b = iasebox(1) else: b = int32([[1,1,1], [1,1,1], [1,1,1]]) return iasedil(y,iasesum(b,r)) elif METRIC == 'OCTAGON': if FLAT == 'FLAT': b1,b2 = iasebox(1),iasecross(1) else: b1 = int32([[1,1,1],[1,1,1],[1,1,1]]) b2 = int32([[-2147483647, 0,-2147483647], [ 0, 1, 0], [-2147483647, 0,-2147483647]]) if r==1: return b1 else: return iasedil( iasedil(y,iasesum(b1,r/2)) ,iasesum(b2,(r+1)/2)) elif METRIC == 'EUCLIDEAN': v = arange(-r,r+1) x = resize(v, (len(v), len(v))) y = transpose(x) Be = iabinary(sqrt(x*x + y*y) <= (r+0.5)) if FLAT=='FLAT': return Be be = h + int32( sqrt( maximum((r+0.5)*(r+0.5) - (x*x) - (y*y),0))) be = iaintersec( iagray(Be,'int32'),be) return be else: assert 0,'Non valid metric' return B
def iasedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0): from iabinary import iabinary from iasecross import iasecross from iasedil import iasedil from iasesum import iasesum from iasebox import iasebox from iaintersec import iaintersec from iagray import iagray METRIC = METRIC.upper() FLAT = FLAT.upper() assert DIM == '2D', 'Supports only 2D structuring elements' if FLAT == 'FLAT': y = iabinary([1]) else: y = int32([h]) if r == 0: return y if METRIC == 'CITY-BLOCK': if FLAT == 'FLAT': b = iasecross(1) else: b = int32([[-2147483647, 0, -2147483647], [0, 1, 0], [-2147483647, 0, -2147483647]]) return iasedil(y, iasesum(b, r)) elif METRIC == 'CHESSBOARD': if FLAT == 'FLAT': b = iasebox(1) else: b = int32([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) return iasedil(y, iasesum(b, r)) elif METRIC == 'OCTAGON': if FLAT == 'FLAT': b1, b2 = iasebox(1), iasecross(1) else: b1 = int32([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) b2 = int32([[-2147483647, 0, -2147483647], [0, 1, 0], [-2147483647, 0, -2147483647]]) if r == 1: return b1 else: return iasedil(iasedil(y, iasesum(b1, r / 2)), iasesum(b2, (r + 1) / 2)) elif METRIC == 'EUCLIDEAN': v = arange(-r, r + 1) x = resize(v, (len(v), len(v))) y = transpose(x) Be = iabinary(sqrt(x * x + y * y) <= (r + 0.5)) if FLAT == 'FLAT': return Be be = h + int32( sqrt(maximum((r + 0.5) * (r + 0.5) - (x * x) - (y * y), 0))) be = iaintersec(iagray(Be, 'int32'), be) return be else: assert 0, 'Non valid metric' return B
def iasupgen(f, INTER): from iaintersec import iaintersec from iaero import iaero from ianeg import ianeg A,Bc = INTER y = iaintersec( iaero( f, A), iaero( ianeg(f), Bc)) return y
def iacmp(f1, oper, f2, oper1=None, f3=None): from iaintersec import iaintersec from iabinary import iabinary if oper == '==': y = (f1==f2) elif oper == '~=': y = (f1!=f2) elif oper == '<=': y = (f1<=f2) elif oper == '>=': y = (f1>=f2) elif oper == '>': y = (f1> f2) elif oper == '<': y = (f1< f2) else: assert 0, 'oper must be one of: ==, ~=, >, >=, <, <=, it was:'+oper if oper1 != None: if oper1 == '==': y = iaintersec(y, f2==f3) elif oper1 == '~=': y = iaintersec(y, f2!=f3) elif oper1 == '<=': y = iaintersec(y, f2<=f3) elif oper1 == '>=': y = iaintersec(y, f2>=f3) elif oper1 == '>': y = iaintersec(y, f2> f3) elif oper1 == '<': y = iaintersec(y, f2< f3) else: assert 0, 'oper1 must be one of: ==, ~=, >, >=, <, <=, it was:'+oper1 y = iabinary(y) return y
def iainfcanon(f, Iab, theta=45, DIRECTION="CLOCKWISE"): from iaunion import iaunion from iainterot import iainterot from iaintersec import iaintersec from iainfgen import iainfgen DIRECTION = DIRECTION.upper() y = iaunion(f, 1) for t in range(0, 360, theta): Irot = iainterot(Iab, t, DIRECTION) y = iaintersec(y, iainfgen(f, Irot)) return y
def iainfcanon(f, Iab, theta=45, DIRECTION="CLOCKWISE"): from iaunion import iaunion from iainterot import iainterot from iaintersec import iaintersec from iainfgen import iainfgen DIRECTION = upper(DIRECTION) y = iaunion(f,1) for t in range(0,360,theta): Irot = iainterot( Iab, t, DIRECTION ) y = iaintersec( y, iainfgen(f, Irot)) return y
def iaskelmrec(f, B=None): from iabinary import iabinary from iaintersec import iaintersec from iadil import iadil from iaunion import iaunion from iasecross import iasecross if B is None: B = iasecross(None) y = iabinary( iaintersec(f, 0)) for r in range(max(ravel(f)),1,-1): y = iadil( iaunion(y,iabinary(f,r)), B) y = iaunion(y, iabinary(f,1)) return y
def iaframe(f, WT=1, HT=1, DT=0, k1=None, k2=None): from iaunion import iaunion from iaintersec import iaintersec from ialimits import ialimits if k1 is None: k1 = ialimits(f)[1] if k2 is None: k2 = ialimits(f)[0] assert len(f.shape)==2,'Supports 2D only' y = iaintersec(f,k2) y[:,0:WT] = k1 y[:,-WT:] = k1 y[0:HT,:] = k1 y[-HT:,:] = k1 return y
def iaframe(f, WT=1, HT=1, DT=0, k1=None, k2=None): from iaunion import iaunion from iaintersec import iaintersec from ialimits import ialimits if k1 is None: k1 = ialimits(f)[1] if k2 is None: k2 = ialimits(f)[0] assert len(f.shape) == 2, 'Supports 2D only' y = iaintersec(f, k2) y[:, 0:WT] = k1 y[:, -WT:] = k1 y[0:HT, :] = k1 y[-HT:, :] = k1 return y
def iaskelmrec(f, B=None): from iabinary import iabinary from iaintersec import iaintersec from iadil import iadil from iaunion import iaunion from iasecross import iasecross if B is None: B = iasecross(None) y = iabinary(iaintersec(f, 0)) for r in range(max(ravel(f)), 1, -1): y = iadil(iaunion(y, iabinary(f, r)), B) y = iaunion(y, iabinary(f, 1)) return y
def iainpos(f, g, bc=iasecross()): from iaisbinary import iaisbinary from iagray import iagray from ianeg import ianeg from iadatatype import iadatatype from ialimits import ialimits from iasuprec import iasuprec from iaintersec import iaintersec from iaunion import iaunion assert iaisbinary(f), 'First parameter must be binary image' fg = iagray(ianeg(f), iadatatype(g)) k1 = ialimits(g)[1] - 1 y = iasuprec(fg, iaintersec(iaunion(g, 1), k1, fg), bc) return y
def iainpos(f, g, bc=iasecross()): from iaisbinary import iaisbinary from iagray import iagray from ianeg import ianeg from iadatatype import iadatatype from ialimits import ialimits from iasuprec import iasuprec from iaintersec import iaintersec from iaunion import iaunion assert iaisbinary(f),'First parameter must be binary image' fg = iagray( ianeg(f), iadatatype(g)) k1 = ialimits(g)[1] - 1 y = iasuprec(fg, iaintersec( iaunion(g, 1), k1, fg), bc) return y
def iacbisector(f, B, n): from iaintersec import iaintersec from iasesum import iasesum from iaero import iaero from iacdil import iacdil from iasubm import iasubm from iaunion import iaunion y = iaintersec(f,0) for i in range(n): nb = iasesum(B,i) nbp = iasesum(B,i+1) f1 = iaero(f,nbp) f2 = iacdil(f1,f,B,n) f3 = iasubm( iaero(f,nb),f2) y = iaunion(y,f3) return y
def iacbisector(f, B, n): from iaintersec import iaintersec from iasesum import iasesum from iaero import iaero from iacdil import iacdil from iasubm import iasubm from iaunion import iaunion y = iaintersec(f, 0) for i in range(n): nb = iasesum(B, i) nbp = iasesum(B, i + 1) f1 = iaero(f, nbp) f2 = iacdil(f1, f, B, n) f3 = iasubm(iaero(f, nb), f2) y = iaunion(y, f3) return y
def iacenter(f, b=None): from iaasf import iaasf from iaunion import iaunion from iaintersec import iaintersec from iaisequal import iaisequal from iasecross import iasecross if b is None: b = iasecross(None) y = f diff = 0 while not diff: aux = y beta1 = iaasf(y,'COC',b,1) beta2 = iaasf(y,'OCO',b,1) y = iaunion( iaintersec(y,beta1),beta2) diff = iaisequal(aux,y) return y
def iacenter(f, b=None): from iaasf import iaasf from iaunion import iaunion from iaintersec import iaintersec from iaisequal import iaisequal from iasecross import iasecross if b is None: b = iasecross(None) y = f diff = 0 while not diff: aux = y beta1 = iaasf(y, 'COC', b, 1) beta2 = iaasf(y, 'OCO', b, 1) y = iaunion(iaintersec(y, beta1), beta2) diff = iaisequal(aux, y) return y
def iaintershow(Iab): from iaseunion import iaseunion from iaintersec import iaintersec assert (type(Iab) is tuple) and (len(Iab) == 2),'not proper fortmat of hit-or-miss template' A,Bc = Iab S = iaseunion(A,Bc) Z = iaintersec(S,0) n = product(S.shape) one = reshape(array(n*'1','c'),S.shape) zero = reshape(array(n*'0','c'),S.shape) x = reshape(array(n*'.','c'),S.shape) saux = choose( S + iaseunion(Z,A), ( x, zero, one)) s = '' for i in range(saux.shape[0]): s=s+(join(list(saux[i]))+' \n') return s
def iagdist(f, g, Bc=iasecross(), METRIC=None): from ianeg import ianeg from iagray import iagray from iaintersec import iaintersec from iaisequal import iaisequal from iacero import iacero from iaaddm import iaaddm from iaunion import iaunion assert METRIC is None, 'Does not support EUCLIDEAN' fneg, gneg = ianeg(f), ianeg(g) y = iagray(gneg, 'uint16', 1) ero = iaintersec(y, 0) aux = y i = 1 while (ero != aux).any(): aux = ero ero = iacero(gneg, fneg, Bc, i) y = iaaddm(y, iagray(ero, 'uint16', 1)) i = i + 1 y = iaunion(y, iagray(ero, 'uint16')) return y
def iagdist(f, g, Bc=iasecross(), METRIC=None): from ianeg import ianeg from iagray import iagray from iaintersec import iaintersec from iaisequal import iaisequal from iacero import iacero from iaaddm import iaaddm from iaunion import iaunion assert METRIC is None,'Does not support EUCLIDEAN' fneg,gneg = ianeg(f),ianeg(g) y = iagray(gneg,'uint16',1) ero = iaintersec(y,0) aux = y i = 1 while (ero != aux).any(): aux = ero ero = iacero(gneg,fneg,Bc,i) y = iaaddm(y,iagray(ero,'uint16',1)) i = i + 1 y = iaunion(y,iagray(ero,'uint16')) return y
def iacthick(f, g, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"): from iaisbinary import iaisbinary from iasupgen import iasupgen from iainterot import iainterot from iaintersec import iaintersec from iaunion import iaunion from iaisequal import iaisequal from iahomothick import iahomothick if Iab is None: Iab = iahomothick() DIRECTION = upper(DIRECTION) assert iaisbinary(f),'f must be binary image' if n == -1: n = product(f.shape) y = f old = y for i in range(n): for t in range(0,360,theta): sup = iasupgen( y, iainterot(Iab, t, DIRECTION)) y = iaintersec( iaunion( y, sup),g) if iaisequal(old,y): break old = y return y
def iacthick(f, g, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"): from iaisbinary import iaisbinary from iasupgen import iasupgen from iainterot import iainterot from iaintersec import iaintersec from iaunion import iaunion from iaisequal import iaisequal from iahomothick import iahomothick if Iab is None: Iab = iahomothick() DIRECTION = DIRECTION.upper() assert iaisbinary(f), 'f must be binary image' if n == -1: n = product(f.shape) y = f old = y for i in range(n): for t in range(0, 360, theta): sup = iasupgen(y, iainterot(Iab, t, DIRECTION)) y = iaintersec(iaunion(y, sup), g) if iaisequal(old, y): break old = y return y