当前位置: 首页>>代码示例>>Python>>正文


Python Image.save方法代码示例

本文整理汇总了Python中SimpleCV.ImageClass.Image.save方法的典型用法代码示例。如果您正苦于以下问题:Python Image.save方法的具体用法?Python Image.save怎么用?Python Image.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCV.ImageClass.Image的用法示例。


在下文中一共展示了Image.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_images

# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import save [as 别名]
def write_images(model_path, fgvc_data_dir, images_nos, options):
    if options.crop:
        # read box information
        box_info = {}
        with open(path.join(fgvc_data_dir, 'images_box.txt')) as ibf:
            for line in ibf:
                result = line.split()
                img_no, coords = result[0], map(int, result[1:])
                box_info[img_no] = coords

    for image_no in images_nos:
        image_file = '%s.%s' % (image_no, FGVC_IMAGE_SUFFIX)
        img = Image(path.join(fgvc_data_dir, 'images', image_file))

        if options.crop:
            # although FGVC pages says the orgin is (1,1)
            # still there's some coordinates in box have 0 value
            # so don't do adjustment - 1px difference should be OK
            x1, y1, x2, y2 = box_info[image_no]
            img = img.crop(x1, y1, x2, y2)
        else:
            # remove out banner
            img = img.crop(0, 0, img.width, img.height-FGVC_BANNER_HEIGHT)

        if options.reduce_color_space:
            img = reduce_color_space(img, fast=True)

        if options.grayscale:
            img = img.grayscale()

        # normalize to width
        img = img.resize(NORMALIZED_WIDTH, int(img.height*1.0*NORMALIZED_WIDTH/img.width))
        img.save(path.join(model_path, image_file))
开发者ID:kavinyao,项目名称:airplane-recognition,代码行数:35,代码来源:select-models.py

示例2: BOFFeatureExtractor

# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import save [as 别名]
class BOFFeatureExtractor(object):
    """
    For a discussion of bag of features please see:
    http://en.wikipedia.org/wiki/Bag_of_words_model_in_computer_vision
    
    Initialize the bag of features extractor. This assumes you don't have
    the feature codebook pre-computed.
    patchsz = the dimensions of each codebook patch
    numcodes = the number of different patches in the codebook.
    imglayout = the shape of the resulting image in terms of patches
    padding = the pixel padding of each patch in the resulting image.
    
    """    
    mPatchSize = (11,11)
    mNumCodes = 128
    mPadding = 0
    mLayout = (8,16)
    mCodebookImg = None
    mCodebook = None
    
    def __init__(self,patchsz=(11,11),numcodes=128,imglayout=(8,16),padding=0):

        self.mPadding = padding
        self.mLayout = imglayout
        self.mPatchSize = patchsz
        self.mNumCodes = numcodes
    
    def generate(self,imgdirs,numcodes=128,sz=(11,11),imgs_per_dir=50,img_layout=(8,16),padding=0, verbose=True):
        """
        This method builds the bag of features codebook from a list of directories
        with images in them. Each directory should be broken down by image class.
        imgdirs = This list of directories.
        patchsz = the dimensions of each codebook patch
        numcodes = the number of different patches in the codebook.
        imglayout = the shape of the resulting image in terms of patches
        padding = the pixel padding of each patch in the resulting image.
        imgs_per_dir = this method can use a specified number of images per directory
                        i.e. min(#imgs_in_dir,imgs_per_dir)
        verbose = print output
                        
        Once the method has completed it will save the results to a local file
        using the file name codebook.png 
        
        
        WARNING: THIS METHOD WILL TAKE FOREVER
        """
        self.mPadding = padding
        self.mLayout = img_layout
        self.mNumCodes = numcodes
        self.mPatchSize = sz
        rawFeatures = np.zeros(sz[0]*sz[1])#fakeout numpy so we can use vstack
        for path in imgdirs:
            fcount = 0
            files = [] 
            for ext in IMAGE_FORMATS:
                files.extend(glob.glob( os.path.join(path, ext)))
            nimgs = min(len(files),imgs_per_dir)
            for i in range(nimgs):
                infile = files[i]
                if verbose:
                    print(path+" "+str(i)+" of "+str(imgs_per_dir))
                    print "Opening file: " + infile
                img = Image(infile)
                newFeat = self._getPatches(img,sz)
                if verbose:
                    print "     Got " + str(len(newFeat)) + " features."
                rawFeatures = np.vstack((rawFeatures,newFeat))
                del img
        rawFeatures = rawFeatures[1:,:] # pop the fake value we put on the top
        if verbose:
            print "=================================="
            print "Got " + str(len(rawFeatures)) + " features "
            print "Doing K-Means .... this will take a long time"
        self.mCodebook = self._makeCodebook(rawFeatures,self.mNumCodes)
        self.mCodebookImg = self._codebook2Img(self.mCodebook,self.mPatchSize,self.mNumCodes,self.mLayout,self.mPadding)
        self.mCodebookImg.save('codebook.png')
    
    def extractPatches(self, img, sz=(11,11) ):
        """
        Get patches from a single images. This is an external access method. The
        user will need to maintain the list of features. See the generate method
        as a guide to doing this by hand. Sz is the image patch size. 
        """
        return self._getPatches(img,sz)

    def makeCodebook(self, featureStack,ncodes=128):
        """
        This method will return the centroids of the k-means analysis of a large
        number of images. Ncodes is the number of centroids to find.
        """
        return self._makeCodebook(featureStack,ncodes)
        
    def _makeCodebook(self,data,ncodes=128):
        """
        Do the k-means ... this is slow as as shit
        """
        [centroids, membership] = cluster.kmeans2(data,ncodes, minit='points')
        return(centroids)
        
    def _img2Codebook(self, img, patchsize, count, patch_arrangement, spacersz):
#.........这里部分代码省略.........
开发者ID:blackball,项目名称:SimpleCV,代码行数:103,代码来源:BOFFeatureExtractor.py


注:本文中的SimpleCV.ImageClass.Image.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。