Attribute filtering vs Spatial filtering

MainPage

 1 from iamxt import MaxTreeAlpha
 2 import numpy as np
 3 import ia870
 4 import ia636
 5 from scipy.ndimage.filters import convolve, median_filter
 6 import time
 7 from iamxt.ssim_index import  SSIMIndex
 8 
 9 #img = adreadgray(find_attachment_file('homeroberto/carotid_demo/carotid_slice.png'))
10 img = adreadgray(find_attachment_file('iamxt/conv_attribute_filtering/ct.png'))
11 img = adreadgray(find_attachment_file('ct.png'))
12 Bc = np.ones((3,3),dtype = bool)
13 fz = np.unique(mmlabelflat(img)).size
14 
15 adshow(img, "Original Image")
16 F = ia636.iadft(img)
17 adshow(ia636.iadftview(F),'Original image Fourier Spectrum')
18 
19 mask = np.ones((7,7))
20 filtered_img = convolve(img.astype(float),mask,mode = 'wrap')
21 filtered_img = ia636.ianormalize(filtered_img)
22 fz2 = np.unique(mmlabelflat(filtered_img)).size
23 adshow(filtered_img,'Mean filter 7x7 mask')
24 #F2 = ia636.iadft(filtered_img)
25 #adshow(ia636.iadftview(F2), 'Mean Filter Fourier Spectrum')
26 
27 
28 
29 
30 filtered_img2 = median_filter(img.astype(float),footprint = mask,mode = 'wrap')
31 filtered_img2 = ia636.ianormalize(filtered_img2)
32 fz3 = np.unique(mmlabelflat(filtered_img2)).size
33 adshow(filtered_img,'Median filter 7x7 mask')
34 #F3 = ia636.iadft(filtered_img2)
35 #adshow(ia636.iadftview(F3),'Median Filter Fourier Spectrum')
36 
37 
38 
39 #mxt = MaxTreeAlpha(img.max()-img,Bc)
40 mxt = MaxTreeAlpha(img,Bc)
41 mxt.areaOpen(50)
42 #area_open = img.max() - mxt.getImage()
43 area_open = mxt.getImage()
44 
45 mxt = MaxTreeAlpha(area_open,Bc)
46 mxt.areaOpen(50)
47 area_open = mxt.getImage()
48 fz4 = np.unique(mmlabelflat(area_open)).size
49 adshow(area_open, 'Area-open - 25')
50 F4 = ia636.iadft(area_open)
51 adshow(ia636.iadftview(F4),'Area-open Fourier Spectrum')
52 
53 adshow(ia636.iadftview(F-F4),'Area-open Fourier Spectrum')
54 
55 print "Flat-zones"
56 print 'Mean: %f' %(1.0*fz2/fz)
57 print 'Median: %f' %(1.0*fz3/fz)
58 print 'Area-open: %f' %(1.0*fz4/fz)
59 print
60 print "SSIM"
61 print 'Mean: %f' %SSIMIndex(img,filtered_img)
62 print 'Median: %f' %SSIMIndex(img,filtered_img2)
63 print 'Area-open: %f' %SSIMIndex(img,area_open)
Warning: downcasting image from double to uint16 (may lose precision)
Warning: downcasting image from double to uint16 (may lose precision)
Flat-zones
Mean: 0.470729
Median: 0.261070
Area-open: 0.720991

SSIM
Mean: 0.878090
Median: 0.902044
Area-open: 0.995860

Original Image

Original image Fourier Spectrum

Mean filter 7x7 mask

Median filter 7x7 mask

Area-open - 25

Area-open Fourier Spectrum

Area-open Fourier Spectrum