In [173]:
# 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 [243]:
# define default common used variables
output_dir = "./output"
input_dir = './data'
cmap = plt.get_cmap('jet')
cluster_file = 'cluster_shade_img_w25d1_iso_glcm_mosaic2.png'
contrast_file = 'contrast_img_w25d1_iso_glcm_mosaic2.png'
homogen_file = 'homogeneity_img_w25d1_iso_glcm_mosaic2.png'
th_m11 = {
'contrast': [30, 150],
'homogeneity': [35, 160],
'cluster_shade': [135, 230]
}
feature_imgs = {}
In [244]:
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 [245]:
masks = {}
th_m11 = {
'contrast': [20, 150],
'homogeneity': [20, 170],
'cluster_shade': [110, 230]
}
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 [246]:
for feature_name in th_m11.keys():
plt.figure()
plt.imshow(masks[feature_name],'gray')
plt.show()
In [247]:
image1 = 'mosaic2.png'
img = cv2.imread(os.path.join(input_dir, image1),
cv2.IMREAD_GRAYSCALE)
masked_img = img.copy()
for feature_name in th_m11.keys():
masked_img *= masks[feature_name]
plt.imshow(masked_img,'gray')
plt.show()
In [240]:
cluster_file = 'cluster_shade_img_w25d1_0_angle_mosaic2.png'
contrast_file = 'contrast_img_w25d1_0_angle_mosaic2.png'
homogen_file = 'homogeneity_img_w25d1_0_angle_mosaic2.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 [241]:
masks = {}
th_m11 = {
'contrast': [0, 50],
'homogeneity': [100, 170],
'cluster_shade': [110, 230]
}
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 [242]:
masked_img = img.copy()
for feature_name in th_m11.keys():
masked_img *= masks[feature_name]
plt.imshow(masked_img,'gray')
plt.show()
In [ ]:
In [ ]:
In [ ]:
In [ ]: