Search code examples
pythonimagecluster-analysisdata-science

How to clustering multiple images by the name in python


I have a multiple types of images in one folder and i want to save each type of Images in a different variable by the name and the first 6 character of the name is same and the primly character is the 7th.

i know how to import the images but my issue is how to separate it, and display them in the same time.

import cv2
import glop

image = [cv2.imread(img)for img in glop.glop ("c:/B/*.png")]

e.g :

sa_01_DF001 "D Type",

sa_01_DF002 "D Type",

sa_01_NB001 "N Type",

sa_01_NB002 "N Type",

sa_01_KP001 "K Type",

sa_01_KP002 "K Type".

To summarize my problem :

  • Separate the image by the name.
  • Save each type into variable.
  • Display multiple image in same time.

Solution

  • Thank you all for the answers, i solve my issue by this :

    import cv2
    import glob
    from keras.models import Sequential
    from keras.layers import Conv2D,MaxPooling2D
    from keras.layers import Activation,Dropout,Flatten,Dense
    import numpy
    import os
    
    seed = 10
    numpy.random.seed(seed)
    image_b = [cv2.imread(file_b)for file_b in glob.glob ("C:/BC/BENI/*.png")]
    labels = [name[name.find("_") + 1 : name.find("-")] 
    for name in glob.glob ("C:/BC/BENI/*.png")]
    labeled_images = list(zip(image_b, labels))
    all_image =('image_b')
    X = all_image[:] 
    Y = all_image[:]