Simple Filtering Example

MainPage

This example illustrates the use of an area-open filter to remove pepper noise

 1 import numpy as np
 2 import iamxt
 3 
 4 img = adreadgray(find_attachment_file('apple.png'))
 5 
 6 adshow(img, "Noisy image")
 7 
 8 #Connectivity-8
 9 Bc = np.ones((3,3),dtype = bool)
10 
11 #Negating the image
12 img_max = img.max()
13 neg_img = img_max - img
14 
15 # Building the max-tree of the negated image, i.e. min-tree
16 mxt = iamxt.MaxTreeAlpha(neg_img,Bc)
17 
18 
19 #Filtering the min-tree
20 a = 50
21 mxt.areaOpen(a)
22 img_filtered = img_max - mxt.getImage()
23 
24 adshow(img_filtered,"Filtered image - area-open a = %d" %a)

Noisy image

Filtered image - area-open a = 50