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)
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])
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())
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])
In [ ]: