Visit the wiki pages to find some additional documentation and instructions on how view an interactive verson of these notebooks using binder.

Function to extract features

In preparation to developing a classifier this script just tests which features could be used. In some sense this script is more for debugging than highlighting a specific algorithm.

In [1]:
import math
import numpy as np
import matplotlib.pyplot as plt

import skimage
from skimage import io, measure, exposure, filters
from skimage.color import rgba2rgb, rgb2gray
from sklearn.cluster import KMeans
from skimage.util import compare_images
from skimage.filters.rank import entropy
from skimage.feature import greycomatrix, greycoprops
from skimage.morphology import disk

from scipy.stats import entropy

import os
import csv

%matplotlib inline
In [2]:
def extract_features(image_input):
    gray =  rgb2gray(image_input)
    [counts, bins] = exposure.histogram(gray,nbins=8,source_range='dtype',normalize=True)
    v = counts.flatten()
    
 
    #fig, ax = plt.subplots(figsize=(12, 12))
    #plt.subplot(1,3,1)
    #plt.imshow(image_input)
    #plt.subplot(1,3,2)
    #plt.imshow(gray)
    
    gray_uint = (255*gray).astype(np.uint8)
    glcm = greycomatrix(gray_uint, distances=[5], angles=[0], levels=256,
                        symmetric=True, normed=True)
    

    
    v2 = np.zeros(6)
    v2[0] = greycoprops(glcm, 'contrast')[0, 0]
    v2[1] = greycoprops(glcm, 'dissimilarity')[0, 0]
    v2[2] = greycoprops(glcm, 'homogeneity')[0, 0]
    v2[3] = greycoprops(glcm, 'ASM')[0, 0]
    v2[4] = greycoprops(glcm, 'energy')[0, 0]
    v2[5] = greycoprops(glcm, 'correlation')[0, 0]

    print(v2)
    return v
In [3]:
normal1 = "../images/papsmear-data/normal_superficiel/157268504-157268544-001.BMP"
normal2 = "../images/papsmear-data/normal_superficiel/158987493-158987505-001.BMP"
normal3 = "../images/papsmear-data/normal_superficiel/209047526-209047717-001.BMP"
displastic1 = "../images/papsmear-data/severe_dysplastic/153829745-153829768-002.BMP"
displastic2 = "../images/papsmear-data/severe_dysplastic/153830680-153830827-002.BMP"
displastic3 = "../images/papsmear-data/severe_dysplastic/153831352-153831372-003.BMP"
In [4]:
im_normal1 = io.imread(normal1)
im_normal2 = io.imread(normal2)
im_normal3 = io.imread(normal3)
im_displastic1 = io.imread(displastic1)
im_displastic2 = io.imread(displastic2)
im_displastic3 = io.imread(displastic3)
In [5]:
extract_features(im_normal1)
[9.50253813e+01 6.22338479e+00 2.00398302e-01 1.34395350e-03
 3.66599714e-02 8.65643194e-01]
Out[5]:
array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
       2.10124164e-03, 1.35425479e-01, 8.62418702e-01, 5.45777050e-05])
In [6]:
extract_features(im_normal2)
[3.40044159e+02 1.12653715e+01 1.63137555e-01 1.19994286e-03
 3.46401914e-02 7.93578373e-01]
Out[6]:
array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
       7.67478115e-04, 1.19438782e-02, 1.30735100e-01, 8.56553544e-01])
In [7]:
extract_features(im_normal3)
[1.11811201e+02 6.42172644e+00 2.04779008e-01 1.44457334e-03
 3.80075432e-02 8.91938200e-01]
Out[7]:
array([0.        , 0.        , 0.        , 0.        , 0.00849059,
       0.50667326, 0.48483615, 0.        ])
In [8]:
extract_features(im_displastic1)
[2.84511595e+02 1.09831421e+01 1.22347677e-01 2.48745288e-04
 1.57716609e-02 9.39128409e-01]
Out[8]:
array([0.        , 0.        , 0.        , 0.        , 0.        ,
       0.32723112, 0.32318841, 0.34958047])
In [9]:
extract_features(im_displastic2)
[7.05307970e+02 1.75041746e+01 1.00181986e-01 5.68179772e-04
 2.38365218e-02 8.46544092e-01]
Out[9]:
array([0.        , 0.        , 0.        , 0.        , 0.0016129 ,
       0.63297491, 0.24713262, 0.11827957])
In [10]:
extract_features(im_displastic3)
[7.30351687e+02 1.60491858e+01 2.92104579e-01 5.70560711e-02
 2.38864127e-01 9.10849413e-01]
Out[10]:
array([0.        , 0.        , 0.        , 0.        , 0.        ,
       0.23632367, 0.1746988 , 0.58897753])
In [13]:
fig, ax = plt.subplots(figsize=(12, 12))
plt.subplot(2,3,1)
plt.imshow(im_normal1)
plt.subplot(2,3,2)
plt.imshow(im_normal2)
plt.subplot(2,3,3)
plt.imshow(im_normal3)
plt.subplot(2,3,4)
plt.imshow(im_displastic1)
plt.subplot(2,3,5)
plt.imshow(im_displastic2)
plt.subplot(2,3,6)
plt.imshow(im_displastic3)
Out[13]:
<matplotlib.image.AxesImage at 0x7fb1f96ea910>
In [ ]: