def compute_texture(im):
    '''Compute features for an image

    Parameters
    ----------
    im : str
        filepath for image to process

    Returns
    -------
    fs : ndarray
        1-D array of features
    '''
    from features import texture
    imc = mh.imread(im)
    return texture(mh.colors.rgb2grey(imc))
def compute_texture(im):
    '''Compute features for an image

    Parameters
    ----------
    im : str
        filepath for image to process

    Returns
    -------
    fs : ndarray
        1-D array of features
    '''
    from features import texture
    imc = mh.imread(im)
    return texture(mh.colors.rgb2grey(imc))
Ejemplo n.º 3
0
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

basedir = 'SimpleImageDataset/'
haralick, labels, chistogram = [], [], []

print(
    'This script will test (with cross-validation) classification of the simple 3 class dataset'
)
print('Computing features...')
# Use glob to get all the images
images = glob('{}/*.jpg'.format(basedir))

for fname in sorted(images):
    imc = mh.imread(fname)
    haralick.append(texture(mh.colors.rgb2gray(imc)))
    chistogram.append(chist(imc))
    labels.append(fname[:-len('xx.jpg')])

print('Finished computing features.')

haralick = np.array(haralick)
chistogram = np.array(chistogram)
labels = np.array(labels)

haralick_plus_chist = np.hstack([chistogram, haralick])

clf = Pipeline([('preproc', StandardScaler()),
                ('classifier', LogisticRegression())])

from sklearn import cross_validation
haralicks = []
sobels = []
labels = []

print('This script will test (with cross-validation) classification of the simple 3 class dataset')
print('Computing features...')
# Use glob to get all the images
images = glob('{}/*.jpg'.format(basedir))

# We sort the images to ensure that they are always processed in the same order
# Otherwise, this would introduce some variation just based on the random
# ordering that the filesystem uses
for fname in sorted(images):
    im = mh.imread(fname, as_grey=True)
    haralicks.append(texture(im))
    sobels.append(edginess_sobel(im))

    # Files are named like building00.jpg, scene23.jpg...
    labels.append(fname[:-len('xx.jpg')])

print('Finished computing features.')

haralicks = np.array(haralicks)
sobels = np.array(sobels)
labels = np.array(labels)

# We use logistic regression because it is very fast.
# Feel free to experiment with other classifiers
scores = cross_validation.cross_val_score(
    LogisticRegression(), haralicks, labels, cv=5)
Ejemplo n.º 5
0
sobels = []
labels = []

print(
    'This script will test (with cross-validation) classification of the simple 3 class dataset'
)
print('Computing features...')
# Use glob to get all the images
images = glob('{}/*.jpg'.format(basedir))

# We sort the images to ensure that they are always processed in the same order
# Otherwise, this would introduce some variation just based on the random
# ordering that the filesystem uses
for fname in sorted(images):
    im = mh.imread(fname, as_grey=True)
    haralicks.append(texture(im))
    sobels.append(edginess_sobel(im))

    # Files are named like building00.jpg, scene23.jpg...
    labels.append(fname[:-len('xx.jpg')])

print('Finished computing features.')

haralicks = np.array(haralicks)
sobels = np.array(sobels)
labels = np.array(labels)

# We use logistic regression because it is very fast.
# Feel free to experiment with other classifiers
scores = cross_validation.cross_val_score(LogisticRegression(),
                                          haralicks,
Ejemplo n.º 6
0
def compute_texture(im):   
    from features import texture
    imc = mh.imread(im)
    return texture(mh.colors.rgb2gray(imc))
Ejemplo n.º 7
0
labels = []
chists = []

print(
    'This script will test (with cross-validation) classification of the simple 3 class dataset'
)
print('Computing features...')
# Use glob to get all the images
images = glob('{}/*.jpg'.format(basedir))

# We sort the images to ensure that they are always processed in the same order
# Otherwise, this would introduce some variation just based on the random
# ordering that the filesystem uses
for fname in sorted(images):
    imc = mh.imread(fname)
    haralicks.append(texture(mh.colors.rgb2grey(imc)))
    chists.append(color_histogram(imc))

    # Files are named like building00.jpg, scene23.jpg...
    labels.append(fname[:-len('xx.jpg')])

print('Finished computing features.')

haralicks = np.array(haralicks)
labels = np.array(labels)
chists = np.array(chists)

haralick_plus_chists = np.hstack([chists, haralicks])

# We use Logistic Regression because it achieves high accuracy on small(ish) datasets
# Feel free to experiment with other classifiers
Ejemplo n.º 8
0
def compute_texture(im):
    from features import texture
    imc = mh.imread(im)
    return texture(mh.colors.rgb2gray(imc))
haralicks = []
labels = []
chists = []

print('This script will test (with cross-validation) classification of the simple 3 class dataset')
print('Computing features...')
# Use glob to get all the images
images = glob('{}/*.jpg'.format(basedir))

# We sort the images to ensure that they are always processed in the same order
# Otherwise, this would introduce some variation just based on the random
# ordering that the filesystem uses
for fname in sorted(images):
    imc = mh.imread(fname)
    haralicks.append(texture(mh.colors.rgb2grey(imc)))
    chists.append(color_histogram(imc))

    # Files are named like building00.jpg, scene23.jpg...
    labels.append(fname[:-len('xx.jpg')])

print('Finished computing features.')

haralicks = np.array(haralicks)
labels = np.array(labels)
chists = np.array(chists)

haralick_plus_chists = np.hstack([chists, haralicks])


# We use Logistic Regression because it achieves high accuracy on small(ish) datasets