示例#1
0
    def _onProcess(self, imageBuffer, startIndex, learningPhase,
                   XResult, yResult):
        """Overload"""

        convertor = NumpyPILConvertor()

        #Logging
        self.setTask(len(imageBuffer),
                     "PixitCoordinator loop for each image")
        #Init
        counter = 0
        index = startIndex * self.nbObjMultiplicator()

        #Main loop
        for image, label in imageBuffer:
            image = convertor.numpyToPIL(image)
            imgLs = self._multiSWExtractor.extract(image)
            #Filling the X and y
            for img in imgLs:
                tmpRes = self._featureExtractor.extract(
                    convertor.pILToNumpy(img))
                XResult[index] = self._rescaler(tmpRes)
                yResult[index] = label
                index += 1
            #Logging progress
            self.updateTaskProgress(counter)
            counter += 1
    def _onProcess(self, imageBuffer, startIndex, learningPhase, XResult,
                   yResult):
        """Overload"""

        convertor = NumpyPILConvertor()

        #Logging
        self.setTask(len(imageBuffer), "PixitCoordinator loop for each image")
        #Init
        counter = 0
        index = startIndex * self.nbObjMultiplicator()

        #Main loop
        for image, label in imageBuffer:
            image = convertor.numpyToPIL(image)
            imgLs = self._multiSWExtractor.extract(image)
            #Filling the X and y
            for img in imgLs:
                tmpRes = self._featureExtractor.extract(
                    convertor.pILToNumpy(img))
                XResult[index] = self._rescaler(tmpRes)
                yResult[index] = label
                index += 1
            #Logging progress
            self.updateTaskProgress(counter)
            counter += 1
示例#3
0
    def _onProcess(self, imageBuffer, learningPhase):
        """Overload"""
        ls = []
        y = []
        convertor = NumpyPILConvertor()

        #Logging
        counter = 0
        self.setTask(len(imageBuffer),
                     "PixitCoordinator loop for each image")
        for image, label in imageBuffer:
            image = convertor.numpyToPIL(image)
            imgLs = self._multiSWExtractor.extract(image)
            for img in imgLs:
                ls.append(
                    self._featureExtractor.extract(convertor.pILToNumpy(img)))
            y = y + [label] * len(imgLs)
            #Logging progress
            self.updateTaskProgress(counter)
            counter += 1
        X = np.vstack((ls))

        return X, y
    def extract(self, image):
        """
        Extract feature from the given image

        Parameters
        ----------
        image : :class:`PIL.Image` or preferably a numpy array
            The image to process

        Return
        ------
        all_subwindow : a list of lists of subwindows
            The element e[i][j] is a numpy array correspond to the ith
            subwindow of the jth filter.
            If the original image is included, it correspond to the first
            (0th) filter.
        """

        #Converting image in the right format
        convertor = NumpyPILConvertor()
        image = convertor.pILToNumpy(image)

        filtered = []

        #Including the original image if desired
        if self._include_image:
            pooledList = self._multiPooler.multipool(image)
            for pooled in pooledList:
                filtered.append(pooled)
        #Applying the filters & Aggregating
        for filt in self._finiteFilter:
            #Filtering
            npTmp = self._convolver(image, filt)
            #Aggregating
            pooledList = self._multiPooler.multipool(npTmp)
            for pooled in pooledList:
                filtered.append(pooled)

        #Refreshing the boxes
        shape = filtered[0].shape
        self._swExtractor.refresh(shape[1], shape[0])  # width, height

        #Extracting the subwindows
        nbFilters = len(self._finiteFilter)
        nbSubWindow = len(self._swExtractor)
        nbPoolers = len(self._multiPooler)
        nbImageFactor = nbFilters*nbPoolers
        if self._include_image:
            nbImageFactor += nbPoolers

        allSubWindows = [[0] * nbImageFactor for i in xrange(nbSubWindow)]

        for col, numpies in enumerate(filtered):
            #converting image to the right format
            img = convertor.numpyToPIL(numpies)
            #Extracting the subwindows s.s.
            subwindows = self._swExtractor.extract(img)
            for row in xrange(nbSubWindow):
                allSubWindows[row, col] = convertor.pILToNumpy(subwindows[row])

        return allSubWindows
示例#5
0
    def extract(self, image):
        """
        Extract feature from the given image

        Parameters
        ----------
        image : :class:`PIL.Image` or preferably a numpy array
            The image to process

        Return
        ------
        all_subwindow : a list of lists of subwindows
            The element e[i][j] is a numpy array correspond to the ith
            subwindow of the jth filter.
            If the original image is included, it correspond to the first
            (0th) filter.
        """

        #Converting image in the right format
        convertor = NumpyPILConvertor()
        image = convertor.pILToNumpy(image)

        filtered = []

        #Including the original image if desired
        if self._include_image:
            pooledList = self._multiPooler.multipool(image)
            for pooled in pooledList:
                filtered.append(pooled)
        #Applying the filters & Aggregating
        for filt in self._finiteFilter:
            #Filtering
            npTmp = self._convolver(image, filt)
            #Aggregating
            pooledList = self._multiPooler.multipool(npTmp)
            for pooled in pooledList:
                filtered.append(pooled)

        #Refreshing the boxes
        shape = filtered[0].shape
        self._swExtractor.refresh(shape[1], shape[0])  # width, height

        #Extracting the subwindows
        nbFilters = len(self._finiteFilter)
        nbSubWindow = len(self._swExtractor)
        nbPoolers = len(self._multiPooler)
        nbImageFactor = nbFilters * nbPoolers
        if self._include_image:
            nbImageFactor += nbPoolers

        allSubWindows = [[0] * nbImageFactor for i in xrange(nbSubWindow)]

        for col, numpies in enumerate(filtered):
            #converting image to the right format
            img = convertor.numpyToPIL(numpies)
            #Extracting the subwindows s.s.
            subwindows = self._swExtractor.extract(img)
            for row in xrange(nbSubWindow):
                allSubWindows[row, col] = convertor.pILToNumpy(subwindows[row])

        return allSubWindows