Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63641403
crossed2anaglyph
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 21, 13:37
Size
2 KB
Mime Type
text/x-python
Expires
Thu, May 23, 13:37 (2 d)
Engine
blob
Format
Raw Data
Handle
17799888
Attached To
rGTOOLS Gtools
crossed2anaglyph
View Options
#!/usr/bin/env python
'''
Create an anaglyph from a color file
Yves Revaz
mar oct 24 16:35:46 CEST 2006
'''
from
numarray
import
*
from
optparse
import
OptionParser
import
string
import
sys
import
os
import
shutil
import
Image
import
ImageDraw
import
ImageFont
import
ImagePalette
import
ImageTk
def
parse_options
():
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
# parser.add_option("-f",
# action="store",
# dest="inputfile",
# type="string",
# default = None,
# help="input file",
# metavar=" FILE NAME")
parser
.
add_option
(
"-o"
,
action
=
"store"
,
dest
=
"output"
,
type
=
"string"
,
default
=
None
,
help
=
"oputput file or output directory"
,
metavar
=
" NAME"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
len
(
args
)
==
0
:
print
"you must specify a filename"
sys
.
exit
(
0
)
files
=
args
return
files
,
options
#############################
# main
#############################
# get options
files
,
options
=
parse_options
()
#inputfile = options.inputfile
output
=
options
.
output
if
len
(
files
)
>
1
:
outdir
=
output
if
os
.
path
.
exists
(
outdir
):
print
"
%s
already exists !"
%
(
outdir
)
txt
=
"Continue anyway and removes the content of
%s
? [Y/n] "
%
(
outdir
)
bool
=
raw_input
(
txt
)
if
len
(
bool
)
==
0
or
bool
[
0
]
==
'y'
or
bool
[
0
]
==
'Y'
:
shutil
.
rmtree
(
outdir
)
print
"Removing
%s
"
%
(
outdir
)
else
:
print
"Nothing has been done. "
sys
.
exit
(
1
)
os
.
mkdir
(
outdir
)
else
:
outputfile
=
output
#############################
# open file
#############################
for
file
in
files
:
if
len
(
files
)
>
1
:
bname
=
os
.
path
.
basename
(
file
)
outputfile
=
os
.
path
.
join
(
outdir
,
bname
)
print
outputfile
# red
img
=
Image
.
open
(
file
)
r
,
g
,
b
=
img
.
split
()
r
=
fromstring
(
r
.
tostring
(),
UInt8
)
g
=
fromstring
(
g
.
tostring
(),
UInt8
)
b
=
fromstring
(
b
.
tostring
(),
UInt8
)
size
=
img
.
size
r
.
shape
=
(
size
[
1
],
size
[
0
])
g
.
shape
=
(
size
[
1
],
size
[
0
])
b
.
shape
=
(
size
[
1
],
size
[
0
])
# cut image
r2
=
r
[:,
0
:
size
[
0
]
/
2
]
g2
=
g
[:,
0
:
size
[
0
]
/
2
]
b2
=
b
[:,
0
:
size
[
0
]
/
2
]
r1
=
r
[:,
size
[
0
]
/
2
:]
g1
=
g
[:,
size
[
0
]
/
2
:]
b1
=
b
[:,
size
[
0
]
/
2
:]
r
=
r1
g
=
g2
b
=
b2
r
=
ravel
(
r
)
g
=
ravel
(
g
)
b
=
ravel
(
b
)
# new size
size
=
(
size
[
0
]
/
2
,
size
[
1
])
image_r
=
Image
.
fromstring
(
"L"
,
size
,
r
)
image_g
=
Image
.
fromstring
(
"L"
,
size
,
g
)
image_b
=
Image
.
fromstring
(
"L"
,
size
,
b
)
# merge image
img
=
Image
.
merge
(
"RGB"
,(
image_r
,
image_g
,
image_b
))
img
.
save
(
outputfile
)
Event Timeline
Log In to Comment