Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

python - 如何检查嵌套列表中的所有数字是否等于n(How to check if all numbers in a nested list are equal to n)

So I want to encode a secret image in another b&w image.

(所以我想在另一个黑白图像中编码一个秘密图像。)

This image must have the same size as the original image that we are trying to hide the secret image in, so we have a correspondence of pixels for the two images.

(该图像的大小必须与我们试图在其中隐藏秘密图像的原始图像大小相同,因此对于这两个图像,我们具有对应的像素。)

To encode the secret image:

(编码秘密图像:)

If a pixel in the secret image is white (so, with RGB values of [255, 255, 255]), add 1 to the blue component (last number).

(如果秘密图像中的像素为白色(因此,RGB值为[255、255、255]),请在蓝色分量(最后一个数字)上加1。)

Otherwise, leave the blue component untouched.

(否则,请保持蓝色组件不变。)

So basically the coloured image is hidden in the b&w image by using an altered blue component from the original image.

(因此,通过使用原始图像中更改的蓝色成分,彩色图像基本上隐藏在黑白图像中。)

Decoding the b&w image is done through reversal of the encoding process.

(通过反转编码过程完成对黑白图像的解码。)

So lets say I currently have the following list of pixels:

(所以可以说我目前有以下像素列表:)

P = [[0, 0, 0], [255, 255, 255], [255, 184, 254], [255, 0, 254]]

Assuming that the width and height of both images are the same.

(假设两个图像的宽度和高度相同。)

How would I check if any 'pixel' in P is equal to 255?

(我如何检查P中的任何“像素”是否等于255?)

So this means that all 3 numbers in the 'pixel' must be equal to 255.

(因此,这意味着“像素”中的所有3个数字必须等于255。)

  ask by Sania translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use

(您可以使用)

for idx,lst in enumerate(P):
    if lst==[255,255,255]:
       print(idx,lst)

or

(要么)

enc_P=[] 
for lst in P:
    if lst==[255,255,255]:
       print(lst)
    enc_P.append(lst)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...