示例#1
0
def predictor():
    for img in glob('/home/linuxsagar/tempTest/*'):

        #List to hold the feature of new Image
        _new_features = []

        #Read the test image
        _custom_image = Image(img)

        #Extract features
        _newHhfe = hhfe.extract(_custom_image)
        _newEhfe = ehfe.extract(_custom_image)
        _newHaarfe = haarfe.extract(_custom_image)

        #List for the graph
        hue_data = []
        haar_data = []
        edge_data = []

        hue_fields = hhfe.getFieldNames()
        for i in range(0, hhfe.getNumFields()):
            hue_data.append(str(hue_fields[i]) + ' = ' + str(_newHhfe[i]))

        edge_fields = ehfe.getFieldNames()
        for i in range(0, hhfe.getNumFields()):
            edge_data.append(str(edge_fields[i]) + ' = ' + str(_newEhfe[i]))

        haar_fields = haarfe.getFieldNames()
        for i in range(0, len(haar_fields)):
            haar_data.append(str(haar_fields[i]) + ' = ' + str(_newHaarfe[i]))

        #Concatinate all feature to one
        _new_features.append(np.concatenate([_newHhfe, _newEhfe, _newHaarfe]))
        probability = np.amax(classifier.predict_proba(_new_features))

        #Call method to generate histogram image
        make_histogram(_custom_image.histogram(), _newHhfe, _newEhfe,
                       _newHaarfe, dataDir)

        #The Final result to view
        result = [
            "The given input is classified as: {}.".format(
                classifier.predict(_new_features)[0]),
            "Probability of prediction: {:.1%}".format((probability))
        ]

        return [result, hue_data, edge_data, haar_data]
示例#2
0
def classify(im, K, show=False):
    """ classify    - classify an image using k-means algorithm.

    Arguments:
        * im            - an image (ndarray) or a filename.
        * K             - number of classes.
        * show  = False - if True, display the image and the classes.

    Return:
        * imClasses     - the classes of the image (ndarray, 2D).

    See also:
        * kMeans        - K-means algorithm.
    """
    a = Image(im)
    a = a.histogram(255)
    
    # Load image
    if type(im) is str:
        im = plt.imread(im)

    # Reshape and apply k-mean
    values = im.reshape((im.shape[0] * im.shape[1], -1))
    centers, classes = kMeans(values, K)
    imClasses = classes.reshape((im.shape[0], im.shape[1]))
##    imClasses.save("imClassesH.png")
##    imClassesHl=image("imClassesH.png")
##    imClassHisto=imClassesH1.histogram(255)
    
    
    # Display
    if show:
                
        cmap = 'gray' if im.ndim < 3 else None
        plt.subplot(131), plt.imshow(im, cmap=cmap), plt.title('Imagen Gray')
        plt.subplot(132), plt.imshow(imClasses), plt.title('Segmentacion por Clases')
        pylab.subplot(133), pylab.plot(a), pylab.draw(), pylab.pause(0.0001), pylab.title('Histograma Img Gray')

        plt.show()

    # The end
    return imClasses
from SimpleCV import Image

# change this to process multiple images
img = Image("../images/beach.jpeg")
histogram = img.histogram()

print histogram.getFieldNames
示例#4
0
        * X     - center of the classes, row by row (ndarray, 2D).

    See also:
        * kMeans            - k-means classification.
        * nearestNeighbor   - nearest neighbor classification.
    """

    # Check dimensions
    if Y.ndim != 2:
        raise Exception('data matrix must be a 2D ndarray')
    if C.ndim != 1:
        raise Exception('classes matrix must be a 1D ndarray')
    if Y.shape[0] != C.shape[0]:
        raise Exception('Y and C matrix must have the same number of rows')

    # Create an empty array
    K = C.max() + 1
    X = np.ndarray((K, Y.shape[1]), Y.dtype)

    # Compute barycenters
    for k in range(K):
        X[k,:] = Y[C == k,:].mean(0)

    # Return them
    return X

a = Image("hola5Gray.png")
b = a.histogram(255)

classify("hola5Gray.png", 2, show=True)
示例#5
0
def getHistogram(imageFile):
    im = Image(imageFile)
    #im = im.toRGB()
    im = im.toHSV()
    
    return im.histogram(64)
from SimpleCV import Image
from SimpleCV.Shell import plot

img = Image('ex21a.jpg') # Open ex21b.jpg and ex21c.jpg too :)

# Generate the histogram with 256 bins, one for each color
histogram = img.histogram(256)
# Show how many elements are in the list
len(histogram)
# Graphically display the histogram
plot(histogram)
示例#7
0
#!/usr/bin/python

from SimpleCV import Camera, Display, Image
import matplotlib.pyplot as plt
import time

cam = Camera()
img = cam.getImage().save("img.jpg")
img = Image("img.jpg")
img.show()
imgGray = img.grayscale().save("imgGray.jpg")
imgGray = Image("imgGray.jpg")
imgGray.show()
hist = imgGray.histogram(255)

(red, green, blue) = img.splitChannels(False)
red_histogram = red.histogram(255)
green_histogram = green.histogram(255)
blue_histogram = blue.histogram(255)
plt.figure(1)
plt.subplot(411)
plt.plot(hist)
plt.subplot(412)
plt.plot(red_histogram)
plt.subplot(413)
plt.plot(green_histogram)
plt.subplot(414)
plt.plot(blue_histogram)
plt.show()

print("Ingresar parametro para binarizar: ")