In [1]:
# Just for test some ideas

# Standard library imports
import os
import sys
import numpy as np
import time

# Third party imports
import matplotlib.pyplot as plt
import cv2

# Private libs
from glcm_texture import *

In [12]:
# define default common used variables
output_dir = "./output"
input_dir = './data'
cmap = plt.get_cmap('jet')

cluster_file = 'cluster_shade_img_w25d1_iso_glcm_mosaic1.png'
contrast_file = 'contrast_img_w25d1_iso_glcm_mosaic1.png'
homogen_file = 'homogeneity_img_w25d1_iso_glcm_mosaic1.png'

th_m11 = {
        'contrast':     [40, 220],
        'homogeneity':  [20, 100],
        'cluster_shade':[150, 250]
    }
feature_imgs = {}

In [22]:
feature_imgs['contrast'] = cv2.imread(os.path.join(output_dir, contrast_file),
                                      cv2.IMREAD_GRAYSCALE)
feature_imgs['homogeneity'] = cv2.imread(os.path.join(output_dir, homogen_file),
                                         cv2.IMREAD_GRAYSCALE)
feature_imgs['cluster_shade'] = cv2.imread(os.path.join(output_dir, cluster_file),
                                           cv2.IMREAD_GRAYSCALE)

In [75]:
masks = {}

th_m11 = {
        'contrast':     [40, 180],
        'homogeneity':  [40, 85],
        'cluster_shade':[120, 220]
    }

for feature_name in th_m11.keys():
    masks[feature_name] = mask_feature(feature_imgs[feature_name],
                                       th_m11[feature_name][0],
                                       th_m11[feature_name][1])

In [76]:
for feature_name in th_m11.keys():
    plt.figure()
    plt.imshow(masks[feature_name],'gray')

plt.show()



In [77]:
image1 = 'mosaic1.png'
img = cv2.imread(os.path.join(input_dir, image1),
                 cv2.IMREAD_GRAYSCALE)

In [79]:
masked_img = img.copy()
for feature_name in th_m11.keys():
    masked_img *= masks[feature_name]

In [81]:
plt.imshow(masked_img,'gray')
plt.show()



In [214]:
cluster_file = 'cluster_shade_img_w25d1_45_angle_mosaic1.png'
contrast_file = 'contrast_img_w25d1_45_angle_mosaic1.png'
homogen_file = 'homogeneity_img_w25d1_45_angle_mosaic1.png'

feature_imgs = {}

feature_imgs['contrast'] = cv2.imread(os.path.join(output_dir, contrast_file),
                                      cv2.IMREAD_GRAYSCALE)
feature_imgs['homogeneity'] = cv2.imread(os.path.join(output_dir, homogen_file),
                                         cv2.IMREAD_GRAYSCALE)
feature_imgs['cluster_shade'] = cv2.imread(os.path.join(output_dir, cluster_file),
                                           cv2.IMREAD_GRAYSCALE)

In [286]:
masks = {}

th_m11 = {
        'contrast': [60, 150],
        'homogeneity': [55, 120],
        'cluster_shade': [135, 250]
    }

for feature_name in th_m11.keys():
    masks[feature_name] = mask_feature(feature_imgs[feature_name],
                                       th_m11[feature_name][0],
                                       th_m11[feature_name][1])
    plt.figure()
    plt.imshow(masks[feature_name],'gray')

plt.show()



In [287]:
masked_img = img.copy()
for feature_name in th_m11.keys():
    masked_img *= masks[feature_name]
plt.imshow(masked_img,'gray')
plt.show()



In [288]:
img2 = img.copy()
print(img2.shape)


(512, 512)

In [289]:
img2 = img2[0:50,0:50]
plt.imshow(img2,'gray')
plt.show()



In [304]:
img2 = scale_image(img2,0,15)
glcm0 = get_glcm(win_image=img2,offsets=[1],
                 angles=[0], levels=16,symm=True, norm=True,
                 isotropic=False, weights=None)
glcm90 = get_glcm(win_image=img2,offsets=[1],
                 angles=[np.pi/2], levels=16,symm=True, norm=True,
                 isotropic=False, weights=None)
print(glcm0[0:3,0:3])
print(glcm90[0:3,0:3])


[[ 0.06612245  0.01979592  0.01285714]
 [ 0.01979592  0.01836735  0.01387755]
 [ 0.01285714  0.01387755  0.01836735]]
[[ 0.06408163  0.02285714  0.01285714]
 [ 0.02285714  0.01469388  0.0155102 ]
 [ 0.01285714  0.0155102   0.01510204]]

In [305]:
name = 'cluster_shade'
cluster1 = get_feature(glcm0,[name])[name]
cluster2 = get_feature(glcm90,[name])[name]

In [308]:
print(cluster1, cluster2)
print(img2.max())


148.593707475 130.624813811
15

In [310]:
f0= construct_texture_image(img2, 
                            win_order=3, 
                            feature='cluster_shade', 
                            offsets=[1], angles=[0],
                            fill_type='mirror', norm=True, symm=True, levels=16,
                            isotropic=False, weight=None,rescale=True)

In [311]:
f90= construct_texture_image(img2, 
                            win_order=3, 
                            feature='cluster_shade', 
                            offsets=[1], angles=[np.pi/2],
                            fill_type='mirror', norm=True, symm=True, levels=16,
                            isotropic=False, weight=None,rescale=True)

In [312]:
print(f0[0:5,0:5])
print(f90[0:5,0:5])


[[134 186 212 203 177]
 [134 186 212 203 177]
 [134 186 212 210 184]
 [130 160 185 216 208]
 [139 137 141 197 215]]
[[158 184 200 197 180]
 [158 184 212 201 183]
 [157 185 223 217 191]
 [124 127 183 212 201]
 [127 127 184 228 224]]

In [ ]: