Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102359911
mprocimgs
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
Wed, Feb 19, 21:37
Size
3 KB
Mime Type
text/x-python
Expires
Fri, Feb 21, 21:37 (2 d)
Engine
blob
Format
Raw Data
Handle
24338250
Attached To
rMTOOLS Mtools
mprocimgs
View Options
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import
sys
,
os
import
glob
import
shutil
import
string
import
pickle
from
PIL
import
Image
from
PIL
import
ImageDraw
from
PIL
import
ImageFont
from
optparse
import
OptionParser
from
Mtools
import
*
####################################################################################
def
parse_options
():
####################################################################################
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
"-m"
,
"--mode"
,
action
=
"store"
,
dest
=
"mode"
,
type
=
"string"
,
default
=
'RGB'
,
help
=
"image mode : L, P or RGB"
)
parser
.
add_option
(
"-p"
,
"--parameterfile"
,
action
=
"store"
,
dest
=
"parameterfile"
,
type
=
"string"
,
default
=
None
,
help
=
"parameter file"
)
parser
.
add_option
(
"-o"
,
action
=
"store"
,
dest
=
"outputfile"
,
type
=
"string"
,
default
=
None
,
help
=
"output file name"
)
parser
.
add_option
(
"-d"
,
"--directory"
,
action
=
"store"
,
dest
=
"directory"
,
type
=
"string"
,
default
=
None
,
help
=
"image directory"
)
parser
.
add_option
(
"--cmd"
,
action
=
"store"
,
dest
=
"cmd"
,
type
=
"string"
,
default
=
None
,
help
=
"execute command"
)
parser
.
add_option
(
"-i"
,
"--infofile"
,
action
=
"store"
,
dest
=
"infofile"
,
type
=
"string"
,
default
=
None
,
help
=
"info file"
)
(
options
,
args
)
=
parser
.
parse_args
()
return
args
,
options
####################################################################################
#
# MAIN
#
####################################################################################
files
,
opt
=
parse_options
()
files
=
[
files
]
opt
.
outputdirectory
=
None
# check parameter file
if
opt
.
parameterfile
!=
None
:
if
not
os
.
path
.
isfile
(
opt
.
parameterfile
):
raise
"parameter file
%s
does not exits !"
%
opt
.
parameterfile
# read info file
info_dict
=
None
if
opt
.
infofile
!=
None
:
f
=
open
(
opt
.
infofile
)
info_dict
=
pickle
.
load
(
f
)
f
.
close
()
if
opt
.
directory
!=
None
:
opt
.
dicretories
=
string
.
split
(
opt
.
directory
,
','
)
files
=
[]
for
directory
in
opt
.
dicretories
:
if
not
os
.
path
.
isdir
(
directory
):
raise
"directory
%s
not exits !"
%
directory
fls
=
glob
.
glob
(
os
.
path
.
join
(
directory
,
"*"
))
fls
.
sort
()
print
directory
,
len
(
fls
)
files
.
append
(
fls
)
if
opt
.
outputfile
==
None
:
raise
"you must specify an output directory, using the outputfile option"
opt
.
outputdirectory
=
opt
.
outputfile
if
os
.
path
.
isdir
(
opt
.
outputdirectory
):
shutil
.
rmtree
(
opt
.
outputdirectory
)
os
.
mkdir
(
opt
.
outputdirectory
)
nd
=
len
(
files
)
# number of directories
n
=
len
(
files
[
0
])
# number of files in first directory
for
i
in
xrange
(
n
):
imgs
=
[]
for
d
in
xrange
(
nd
):
file
=
files
[
d
][
i
]
print
"
%08d
/
%08d
%s
"
%
(
i
,
n
,
file
)
# open the images
img
=
Image
.
open
(
file
)
# set the output type
if
opt
.
mode
!=
None
:
img
=
img
.
convert
(
opt
.
mode
)
# add to the list
imgs
.
append
(
img
)
# apply transformation
if
opt
.
cmd
!=
None
:
exec
(
opt
.
cmd
)
# apply transformations
if
opt
.
parameterfile
!=
None
:
execfile
(
opt
.
parameterfile
)
# save image
if
opt
.
outputdirectory
!=
None
:
img
.
save
(
os
.
path
.
join
(
opt
.
outputdirectory
,
"
%08d
.png"
%
i
))
elif
opt
.
outputfile
!=
None
:
img
.
save
(
opt
.
outputfile
)
Event Timeline
Log In to Comment