Function iaasf

namespace:morph
page:iaasf

Synopse

Alternating Sequential Filtering

  • y = iaasf(f, SEQ="OC", b=ia_secross(NULL), n=1)
    • y: Image
    • f: Image
    • SEQ: String 'OC', 'CO', 'OCO', 'COC'.
    • b: Structuring Element
    • n: Double (number of iterations).
01. from numpy import *
02. from string import upper
03. 
04. def iaasf(f, SEQ="OC", b=None, n=1):
05.     from iasesum import iasesum
06.     from iaopen import iaopen
07.     from iaclose import iaclose
08.     from iasecross import iasecross
09.     if b is None:
10.         b = iasecross(None)
11. 
12.     SEQ=upper(SEQ)
13.     y = f
14.     if SEQ == 'OC':
15.         for i in range(1,n+1):
16.             nb = iasesum(b,i)
17.             y = iaopen( iaclose(y,nb),nb)
18.     elif SEQ == 'CO':
19.         for i in range(1,n+1):
20.             nb = iasesum(b,i)
21.             y = iaclose( iaopen(y,nb),nb)
22.     elif SEQ == 'OCO':
23.         for i in range(1,n+1):
24.             nb = iasesum(b,i)
25.             y = iaopen( iaclose( iaopen(y,nb),nb),nb)
26.     elif SEQ == 'COC':
27.         for i in range(1,n+1):
28.             nb = iasesum(b,i)
29.             y = iaclose( iaopen( iaclose(y,nb),nb),nb)
30. 
31.     return y

Description

iaasf creates the image y by filtering the image f by n iterations of the close and open alternating sequential filter characterized by the structuring element b. The sequence of opening and closing is controlled by the parameter SEQ. 'OC' performs opening after closing, 'CO' performs closing after opening, 'OCO' performs opening after closing after opening, and 'COC' performs closing after opening after closing.

Examples

Example 1

1. from ia870 import iaasf
2. from ia870 import iasecross
3. 
4. 
5. f=mmreadgray('gear.tif')
6. g=iaasf(f,'oc',iasecross(),2)
7. mmshow(f)
8. mmshow(g)

Example 2

1. f=mmreadgray('fabric.tif')
2. g=iaasf(f,'oc',iasecross(),3)
3. mmshow(f)
4. mmshow(g)

Equation

Algorithm

function y=iaasf_equ( f, SEQ, b, n )
switch SEQ
case 'OC',
   y = f;
   for i=1:n
      nb = iasesum(b,i);
      y = iaclose(y,nb);
      y = iaopen(y,nb);
   end;
case 'CO',
   y = f;
   for i=1:n
      nb = iasesum(b,i);
      y = iaopen(y,nb);
      y = iaclose(y,nb);
   end;
case 'OCO',
   y = f;
   for i=1:n
      nb = iasesum(b,i);
      y = iaopen(y,nb);
      y = iaclose(y,nb);
      y = iaopen(y,nb);
   end;
case 'COC',
   y = f;
   for i=1:n
      nb = iasesum(b,i);
      y = iaclose(y,nb);
      y = iaopen(y,nb);
      y = iaclose(y,nb);
   end;
end;