Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Examples > Converting Set of Images

Converting Set of Images

This example uses the ImageSet library to convert an entire directory of images to the .jpg format. It first uses the ImageSet to load the directory of images. It then iterates through the set, changing the name of the file to have a .jpg extension. Then it saves the file again with the new file extension and automatically converts it to the new file format during the save process.

from SimpleCV import ImageSet

set = ImageSet(".")  1

for img in set:  2

     oldname = img.filename  3

     newname = oldname[0:-3] + 'jpg'  4

     print "Converting " + oldname + " to " + newname

     img.save(newname)  5
1

The first step is to get an ImageSet of all the files. This example assumes that the code is run from the same directory that contains the images, the Chapter 3 folder. Note that although the chicago.mp4 file is also in the Chapter 3 folder, it is not an image file, so ImageSet will skip it.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial