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


Python ImageClass.Image类代码示例

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


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

示例1: mHullImg

 def mHullImg(self):
     tl = self.topLeftCorner()
     retVal = np.zeros((self.height(), self.width(), 3), np.uint8)
     npimg = self.image.getNumpy()[tl[1]:tl[1]+self.height(), tl[0]:tl[0]+self.width()]
     mask = self.mHullMask.getGrayNumpy()
     Image._copyNpwithMask(npimg, retVal, mask)
     return Image(retVal)
开发者ID:rajatkapoor,项目名称:SimpleCV2,代码行数:7,代码来源:Blob.py

示例2: circleDistance

    def circleDistance(self):
        """
        **SUMMARY**

        Compare the hull mask to an ideal circle and count the number of pixels
        that deviate as a fraction of total area of the ideal circle.

        **RETURNS**

        The difference, as a percentage, between the hull of our blob and an idealized
        circle of our blob. 

        """
        w = self.mHullMask.width
        h = self.mHullMask.height

        idealcircle = Image((w, h))
        radius = min(w, h) / 2
        idealcircle.dl().circle((w / 2, h / 2), radius, filled=True, color=Color.WHITE)
        idealcircle = idealcircle.applyLayers()
        print self.mHullMask
        print idealcircle
        print self.mHullMask.width
        print self.mHullMask.height
        print idealcircle.width
        print idealcircle.height
        netdiff = (idealcircle - self.mHullMask) + (self.mHullMask - idealcircle)
        numblack, numwhite = netdiff.histogram(2)
        return float(numwhite) / (radius * radius * np.pi)
开发者ID:rick446,项目名称:SimpleCV,代码行数:29,代码来源:Blob.py

示例3: reconstruct

 def reconstruct(self,img):
     """
     This is a "just for fun" method as a sanity check for the BOF codeook.
     The method takes in an image, extracts each codebook code, and replaces
     the image at the position with the code. 
     """
     retVal = cv.CreateImage((img.width,img.height), cv.IPL_DEPTH_8U, 1)
     data = self._getPatches(img)
     p = spsd.cdist(data,self.mCodebook)
     foo = p.shape[0]
     codes = np.argmin(p,axis=1)   
     count = 0
     wsteps = img.width/self.mPatchSize[0]
     hsteps = img.height/self.mPatchSize[1]
     w=self.mPatchSize[0]
     h=self.mPatchSize[1]
     length = w*h
     retVal = Image(retVal)
     for widx in range(wsteps):
         for hidx in range(hsteps):
             x = (widx*self.mPatchSize[0])
             y = (hidx*self.mPatchSize[1])
             p = codes[count]
             temp = Image(self.mCodebook[p,:].reshape(self.mPatchSize[0],self.mPatchSize[1]))    
             retVal.blit(temp,pos=(x,y))
             count = count + 1
     return retVal
开发者ID:blackball,项目名称:SimpleCV,代码行数:27,代码来源:BOFFeatureExtractor.py

示例4: addImage

    def addImage(self, img):
        """
        Add a single image to the segmentation algorithm
        """
        if( img is None ):
            return
        if( self.mLastImg == None ):
            if( self.mGrayOnlyMode ):
                self.mLastImg = img.toGray()
                self.mDiffImg = Image(self.mLastImg.getEmpty(1))
                self.mCurrImg = None
            else:
                self.mLastImg = img
                self.mDiffImg = Image(self.mLastImg.getEmpty(3))
                self.mCurrImg = None
        else:
            if( self.mCurrImg is not None ): #catch the first step
                self.mLastImg = self.mCurrImg

            if( self.mGrayOnlyMode ):
                self.mColorImg = img
                self.mCurrImg = img.toGray()
            else:
                self.mColorImg = img
                self.mCurrImg = img

            self.mDiffImg = Image(cv2.absdiff(self.mCurrImg.getNumpy(), self.mLastImg.getNumpy()))
        return
开发者ID:Betrezen,项目名称:SimpleCV2,代码行数:28,代码来源:DiffSegmentation.py

示例5: mImg

    def mImg(self):
        #NOTE THAT THIS IS NOT PERFECT - ISLAND WITH A LAKE WITH AN ISLAND WITH A LAKE STUFF
        retVal = np.zeros((self.height(), self.width(), 3), np.uint8)
        tl = self.topLeftCorner()

        npimg = self.image.getNumpy()[tl[1]:tl[1]+self.height(), tl[0]:tl[0]+self.width()]
        mask = self.mMask.getGrayNumpy()
        Image._copyNpwithMask(npimg, retVal, mask)

        return Image(retVal)
开发者ID:rajatkapoor,项目名称:SimpleCV2,代码行数:10,代码来源:Blob.py

示例6: draw

 def draw(self, color = Color.GREEN, width = -1, alpha = -1, layer = None):
     """
     **SUMMARY**
     
     Draw the blob, in the given color, to the appropriate layer
     
     By default, this draws the entire blob filled in, with holes.  If you
     provide a width, an outline of the exterior and interior contours is drawn.
     
     **PARAMETERS**
     
     * *color* -The color to render the blob as a color tuple.
     * *alpha* - The alpha value of the rendered blob 0=transparent 255=opaque.
     * *width* - The width of the drawn blob in pixels, if -1 then filled then the polygon is filled.
     * *layer* - A source layer, if layer is not None, the blob is rendered to the layer versus the source image.
     
     **RETURNS**
     
     This method either works on the original source image, or on the drawing layer provided.
     The method does not modify object itself.
     
     **EXAMPLE**
     
     >>> img = Image("lenna")
     >>> blobs = img.findBlobs()
     >>> blobs[-2].draw(color=Color.PUCE,width=-1,alpha=128)
     >>> img.show()
     """
     if not layer:
         layer = self.image.dl()
     
     if width == -1:
         #copy the mask into 3 channels and multiply by the appropriate color
         maskred = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
         maskgrn = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
         maskblu = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
         
         maskbit = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 3)
         
         cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskred, color[0] / 255.0)
         cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskgrn, color[1] / 255.0)
         cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskblu, color[2] / 255.0)
         
         cv.Merge(maskblu, maskgrn, maskred, None, maskbit)
         
         masksurface = Image(maskbit).getPGSurface()
         masksurface.set_colorkey(Color.BLACK)
         
         if alpha != -1:
             masksurface.set_alpha(alpha)
         layer._mSurface.blit(masksurface, self.topLeftCorner()) #KAT HERE
     
     else:
         self.drawOutline(color, alpha, width, layer)
         self.drawHoles(color, alpha, width, layer)
开发者ID:vivekannan,项目名称:SimpleCV,代码行数:55,代码来源:Blob.py

示例7: __add__

 def __add__(self, flt):
     if not isinstance(flt, type(self)):
         warnings.warn("Provide SimpleCV.DFT object")
         return None
     if self.size() != flt.size():
         warnings.warn("Both SimpleCV.DFT object must have the same size")
         return None
     flt_numpy = self._numpy + flt._numpy
     flt_image = Image(flt_numpy)
     retVal = DFT(numpyarray=flt_numpy, image=flt_image, size=flt_image.size())
     return retVal
开发者ID:AndersonYangOh,项目名称:SimpleCV,代码行数:11,代码来源:DFT.py

示例8: circleDistance

 def circleDistance(self):
     """
     Compare the hull mask to an ideal circle and count the number of pixels
     that deviate as a fraction of total area of the ideal circle
     """
     idealcircle = Image((self.width(), self.height()))
     radius = min(self.width(), self.height()) / 2
     idealcircle.dl().circle((self.width()/2, self.height()/2), radius, filled= True, color=Color.WHITE)
     idealcircle = idealcircle.applyLayers()
     
     netdiff = (idealcircle - self.mHullMask) + (self.mHullMask - idealcircle)
     numblack, numwhite = netdiff.histogram(2)
     return float(numwhite) / (radius * radius * np.pi)
开发者ID:ChrisCTX,项目名称:SimpleCV,代码行数:13,代码来源:Blob.py

示例9: _segmentSuperpixels

 def _segmentSuperpixels(self):
     img = self.new_clusters
     limit = np.max(img)
     superpixels = Superpixels()
     for label in range(limit+1):
         clusterimg = Image(255*(img == label).astype(np.uint8))
         blobs = clusterimg.findBlobs()
         if blobs is None:
             continue
         blob = blobs[-1]
         blob.image = self.image & clusterimg
         superpixels.append(blob)
     return superpixels
开发者ID:Betrezen,项目名称:SimpleCV2,代码行数:13,代码来源:Superpixels.py

示例10: getFullHullMaskedImage

    def getFullHullMaskedImage(self):
        """
        Get the full size image with the masked to the blob
        """
        tl = self.topLeftCorner()
        retVal = np.zeros((self.image.height, self.image.width, 3), np.uint8)
        npimgcrop = self.image.getNumpy()[tl[1]:tl[1]+self.height(), tl[0]:tl[0]+self.width()]
        mask = self.mHullMask.getGrayNumpy()
        retValcrop = retVal[tl[1]:tl[1]+self.height(), tl[0]:tl[0]+self.width()]

        Image._copyNpwithMask(npimgcrop, retValcrop, mask)

        retVal[tl[1]:tl[1]+self.height(), tl[0]:tl[0]+self.width()] = retValcrop

        return Image(retVal)
开发者ID:rajatkapoor,项目名称:SimpleCV2,代码行数:15,代码来源:Blob.py

示例11: load

 def load(self,datafile):
     """
     Load a codebook from file using the datafile. The datafile
     should point to a local image for the source patch image. 
     """
     myFile = open(datafile, 'r')
     temp = myFile.readline()
     #print(temp)
     self.mNumCodes = int(myFile.readline())
     #print(self.mNumCodes)
     w = int(myFile.readline())
     h = int(myFile.readline())
     self.mPatchSize = (w,h)
     #print(self.mPatchSize)
     self.mPadding = int(myFile.readline())
     #print(self.mPadding)
     w = int(myFile.readline())
     h = int(myFile.readline())
     self.mLayout = (w,h)
     #print(self.mLayout)
     imgfname = myFile.readline().strip()
     #print(imgfname)
     self.mCodebookImg = Image(imgfname)        
     self.mCodebook = self._img2Codebook(self.mCodebookImg,
                                         self.mPatchSize,
                                         self.mNumCodes,
                                         self.mLayout,
                                         self.mPadding)
     #print(self.mCodebook)        
     return
开发者ID:blackball,项目名称:SimpleCV,代码行数:30,代码来源:BOFFeatureExtractor.py

示例12: draw

    def draw(self, color=Color.RED, width=2, alpha=255):
        """
        **SUMMARY**

        Draw all the superpixels, in the given color, to the appropriate layer

        By default, this draws the superpixels boundary. If you
        provide a width, an outline of the exterior and interior contours is drawn.

        **PARAMETERS**

        * *color* -The color to render the blob as a color tuple.
        * *width* - The width of the drawn blob in pixels, if -1 then filled then the polygon is filled.
        * *alpha* - The alpha value of the rendered blob 0=transparent 255=opaque.
        
        **RETURNS**

        Image with superpixels drawn on it.

        **EXAMPLE**

        >>> image = Image("lenna")
        >>> sp = image.segmentSuperpixels(300, 20)
        >>> sp.draw(color=(255, 0, 255), width=5, alpha=128).show()
        """
        img = self.image.copy()
        self._drawingImage = Image(self.image.getEmpty(3))
        _mLayers = []
        for sp in self:
            sp.draw(color=color, width=width, alpha=alpha)
            self._drawingImage += sp.image.copy()
            for layer in sp.image._mLayers:
                _mLayers.append(layer)
        self._drawingImage._mLayers = copy(_mLayers)
        return self._drawingImage.copy()
开发者ID:Betrezen,项目名称:SimpleCV2,代码行数:35,代码来源:Superpixels.py

示例13: write_images

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,代码行数:33,代码来源:select-models.py

示例14: addImage

    def addImage(self, img):
        """
        Add a single image to the segmentation algorithm
        """
        if( img is None ):
            return

        self.mColorImg = img
        if( self.mModelImg == None ):
            self.mModelImg = Image(cv.CreateImage((img.width,img.height), cv.IPL_DEPTH_32F, 3))
            self.mDiffImg = Image(cv.CreateImage((img.width,img.height), cv.IPL_DEPTH_32F, 3))
        else:
            # do the difference
            cv.AbsDiff(self.mModelImg.getBitmap(),img.getFPMatrix(),self.mDiffImg.getBitmap())
            #update the model
            cv.RunningAvg(img.getFPMatrix(),self.mModelImg.getBitmap(),self.mAlpha)
            self.mReady = True
        return
开发者ID:AndersonYangOh,项目名称:SimpleCV,代码行数:18,代码来源:RunningSegmentation.py

示例15: draw

    def draw(self, color = Color.GREEN, alpha=-1, width=-1, layer=None):
        """
        Draw the blob, in the given color, to the appropriate layer
        
        By default, this draws the entire blob filled in, with holes.  If you
        provide a width, an outline of the exterior and interior contours is drawn.
        
        color = The color to render the blob.
        alpha = The alpha value of the rendered blob.
        width = The width of the drawn blob in pixels, if -1 then filled then the polygon is filled.
        layer = if layer is not None, the blob is rendered to the layer versus the source image.

        Parameters:
            color - Color object or Color tuple
            alpha - Int
            width - Int
            layer - DrawingLayer
        """
        if not layer:
            layer = self.image.dl()
            
        if width == -1:
            #copy the mask into 3 channels and multiply by the appropriate color
            maskred = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
            maskgrn = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
            maskblu = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
            
            maskbit = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 3) 

            cv.ConvertScale(self.mMask, maskred, color[0] / 255.0)
            cv.ConvertScale(self.mMask, maskgrn, color[1] / 255.0)
            cv.ConvertScale(self.mMask, maskblu, color[2] / 255.0)
            
            cv.Merge(maskblu, maskgrn, maskred, None, maskbit)    
            
            masksurface = Image(maskbit).getPGSurface()
            masksurface.set_colorkey(Color.BLACK)
            if alpha != -1:
                masksurface.set_alpha(alpha)
            layer._mSurface.blit(masksurface, self.points[0])
        else:
            self.drawOutline(color, alpha, width, layer)
            self.drawHoles(color, alpha, width, layer)
开发者ID:blackball,项目名称:SimpleCV,代码行数:43,代码来源:Blob.py


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