[Up] [hoeq1s1] Chapter 1 - Binary Erosion and Dilation

hofig1s1a
Probing an image

Description

This figure illustrates the principle of fitting.

Demo Script

Image reading and structuring element creation

The binary image to be processed is read. The structuring element is created from box of radius 25.

from morph import *
from handson import *
F=mmreadgray('blob_1.tif')
print 'The pixel datatype of image F is ',mmdatatype(F)
The pixel datatype of image F is  binary
mmshow(F)
B=mmsebox(25)
mmshow(mmseshow(B))
F mmseshow(B)

Translating the structuring element in two places

An image of two points to translate the structuring element is created. The 3x3 elementary cross is placed on these points to mark them more clearly. Then this image with the two points is dilated by the structuring element.

Z=mmsubm(F,F)
Z[80,120]=1; Z[160,240]=1
Z1=mmdil(Z)
mmshow(Z1)
Z2=mmdil(Z,B)
mmshow(Z2)
Z1 Z2

Combine both and compute their edges

A symmetrical difference can show simultaneously the image with points and the image with the translated structuring elements. The edges of this image shows the contour of the structuring elements.

T=mmsymdif(Z2,Z1)
mmshow(T)
E=mmgradm(T) # edges
mmshow(E)
T E

Final display

The original image and the edges of the translated structuring elements are combined using their symmetrical difference.

G=mmsymdif(F,E)
mmshow(G)
G

Alternative display in color

A simpler illustration can be computed using the color overlay facility of mmshow.

mmshow(F,Z2,Z1)
F,Z2,Z1

[Up] [hoeq1s1] http://www.python.org