Skip to content

Instantly share code, notes, and snippets.

@realazthat
Last active April 13, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realazthat/21ab404c30eb691a5e14c25b8c601d2f to your computer and use it in GitHub Desktop.
Save realazthat/21ab404c30eb691a5e14c25b8c601d2f to your computer and use it in GitHub Desktop.
Unpermutator.md
"""
Scramble/permute a frame of a video, requires numpy and opencv.
Licensed under CC0 (https://creativecommons.org/publicdomain/zero/1.0/)
"""
import argparse
import cv2
import numpy as np
def main():
parser = argparse.ArgumentParser(description='Extract and permute a frame.')
parser.add_argument('invideo', type=argparse.FileType('rb'),
help='A video to add to the MI frame')
parser.add_argument('--out', dest='outfile', type=argparse.FileType('wb'),
help='path to output frame')
parser.add_argument('--frame', type=int, default=0,
help='Frame number to extract (defaults to 0)')
parser.add_argument('--permute', action='store_true', default=False,
help='Should the output frame be permuted')
parser.add_argument('--gray', action='store_true', default=False,
help='Should the output frame be gray scale')
parser.add_argument('--binary', action='store_true', default=False,
help='Should the output frame be binary')
args = parser.parse_args()
cap = cv2.VideoCapture(args.invideo.name)
expected_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
width0 = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height0 = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
n0 = width0*height0
ret = True
i = 0
while(ret and cap.isOpened()):
ret, frame0 = cap.read()
if not ret:
break
if i < args.frame:
i += 1
continue
frame = frame0
depth = 3
if args.gray or args.binary:
frame = cv2.cvtColor(frame0, cv2.COLOR_BGR2GRAY)
depth = 1
print (frame.dtype)
print (frame)
if args.binary:
frame >>= 7
frame *= 255
print (frame.dtype)
print (frame)
expected_size = n0*depth
expected_shape = (height0,width0,depth)
if depth == 1:
expected_shape = (height0, width0)
assert frame.size == expected_size
assert frame.shape == expected_shape, (frame.shape, expected_shape, depth)
permuted_frame = np.copy(frame)
permuted_frame = permuted_frame.reshape((height0*width0,depth))
print ('permuted_frame.shape:',permuted_frame.shape)
np.random.shuffle(permuted_frame)
permuted_frame = permuted_frame.reshape((height0,width0, depth))
print (permuted_frame.shape)
outframe = frame
if args.permute:
outframe = permuted_frame
if args.outfile is not None:
cv2.imwrite(args.outfile.name, img=outframe)
return
if __name__ == '__main__':
main()
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="297mm"
height="210mm"
viewBox="0 0 1052.3622 744.09448"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="scramble.svg"
inkscape:export-filename="E:\realz\dump\code\brains\depermuter\docs\scramble.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7"
inkscape:cx="505.02906"
inkscape:cy="326.01041"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:window-width="1536"
inkscape:window-height="801"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid3336" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-308.26772)">
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 585.48128,422.96424 256.0076,852.57107"
id="path3441"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0"
inkscape:connection-start="#path3340-0-1-5"
inkscape:connection-end="#path3340-9-1" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 584.5392,526.38031 240,632.3622"
id="path3443"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0"
inkscape:connection-start="#path3340-6" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 584.23261,739.88284 257.14556,417.14742"
id="path3445"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0"
inkscape:connection-start="#path3340-9-7"
inkscape:connection-end="#path3340-0-1" />
<path
style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 584.46299,867.78331 255.8162,982.3332"
id="path3447"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0"
inkscape:connection-start="#path3340-9-1-4"
inkscape:connection-end="#path3340-9-9" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 580,992.3622 -340,-260"
id="path3449"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#808000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340"
d="m 253.39834,487.6336 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22413,6.95125 -13.22413,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97366,-7.51947 12.97366,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#5ebbff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3455"
d="m 660.29315,398.00639 c 13.84565,11.8261 28.26388,22.9815 42.31334,34.57435 3.42816,3.10793 6.87157,6.19912 10.28449,9.32379 11.02251,10.09154 21.8587,20.23512 33.62618,29.47873 11.7988,9.2682 17.60681,13.12596 30.04459,21.91732 22.47158,15.46094 46.16089,29.01391 69.28751,43.44255 38.58335,24.07207 -7.68955,-4.30454 26.78671,16.75454 17.51902,10.47425 35.06663,20.89948 52.9399,30.76267 32.96309,18.7221 67.51212,34.36356 102.05653,49.88379 7.3746,3.53845 15.0759,6.32956 22.5232,9.69968 3.1522,1.42646 6.2313,3.00927 9.3469,4.51391 3.23,1.50601 6.441,3.05363 9.6901,4.51801 6.068,2.73486 13.6148,5.87788 19.7443,8.46577 11.9055,4.76458 24.108,8.839 36.4587,12.29346 3.6012,1.08499 7.3179,1.23294 11.0445,1.2307 1.9694,-0.04 3.915,0.10826 5.8312,-0.37727 0,0 -16.9175,12.66813 -16.9175,12.66813 l 0,0 c -1.9914,0.0948 -3.9844,0.10101 -5.9779,0.0665 -3.7924,-0.11925 -7.5188,-0.57313 -11.0987,-1.92636 -11.8494,-4.11395 -23.589,-8.5801 -35.1701,-13.39447 -20.4395,-8.64768 -40.4838,-18.09956 -60.4015,-27.88658 -34.08655,-16.82995 -68.60706,-32.75299 -102.71142,-49.54636 -9.95792,-4.96435 -11.04782,-5.32474 -20.0088,-10.39713 -11.22076,-6.35155 -21.82441,-13.75474 -32.66105,-20.72254 -8.66319,-5.71909 -17.18869,-11.64606 -25.88572,-17.31356 -22.85471,-14.89346 -46.56898,-28.43485 -69.28252,-43.55081 -14.88301,-10.16894 -29.75023,-20.3185 -43.6468,-31.83334 -8.37053,-6.93591 -13.22195,-11.83226 -21.20715,-19.08065 -3.4094,-3.09481 -6.87156,-6.13101 -10.30734,-9.19651 -14.52646,-11.52768 -29.33007,-22.67092 -44.55385,-33.26434 0,0 17.8522,-11.10397 17.8522,-11.10397 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#5ebbff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3465"
d="m 1126.3079,701.11676 c -7.1406,2.95653 -14.7754,4.46713 -22.2018,6.52206 -14.9913,5.33392 -29.3555,12.13864 -43.6654,19.04827 -20.4182,10.47398 -41.2602,20.04698 -62.19868,29.42275 -25.82948,11.09278 -51.25924,23.05088 -76.60043,35.20804 -29.615,14.4552 -30.80586,15.07414 -52.1908,28.57105 -20.395,12.23358 -40.43302,25.01639 -60.34313,38.01797 -16.67122,10.77577 -33.87399,20.7806 -50.0479,32.30277 -8.98249,6.93418 -17.60837,14.38381 -24.51393,23.42686 -4.52964,5.43275 -8.1329,11.51678 -12.06629,17.36944 -3.70702,4.8038 -7.71451,9.36005 -11.4539,14.15276 -4.99134,6.26417 -9.44106,12.923 -14.22362,19.33812 -4.05584,5.31517 -8.04916,10.63777 -12.74214,15.40844 -4.01277,3.74823 -7.77348,7.62213 -10.51368,12.40612 -1.40602,3.11579 -3.55382,5.75425 -5.57511,8.47189 0,0 -19.40058,8.3405 -19.40058,8.3405 l 0,0 c 2.10051,-2.6857 4.48605,-5.167 5.96324,-8.2834 2.57084,-5.03267 6.05443,-9.27693 10.32963,-12.98454 1.45138,-1.42588 2.99927,-2.75763 4.37205,-4.25934 3.14042,-3.43538 5.59434,-7.46402 8.64438,-10.97522 2.51903,-3.16003 4.62566,-6.49271 6.9678,-9.77427 2.33351,-3.26947 5.15202,-6.17722 7.30898,-9.57937 2.0874,-2.77837 4.1208,-5.65765 6.32186,-8.34753 3.10444,-3.79389 0.45536,-0.2212 3.40847,-3.65811 0.53177,-0.61889 0.99473,-1.29374 1.49209,-1.94061 4.17802,-5.84301 7.76369,-12.10656 12.42564,-17.59795 6.87008,-9.50898 15.82306,-17.08771 25.01067,-24.30537 7.40367,-5.32257 15.00674,-10.08044 22.71955,-14.93636 9.37047,-5.89958 18.56218,-12.08712 28.08098,-17.75197 19.89491,-12.9353 39.79616,-25.85132 60.19554,-37.98753 27.07153,-17.17115 54.9998,-33.06684 84.01395,-46.73222 25.50712,-12.24118 51.13159,-24.21889 77.07056,-35.52262 21.0612,-9.49179 42.0127,-19.20734 62.5588,-29.78057 14.554,-7.09202 29.1947,-14.07867 44.5499,-19.29584 7.6578,-2.16978 15.6285,-3.86488 22.7237,-7.57914 0,0 -16.4204,13.28492 -16.4204,13.28492 z"
inkscape:connector-curvature="0" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 584.08225,639.64042 256.12607,522.5738"
id="path3467"
inkscape:connector-type="polyline"
inkscape:connector-curvature="0"
inkscape:connection-start="#path3340-0-4"
inkscape:connection-end="#path3340" />
<path
style="opacity:1;fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-6"
d="m 594.8269,491.91931 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22412,6.95125 -13.22412,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97365,-7.51947 12.97365,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#808000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-0-4"
d="m 594.37873,609.34932 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22411,6.95125 -13.22411,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97364,-7.51947 12.97364,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#ffff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9-7"
d="m 594.55205,713.56835 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22411,6.95125 -13.22411,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97364,-7.51947 12.97364,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9-1-4"
d="m 594.74999,833.06581 c 1.47063,3.3999 1.98607,7.0403 2.34454,10.6937 0.33272,5.0608 0.31011,10.1335 0.35892,15.202 -0.0388,4.3821 0.0182,8.764 0.0737,13.1456 -0.1535,2.5 0.27617,4.9457 0.60201,7.4106 0.18533,2.7941 0.63071,5.5569 0.97215,8.3349 0.21562,1.1144 0.49243,2.2094 0.6918,3.3266 0,0 -13.2241,6.9513 -13.2241,6.9513 l 0,0 c -0.0821,-1.1579 -0.37051,-2.2547 -0.59783,-3.3931 -0.31015,-2.7692 -0.83217,-5.5085 -1.02096,-8.2905 -0.31867,-2.5373 -0.83726,-5.0538 -0.60194,-7.6276 0.07,-4.4086 0.14851,-8.8175 0.10076,-13.2268 0.0179,-5.0156 -0.002,-10.0402 -0.36321,-15.0449 -0.32845,-3.4022 -0.72799,-6.8758 -2.30949,-9.9623 0,0 12.97363,-7.5195 12.97363,-7.5195 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9-9-2"
d="m 594.55204,956.42551 c 1.47063,3.3999 1.98607,7.0403 2.34454,10.6937 0.33272,5.0608 0.31011,10.1335 0.35892,15.202 -0.0388,4.3821 0.0182,8.7639 0.0737,13.1456 -0.1535,2.5 0.27617,4.94569 0.60201,7.41049 0.18533,2.7941 0.63071,5.557 0.97215,8.335 0.21562,1.1143 0.49243,2.2094 0.6918,3.3266 0,0 -13.2241,6.9513 -13.2241,6.9513 l 0,0 c -0.0821,-1.1579 -0.37051,-2.2547 -0.59783,-3.3931 -0.31015,-2.7692 -0.83217,-5.5085 -1.02096,-8.2905 -0.31867,-2.5374 -0.83726,-5.0538 -0.60194,-7.6276 0.07,-4.40859 0.14851,-8.81749 0.10076,-13.22679 0.0179,-5.0157 -0.002,-10.0402 -0.36321,-15.0449 -0.32845,-3.4022 -0.72799,-6.8759 -2.30949,-9.9624 0,0 12.97363,-7.5194 12.97363,-7.5194 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#800000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-0-1-5"
d="m 595.80729,382.20646 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.2241,6.95125 -13.2241,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97363,-7.51947 12.97363,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-0"
d="m 252.95017,605.06361 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22412,6.95125 -13.22412,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97365,-7.51947 12.97365,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9"
d="m 253.12349,709.28264 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22412,6.95125 -13.22412,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97365,-7.51947 12.97365,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#800000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9-1"
d="m 253.32143,828.78011 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22411,6.95125 -13.22411,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97364,-7.51947 12.97364,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-9-9"
d="m 253.12348,952.13978 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79406 0.63071,5.55696 0.97215,8.33496 0.21562,1.1143 0.49243,2.2094 0.6918,3.3266 0,0 -13.22411,6.9513 -13.22411,6.9513 l 0,0 c -0.0821,-1.1579 -0.37051,-2.2547 -0.59783,-3.3931 -0.31015,-2.7692 -0.83217,-5.5085 -1.02096,-8.2905 -0.31867,-2.5374 -0.83726,-5.0538 -0.60194,-7.62764 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97364,-7.51947 12.97364,-7.51947 z"
inkscape:connector-curvature="0" />
<path
style="opacity:1;fill:#ffff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3340-0-1"
d="m 254.37873,377.92075 c 1.47063,3.39991 1.98607,7.0403 2.34454,10.69373 0.33272,5.06078 0.31011,10.13345 0.35892,15.20196 -0.0388,4.38212 0.0182,8.76398 0.0737,13.14564 -0.1535,2.49999 0.27617,4.9457 0.60201,7.41053 0.18533,2.79409 0.63071,5.55695 0.97215,8.33497 0.21562,1.11432 0.49243,2.20934 0.6918,3.32659 0,0 -13.22411,6.95125 -13.22411,6.95125 l 0,0 c -0.0821,-1.15787 -0.37051,-2.25466 -0.59783,-3.39308 -0.31015,-2.76918 -0.83217,-5.50846 -1.02096,-8.29045 -0.31867,-2.53738 -0.83726,-5.05382 -0.60194,-7.62766 0.07,-4.40855 0.14851,-8.81747 0.10076,-13.22677 0.0179,-5.01564 -0.002,-10.04022 -0.36321,-15.04491 -0.32845,-3.4022 -0.72799,-6.87583 -2.30949,-9.96233 0,0 12.97364,-7.51947 12.97364,-7.51947 z"
inkscape:connector-curvature="0" />
<flowRoot
xml:space="preserve"
id="flowRoot3469"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
transform="matrix(0,-0.96351717,1.7380712,0,67.549061,1549.1129)"><flowRegion
id="flowRegion3471"><rect
id="rect3473"
width="320"
height="100"
x="760"
y="344.09448" /></flowRegion><flowPara
id="flowPara3475">Original video</flowPara></flowRoot> <text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="-860.11121"
y="150.44"
id="text3501"
sodipodi:linespacing="125%"
transform="matrix(-0.00171673,-0.99999853,0.99999853,-0.00171673,0,0)"><tspan
sodipodi:role="line"
x="-860.11121"
y="150.44"
id="tspan3505">Scrambled Video</tspan></text>
</g>
</svg>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

#Question

##Reconstructing a screen of permuted pixels

###Summary

Given a video with the pixel locations randomly permuted (once, for the entire video), can we (efficiently) reconstruct the original picture?

###Details

  • You are given an LCD screen with $n = w \times h$ pixels, that has been altered so that the pixel locations are permuted, once, in some random manner.
  • Watching a video on this LCD screen would obviously result in quite a garbled picture.
  • The permutation is mapped by some unknown function, we shall call $\text{permute}\left(x_0,y_0\right) \implies (x,y)$
  • Each pixel on the screen has a permuted location $(x,y)$ and some unknown original location $(x_0,y_0)$ (such that $\text{permute}\left(x_0,y_0\right)=(x,y)$).
  • You (and your computer) are given to watch a particular video of an average film of average length, with $m$ frames, and having the same resolution as the LCD screen; however for simplicity, assume the video will be in grayscale (for example, each pixel is a single color in the range $[0,256)$).
  • As a frame of reference, you are also informed which pixel is the lowest location in the original non-permuted screen (i.e you are given the values $x$ and $y$, such that $(x_0,y_0) =(0,0)$, and $\text{permute}\left(0,0\right)=(x,y)$).

###Goal

  • Algorithm to (efficiently) compute the mapping of the pixels to their original locations.
  • Can this be done in $o\left(n^2\right)$ space (i.e in better than $\mathcal O\left(n^2\right)$ space?)
  • Can this be done in $o\left(n^2f(m)\right)$ time?
    • I'm not sure how to ask this question correctly, but I am mostly wondering about reducing the $n^2$ factor.
  • Is this a known problem, or similar to any known problems?

PS. What about same question but for the case of binary images for each frame instead of grayscale.

###Appendix

 

Figure 1 Example permuted "LCD screen", side view

Figure 2 Example permuted "LCD screen", front view

 

Figure 3 Example video frame (color)

Figure 4 Example permuted video frame (color)

 

Figure 5 Example video frame (grayscale)

Figure 6 Example permuted video frame (grayscale)

 

Figure 7 Example video frame (binary, using most-significant-bitplane)

Figure 8 Example permuted video frame (binary)

###Related source codes are on gist.github.com

###Credits:

tags: reference-request, information-theory, algorithms, data-structures, probability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment