コード例 #1
0
ファイル: kmeans2.py プロジェクト: Zeno199/NCTU_ML
    def kmeanDraw(self):
        cp_imgarr = copy.deepcopy(self.px)
        img = Image.new('RGB', (self.img_width, self.img_height), "white")
        p = img.load()

        Distance = cdist(self.px, self.centroids)
        cluster_id = np.argmin(Distance, axis=1)

        for i in range(len(cluster_id)):
            RGB_value = self.centroids[cluster_id[i]] * 255
            cp_imgarr[i] = RGB_value

        i = 0
        for x in range(self.img_width):
            for y in range(self.img_height):
                p[x, y] = tuple(cp_imgarr[i].astype(int))
                i += 1
        img.show()
        img.save('Kmean' + str(self.K) + '_poblem3.jpg')
コード例 #2
0
def loadImage(nombreImage='leon.jpeg', mostrarImagen=True):
    img = Image.open(nombreImage)
    if (mostrarImagen == True):
        img.show()
    return img
コード例 #3
0
def taskC():
    image = Image.open('f1.jpg')
    print(image.size)
    image.thumbnail((100, 100))
    print(image.size)
    image.show()
コード例 #4
0
def taskA():
    image = Image.open("f1.jpg")
    print(image.format)
    print(image.mode)
    print(image.size)
    image.show()
コード例 #5
0
'''
############################### Method 3: Keras: ###############################
'''
print("##### Keras #####")
################################ Load image ###############################
from keras.preprocessing.image import load_img

# load the image in PIL format
image = load_img("3096_color.jpeg")
# report details about the image
print(type(image))  # <class 'PIL.JpegImagePlugin.JpegImageFile'>
print(image.format)  # JPEG
print(image.mode)  # RGB
print(image.size)  # (481, 321)

image.show()

################################ Convert image PIL into np.array ###############################
from keras.preprocessing.image import img_to_array
image_array = img_to_array(image)
print(type(image_array))  # <class 'numpy.ndarray'>
print(image_array.dtype)  # float32
print(image_array.shape)  # (321, 481, 3)

################################ Reverse np.array into  PIL ###############################
from keras.preprocessing.image import array_to_img
image_PIL = array_to_img(image_array)
print(type(image_PIL))  # <class 'PIL.Image.Image'>

################################ Save image ###############################
from keras.preprocessing.image import save_img