Search code examples
python-3.xsteganography

How can the code be modified so that multiple images can be read and stored in an array? so that they will be used for LSB steganography


The problem here is that this is only used for one image and i need to optimize it so that multiple images can be stored. (their width,height etc)

I am not fluent in python. I have worked on it about 4 years ago but now i have almost forgotten most part of the syntax.

def __init__(self, im):
    self.image = im
    self.height, self.width, self.nbchannels = im.shape
    self.size = self.width * self.height

    self.maskONEValues = [1,2,4,8,16,32,64,128]
    #Mask used to put one ex:1->00000001, 2->00000010 .. associated with OR bitwise
    self.maskONE = self.maskONEValues.pop(0) #Will be used to do bitwise operations

    self.maskZEROValues = [254,253,251,247,239,223,191,127]
    #Mak used to put zero ex:254->11111110, 253->11111101 .. associated with AND bitwise
    self.maskZERO = self.maskZEROValues.pop(0)

    self.curwidth = 0  # Current width position
    self.curheight = 0 # Current height position
    self.curchan = 0   # Current channel position

I want to store multiple images (their width, height etc) from a file path (that contains these images) in an array


Solution

  • TRY:-

    from PIL import Image
    import os
    
    # This variable will store the data of the images
    Image_data = []
    
    dir_path = r"C:\Users\vasudeos\Pictures"
    
    for file in os.listdir(dir_path):
    
        if file.lower().endswith(".png"):
    
            # Creating the image file object
            img = Image.open(os.path.join(dir_path, file))
    
            # Getting Dimensions of the image
            x, y = img.size
            # Getting channels of the image
            channel = img.mode
    
            img.close()
    
            # Adding the data of the image file to our list
            Image_data.append(tuple([channel, (x, y)]))
    
    
    print(Image_data)
    

    Just change the dir_path variable with the directory of your Image files. This code stores the color channel and dimensions of the Images, in a separate tuple unique to that file. And adds the tuple to a list.

    P.S.: Tuple format = (channels, dimensions)