back to iatexture

Extraction of texture attributes on a 3d image

 1 t1 = t = time.time()
 2 
 3 import glob, urllib, os
 4 from toolbox.fattach import find_attachment_files
 5 import numpy as np
 6 from ia636 import ianormalize, iamosaic, iagshow,iaotsu
 7 from homemariana.identWMH import iacrop2
 8 
 9 foldername = '/awmedia/www/media/p/LesionMRI/CAINdata/Original_Data/CAIN10176001/BASELINE - CAIN1/AX_T2_FLAIR_HEAD_4/*'
10 wmlfoldername = '/awmedia/www/media/p/LesionMRI/CAINdata/WML Masks/0176/001/BASELINE/DICOM/*'
11 folder = glob.glob(foldername)
12 folder.sort()
13 
14 folderWML = glob.glob(wmlfoldername)
15 folderWML.sort()
16 
17 print len(folder)
18 print len(folderWML)
19 img = zeros((len(folder),256,256),dtype=int32)
20 r = zeros((len(folderWML),256,256),dtype=bool)
21 
22 if len(folder) == len(folderWML):
23 
24     for i in arange(len(folder)):
25         orig = dicom.read_file(find_attachment_file(folder[i]))
26         img[i] = orig.pixel_array.astype(int32)
27 
28 
29         mask = dicom.read_file(find_attachment_file(folderWML[i]))
30         mask = mask.pixel_array.astype(bool)
31         r[i] = mask
32 print 'time to read images', time.time()-t1
48
48
time to read images 0.736618995667

Compute texture descriptors

 1 from iatexture import *
 2 import time
 3 import numpy as np
 4 from ia636 import ianormalize
 5 import morph
 6 
 7 
 8 
 9 print 'img.shape:',img.shape
10 print 'roi.shape:',r.shape
11 
12 
13 for i in xrange(img.shape[0]):
14     adshow(iagshow(ianormalize(img[i]),r[i]>0),'img[%d],mask[%d]'%(i+1,i+1))
15 t1 = time.time()
16 print 'texture descriptors\n', textpipe(img,roi = r>0,rate=3,comp=1)
17 print 'texture analysis time=',time.time()-t1
18 t1 = time.time()
19 print 'texture descriptors\n', textpipe(img,roi = r>0,rate=3,comp=1,bb_use=0)#without using bb
20 print 'texture analysis time without using bb=',time.time()-t1
img.shape: (48, 256, 256)
roi.shape: (48, 256, 256)
texture descriptors
[  3.91910651e+01   2.82633859e+01   1.16289875e+00   2.80649386e+00
   3.10000000e+01   3.30000000e+01   3.80000000e+01   4.60000000e+01
   5.50000000e+01   1.29265319e+00   3.60000000e+01   3.80000000e+01
   3.76247180e-03   3.79812589e+01   4.48479179e-01   3.43645276e+01
   2.18435606e-01   8.33350348e+01   9.68363145e+01   1.57477360e+00
   2.54477011e+00   1.56958386e+01   1.10329107e+00   3.68565197e-03
   5.15347901e+01   3.07965010e-01   3.75075601e+01   1.90454204e-01
   8.37500343e+01   9.56209360e+01   1.57129930e+00   2.54238370e+00
   2.13067139e+01   1.17753200e+00   3.99392730e-03   6.05859778e+01
   2.07556471e-01   3.92844905e+01   1.77955427e-01   8.34057281e+01
   9.03942382e+01   1.55498727e+00   2.49868895e+00   2.57995617e+01
   1.20755568e+00   5.67183596e+03   3.74558427e+02   1.15376561e+00
   9.66374749e-01   9.54992449e-01   1.34361228e+01   5.22015974e+01
   9.63102584e-01   1.48673732e+00   1.00000000e+00]
texture analysis time= 5.00299096107
texture descriptors
[  3.91910651e+01   2.82633859e+01   1.16289875e+00   2.80649386e+00
   3.10000000e+01   3.30000000e+01   3.80000000e+01   4.60000000e+01
   5.50000000e+01   1.29265319e+00   3.60000000e+01   3.80000000e+01
   3.76247180e-03   3.79812589e+01   4.48479179e-01   3.43645276e+01
   2.18435606e-01   8.33350348e+01   9.68363145e+01   1.57477360e+00
   2.54477011e+00   1.56958386e+01   1.10329107e+00   3.68565197e-03
   5.15347901e+01   3.07965010e-01   3.75075601e+01   1.90454204e-01
   8.37500343e+01   9.56209360e+01   1.57129930e+00   2.54238370e+00
   2.13067139e+01   1.17753200e+00   3.99392730e-03   6.05859778e+01
   2.07556471e-01   3.92844905e+01   1.77955427e-01   8.34057281e+01
   9.03942382e+01   1.55498727e+00   2.49868895e+00   2.57995617e+01
   1.20755568e+00   5.67183596e+03   3.74558427e+02   1.15376561e+00
   9.66374749e-01   9.54992449e-01   1.34361228e+01   5.22015974e+01
   9.63102584e-01   1.48673732e+00   1.00000000e+00]
texture analysis time without using bb= 12.7304241657

img[1],mask[1]

img[2],mask[2]

img[3],mask[3]

img[4],mask[4]

img[5],mask[5]

img[6],mask[6]

img[7],mask[7]

img[8],mask[8]

img[9],mask[9]

img[10],mask[10]

img[11],mask[11]

img[12],mask[12]

img[13],mask[13]

img[14],mask[14]

img[15],mask[15]

img[16],mask[16]

img[17],mask[17]

img[18],mask[18]

img[19],mask[19]

img[20],mask[20]

img[21],mask[21]

img[22],mask[22]

img[23],mask[23]

img[24],mask[24]

img[25],mask[25]

img[26],mask[26]

img[27],mask[27]

img[28],mask[28]

img[29],mask[29]

img[30],mask[30]

img[31],mask[31]

img[32],mask[32]

img[33],mask[33]

img[34],mask[34]

img[35],mask[35]

img[36],mask[36]

img[37],mask[37]

img[38],mask[38]

img[39],mask[39]

img[40],mask[40]

img[41],mask[41]

img[42],mask[42]

img[43],mask[43]

img[44],mask[44]

img[45],mask[45]

img[46],mask[46]

img[47],mask[47]

img[48],mask[48]

CAIN patient 320001

 1 t1 = t = time.time()
 2 
 3 import glob, urllib, os
 4 from toolbox.fattach import find_attachment_files
 5 import numpy as np
 6 from ia636 import ianormalize, iamosaic, iagshow,iaotsu
 7 from homemariana.identWMH import iacrop2
 8 
 9 foldername = '/awmedia/www/media/p/LesionMRI/CAINdata/Original_Data/CAIN10320001/BASELINE - CAIN1/FLAIR_LongTR_601/*'
10 wmlfoldername = '/awmedia/www/media/p/LesionMRI/CAINdata/WML Masks/0320/001/BASELINE/DICOM/*'
11 
12 folder = glob.glob(foldername)
13 folder.sort()
14 
15 folderWML = glob.glob(wmlfoldername)
16 folderWML.sort()
17 
18 print len(folder)
19 print len(folderWML)
20 img = zeros((len(folder),560,560),dtype=int32)
21 r = zeros((len(folderWML),560,560),dtype=bool)
22 
23 if len(folder) == len(folderWML):
24 
25     for i in arange(len(folder)):
26         orig = dicom.read_file(find_attachment_file(folder[i]))
27         img[i] = orig.pixel_array.astype(int32)
28 
29         mask = dicom.read_file(find_attachment_file(folderWML[i]))
30         mask = mask.pixel_array.astype(bool)
31         r[i] = mask
32 print 'time to read images', time.time()-t1
50
50
time to read images 0.749149084091

Compute texture descriptors

 1 from iatexture import *
 2 import time
 3 import numpy as np
 4 
 5 #for i in xrange(img.shape[0]):
 6 #    adshow(iagshow(ianormalize(img[i]),r[i]>0),'img[%d],mask[%d]'%(i+1,i+1))
 7 
 8 print 'img.shape:',img.shape
 9 print 'roi.shape:',r.shape
10 t1 = time.time()
11 print 'texture descriptors\n', textpipe(img,roi = r>0,rate=5,comp=1)
12 print 'texture analysis time=',time.time()-t1
13 t1 = time.time()
14 print 'texture descriptors\n', textpipe(img,roi = r>0,rate=5,comp=1,bb_use=0)
15 print 'texture analysis time without using bb:',time.time()-t1
img.shape: (50, 560, 560)
roi.shape: (50, 560, 560)
texture descriptors
[  4.90283589e+01   4.52088859e+01   2.42563981e-01  -8.09144408e-01
   3.70000000e+01   4.10000000e+01   4.80000000e+01   5.90000000e+01
   6.30000000e+01   1.42199702e+00   4.40000000e+01   4.80000000e+01
   2.96297490e-03   3.38551900e+01   6.22206171e-01   4.28667744e+01
   2.46913830e-01   1.03728865e+02   1.41908040e+02   1.67937165e+00
   2.64820848e+00   1.28448637e+01   1.04245592e+00   2.26337957e-03
   4.93051395e+01   4.67768174e-01   4.37888418e+01   1.85184291e-01
   1.04821464e+02   1.29793453e+02   1.66132583e+00   2.72696862e+00
   1.78521997e+01   1.14862407e+00   2.03930835e-03   6.05298271e+01
   3.52013841e-01   4.44917109e+01   1.61373738e-01   1.04654465e+02
   1.20678578e+02   1.64674410e+00   2.76234245e+00   2.13595252e+01
   1.19953650e+00   4.02038649e+04   1.89758678e+03   1.32457167e+00
   9.46560713e-01   9.23451642e-01   1.32522330e+01   6.32533215e+01
   7.94990085e-01   2.79424724e-01   9.99594507e-01]
texture analysis time= 10.520378828
texture descriptors
[  4.90283589e+01   4.52088859e+01   2.42563981e-01  -8.09144408e-01
   3.70000000e+01   4.10000000e+01   4.80000000e+01   5.90000000e+01
   6.30000000e+01   1.42199702e+00   4.40000000e+01   4.80000000e+01
   2.96297490e-03   3.38551900e+01   6.22206171e-01   4.28667744e+01
   2.46913830e-01   1.03728865e+02   1.41908040e+02   1.67937165e+00
   2.64820848e+00   1.28448637e+01   1.04245592e+00   2.26337957e-03
   4.93051395e+01   4.67768174e-01   4.37888418e+01   1.85184291e-01
   1.04821464e+02   1.29793453e+02   1.66132583e+00   2.72696862e+00
   1.78521997e+01   1.14862407e+00   2.03930835e-03   6.05298271e+01
   3.52013841e-01   4.44917109e+01   1.61373738e-01   1.04654465e+02
   1.20678578e+02   1.64674410e+00   2.76234245e+00   2.13595252e+01
   1.19953650e+00   4.02038649e+04   1.89758678e+03   1.32457167e+00
   9.46560713e-01   9.23451642e-01   1.32522330e+01   6.32533215e+01
   7.94990085e-01   2.79424724e-01   9.99594507e-01]
texture analysis time without using bb: 60.020498991