Skip to content

Commit

Permalink
Fragmenta y une aleatoriamente cualquier imagen
Browse files Browse the repository at this point in the history
  • Loading branch information
ac-marlon authored Sep 9, 2018
1 parent d0df026 commit ede0141
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions SliceConcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

from random import shuffle
from random import choice
from skimage import io
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -16,20 +17,35 @@
i, j = matrizOriginal.shape

subMatrices = []
divHor = []
divVer = []

for x in range(4):
for y in range(7):
subMatrices.append(matrizOriginal[(x*160):160*(x+1), (y*61):61*(y+1)])
for n in range(2, 11):
if (i % n) == 0:
divVer.append(n)

for m in range(2, 11):
if (j % m) == 0:
divHor.append(m)

nPartVer = choice(divVer)
nPartHor = choice(divHor)

for x in range(nPartVer):
for y in range(nPartHor):
subMatrices.append(matrizOriginal[(x*int(i/nPartVer)):(int(i/nPartVer)*(x+1)),
(y*int(j/nPartHor)):(int(j/nPartHor)*(y+1))])

shuffle(subMatrices)
imaRand = np.hstack((subMatrices[0:nPartHor]))

imaRand = np.vstack((np.hstack((subMatrices[0:7])),
np.hstack((subMatrices[7:14])),
np.hstack((subMatrices[14:21])),
np.hstack((subMatrices[21:28]))))
for p in range(1, nPartVer):
imaRand = np.concatenate((imaRand, np.hstack((subMatrices[(p*nPartHor):((p+1)*nPartHor)]))),
axis=0)

plt.imshow(matrizOriginal, vmin=0, vmax=1)
plt.figure()
plt.imshow(imaRand, vmin=0, vmax=1)

io.imsave("imagenAleatoria.png", imaRand)

0 comments on commit ede0141

Please sign in to comment.