如何修改代码以便可以读取多个图像并将其存储在一个数组中?以便它们将用于 LSB 隐写术
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
这里的问题是这只用于一张图片,我需要优化它以便可以存储多张图片。 (它们的宽度、高度等)
我不流利python。我大约 4 年前就研究过它,但现在我几乎忘记了大部分语法。
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
我想将一个文件路径(包含这些图像)中的多个图像(它们的宽度、高度等)存储在一个数组中
尝试:-
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)
只需将 dir_path
变量更改为图像文件的目录。此代码将图像的颜色通道和尺寸存储在该文件唯一的单独元组中。并将元组添加到列表中。
P.S.:
元组格式 =(通道,维度)
这里的问题是这只用于一张图片,我需要优化它以便可以存储多张图片。 (它们的宽度、高度等)
我不流利python。我大约 4 年前就研究过它,但现在我几乎忘记了大部分语法。
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
我想将一个文件路径(包含这些图像)中的多个图像(它们的宽度、高度等)存储在一个数组中
尝试:-
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)
只需将 dir_path
变量更改为图像文件的目录。此代码将图像的颜色通道和尺寸存储在该文件唯一的单独元组中。并将元组添加到列表中。
P.S.: 元组格式 =(通道,维度)