【问题标题】: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如何修改代码以便可以读取多个图像并将其存储在一个数组中?以便它们用于 LSB 隐写术
【发布时间】:2019-05-26 04:21:41
【问题描述】:

这里的问题是这仅用于一张图像,我需要对其进行优化以便可以存储多张图像。 (它们的宽度、高度等)

我不精通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

我想将来自文件路径(包含这些图像)的多个图像(它们的宽度、高度等)存储在一个数组中

【问题讨论】:

  • 你能描述一下你想要存储在你的数组中的数据吗
  • 每张图片的高度、宽度和通道像素
  • 通道像素是指构成图像的各个通道(例如 RGB)
  • 没错
  • 图像文件的扩展名是相同的还是可变的?如果是一样的,那你能说一下扩展名是什么

标签: python-3.x steganography


【解决方案1】:

试试:-

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 变量更改为图像文件的目录即可。此代码将图像的颜色通道和尺寸存储在该文件唯一的单独元组中。并将元组添加到列表中。

附注: 元组格式 =(通道、维度)

【讨论】:

  • 我正在重新评估代码,但没有看到 maskONEValues 和 maskZEROValues。它们对代码没有用处吗?
  • mask1 和 mask0 存储了什么?
  • 我建议你先试试我的代码,看看它是否适合你。然后我们可以对其进行改进或优化
  • 这两个代码的不同之处在于,我使用了PIL库提供的更多功能,以减少我编写所有代码的痛苦。另一方面,您似乎创建了一个类以实现相同的结果。其次,由于您只提供了代码的 sn-p 而不是完整版本,因此我很难校准/理解您在代码中使用的逻辑。
猜你喜欢
  • 2015-06-25
  • 1970-01-01
  • 1970-01-01
  • 2015-01-26
  • 2013-06-04
  • 1970-01-01
  • 1970-01-01
  • 2018-09-16
  • 2021-05-29
相关资源
最近更新 更多