[IPOL discuss] input image format in demos
Nicolas Limare
nicolas.limare at cmla.ens-cachan.fr
Tue Feb 8 10:55:04 CET 2011
Hi Pascal,
> I have a question about input image format in IPOL demos' python code. It
> seems you can select the format by setting the string app.input_ext (for
> example '.ppm' in graph cuts demo) but that first the images are saved in PNG
> format, and then additional files with required format (here PPM) are
> generated. Is this assumption correct?
Yes. In the file lib/base_app.py, lines 152 and following:
def process_input(self):
# [...]
for i in range(self.input_nb):
# [...]
# open the file as an image
try:
im = image(self.work_dir + 'input_%i' % i)
except IOError:
raise cherrypy.HTTPError(400, # Bad Request
"Bad input file")
# save the original file as png
im.save(self.work_dir + 'input_%i.orig.png' % i)
# convert to the expected input format
im.convert(self.input_dtype)
# check max size
if self.input_max_pixels \
and prod(im.size) > (self.input_max_pixels):
im.resize(self.input_max_pixels)
# [...]
# save a working copy
im.save(self.work_dir + 'input_%i' % i + self.input_ext)
# save a web viewable copy
im.save(self.work_dir + 'input_%i.png' % i)
# delete the original
os.unlink(self.work_dir + 'input_%i' % i)
The uploaded files, already received and saved as `input_X` in the
folder `self.work_dir`, are read as an image (via the PIL library),
and if successfully read, are
* saved in PNG, original size, as `input_X.orig.png`
* converted (in memory) to the requested data type (color, gray, ...)
* downsized if necessary
* saved in the requested format (app.input_ext) for further processing
by the program
* saved in PNG for inclusion in the web pages
--
Nicolas LIMARE
http://nicolas.limare.net/ pgp:0xFA423F4F
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20110208/51627e88/attachment-0001.pgp>
More information about the discuss
mailing list