back to iatexture

Texture maps

01. #:xsandbox_key: xsb_mmorph_3
02. 
03. from iatexture import *
04. import ia870
05. import time
06. import ia636
07. import numpy as np
08. from ia636 import iaotsu
09. from homemariana.identWMH import iacrop2
10. 
11. img = adreadgray('p/LesionMRI/EM/Adriana A da Fonseca - 324575-6 - 19A/20.png')
12. roi = adreadgray('p/LesionMRI/EM/Adriana A da Fonseca - 324575-6 - 19A/Peri_20_1.png')>0
13. 
14. (t, eta) = iaotsu(img)
15. g,row,col = iacrop2(img>t)
16. img = (img[row[0]:row[-1]+1, col[0]:col[-1]+1])
17. roi = roi[row[0]:row[-1]+1, col[0]:col[-1]+1]
18. 
19. aux = ia870.ialabel(roi)
20. aux = ia870.iablob(aux,'area')
21. roiTrue = aux>aux.max()-1 # ensure that it is only one lesion, use the biggest blob, avoid manual segmentation mistakes.
22. 
23. rate = 4
24. 
25. adshow(img,'img')
26. adshow(ia870.iagshow(img,roiTrue),'roi')
27. 
28. 
29. # retalhar a imagem em retangulos
30. sizex = 7
31. sizey = 7
32. 
33. (x, y) = ia636.iameshgrid(arange(0,img.shape[0],sizex), arange(0,img.shape[1],sizey))
34. grid = np.zeros(img.shape, dtype = bool)
35. grid[x,:] = 1
36. grid[:,y] = 1
37. adshow(ia870.iagshow(img,grid),'ROIs')
38. 
39. x = x[0,:]
40. y= y[:,0]
41. 
42. mask = np.zeros(img.shape, dtype = float)
43. maskC = np.zeros(img.shape, dtype = float)
44. maskE = np.zeros(img.shape, dtype = float)
45. print mask.shape
46. imgquant = quantimg(img,rate)
47. t1 = time.time()
48. for i in arange(100,160):#arange(3,img.shape[0]-4):
49.     for j in arange(50,120):#arange(3,img.shape[1]-4):
50.         f = img.copy()
51.         r = zeros_like(img).astype(bool)
52.         r[i-3:i+3,j-3:j+3] =1
53.         bb = ia870.iablob(r,'boundingbox','data')[0]
54.         bb = bb+[-3,-3,+3,+3]
55.         f = f[bb[1]:bb[3],bb[0]:bb[2]]
56.         r = r[bb[1]:bb[3],bb[0]:bb[2]]
57.         _,att0 = glcmdesc(f,offset = np.array([0,3],dtype=np.int32),mask =r)# d=3, q = 0
58.         _,att90 = glcmdesc(f,offset = np.array([3,0],dtype=np.int32),mask =r)# d=3, q = 90
59.         _,att45 = glcmdesc(f,offset = np.array([3,-3],dtype=np.int32),mask =r)# d=3, q = 45
60.         _,att135 = glcmdesc(f,offset = np.array([3,3],dtype=np.int32),mask =r)# d=3, q = 135
61.         mask[i,j] = (att0[0]+att90[0]+att45[0]+att135[0])/4
62.         maskC[i,j] = (att0[1]+att90[1]+att45[1]+att135[1])/4
63.         maskE[i,j] = (att0[9]+att90[9]+att45[9]+att135[9])/4
64. adshow(ia636.ianormalize(mask),'texture maps GLCM-Angular second moment')
65. adshow(ia636.ianormalize(maskC),'texture maps GLCM-Contrast')
66. adshow(ia636.ianormalize(maskE),'texture maps GLCM-Entropy')
67. print 'processing time',time.time()-t1
(212, 173)
processing time 849.411823988

img

roi

ROIs

texture maps GLCM-Angular second moment

texture maps GLCM-Contrast

texture maps GLCM-Entropy