[hofig4s1] [Up] [hofig4s3] Chapter 4 - Hit-or-Miss Transform

hofig4s2
Recognition of noisy object

Description

This figure illustrates the recognition of a noisy object using the hit-or-miss transform.

Demo Script

.

from morph import *
from handson import mmbggmodel
from Numeric import zeros, array, shape
Z=mmbinary(zeros((100,100)))
A=array(Z); A[19:80,34:65]=1
B=array(Z); B[24:75,24:75]=1
C=array(B); C[14:30,39:60]=1
F=mmconcat('W',A,B,C)
hit=array(B)
miss=mmgradm(B,mmsebox(2),mmsebox(0))
b1=mmimg2se(hit)
b2=mmimg2se(miss)
I=mmse2hmt(b1,b2)
G=mmsupgen(F,I)
p=mmgray(mmunion(hit,1),'uint8',128)
Warning: Converting input image from int32 to binary uint8.
T=mmintersec(mmunion(mmgray(hit),p),mmneg(mmgray(miss)))
Na=mmbggmodel(shape(F),mmsecross(),2,0.05)
Ns=mmneg(mmbggmodel(shape(F),mmsecross(),2,0.05))
Fn=mmareaclose(mmdil(mmareaopen(mmintersec(mmunion(F,Na),Ns),100)),20)
hit_n=mmero(hit,mmsebox(4))
b1n=mmimg2se(hit_n)
miss_n = mmgradm( mmdil(hit,mmsebox(4)), mmsebox(2),mmsebox(0))
b2n=mmimg2se(miss_n)
In=mmse2hmt(b1n,b2n)
Gn=mmsupgen(Fn,In)
Tn=mmintersec(mmunion(mmgray(hit_n),p),mmneg(mmgray(miss_n)))
H=mmconcat('W',F, Fn)
G1=mmsupgen(H,I)
G2=mmsupgen(H,In)
fig_a = H
fig_b = T
fig_c = mmdil(G1,mmsebox())
fig_d = Tn
fig_e = mmdil(G2,mmsebox())
mmshow(fig_a)
mmshow(fig_b)
mmshow(fig_c)
mmshow(fig_d)
mmshow(fig_e)
fig_a fig_b
fig_c fig_d
fig_e

[hofig4s1] [Up] [hofig4s3] http://www.python.org