我在尝试弄乱我的图像时遇到问题。我希望它只移动特定的列,而现在它混杂了x和y轴以将块放置在任何地方。问题很可能出在yblock参数上,我不确定如何更改它以使此列混杂算法。
# Image Jumble for a single image
BLOCKLEN = 100
# The higher the value the less jumbled the
# image becomes...
img = PIL.Image.open(r'G:\My Drive\CATSVDOGS2.0\test_resized\1test_re.jpg')
width, height = img.size
xblock = width / BLOCKLEN
yblock =
blockmap = [(xb*BLOCKLEN, yb*BLOCKLEN, (xb+1)*BLOCKLEN, (yb+1)*BLOCKLEN)
for xb in range(int(xblock)) for yb in range(int(yblock))]
shuffle = list(blockmap)
random.shuffle(shuffle)
result = Image.new(img.mode, (width, height))
for box, sbox in zip(blockmap, shuffle):
c = img.crop(sbox)
result.paste(c, box)
#result.save(r"G:\My Drive\CATSVDOGS2.0\test_resized\00000000001.jpg")
# test to see if save works
result.show() # needs to be outside of the loop or it will iterate 10 times
# to get to the result
以下是一个从我的数据集中显示出来的图像的例子:
如果有人可以帮助我得到它,以便使它排成10列并弄乱这些列,我将不胜感激,谢谢