예제 #1
0
    def LoadImages(self):
        """处理每一个训练的image.

        处理每一个image,来初始化初始化self.images(存入所有训练图像矩阵),用mean_shape缩放得到的
        landmark初始化self.initLandmarks,用self.origLandmarks(通过读取.pts文件获得)来初始化self.gtLandmarks(gr-
        ound truth landmark)
        """
        pass
        print('Loading Images......')
        self.imgs = []
        self.initLandmarks = []
        self.gtLandmarks = []

        for i in range(len(self.filenames)):
            print('Loading ......%dth image.....'%(i))
            # ndimage.imread类似matlab的imread函数,对于RGB图像,返回height*width*3的矩阵, 对于灰度图返回height*width
            img = ndimage.imread(self.filenames[i])

            # 如果self.color为true保持rgb图不变灰度图叠加三次,结果为height*width*3 的img
            # 如果self.color为false保持灰度图不变rgb图rgb取平均,结果为height*width的img
            if self.color:
                if len(img.shape) == 2:
                    # 类似于np.concarenate
                    img = np.dstack((img, img, img))
            else:
                if len(img.shape) > 2:
                    # 转换为灰度图像,将RGB三值取平均
                    img = np.mean(img, axis=2)
            img = img.astype(np.uint8)

            if self.mirrors[i]:
                # 对需要做特征变换的图像,特征点做一个镜像变换
                self.origLandmarks[i] = utils.mirrorShape(self.origLandmarks[i], img.shape)
                # 对图像做镜像变换,fliplr即数组左右翻转,
                img = np.fliplr(img)

            # 如果self.color为true,则调整矩阵维度先后,变为3*height*width
            # 如果self.color为false,则增加一个维度, 变为1*height*width
            if self.color:
                img = np.transpose(img, (2, 0, 1))
            else:
                img = img[np.newaxis]

            groundTruth = self.origLandmarks[i]

            if self.initialization == 'rect':
                bestFit = utils.bestFitRect(groundTruth, self.meanShape)
            elif self.initialization == 'similarity':
                bestFit = utils.bestFit(groundTruth, self.meanShape)
            elif self.initialization == 'box':
                bestFit = utils.bestFitRect(groundTruth, self.meanShape, box=self.boundingBoxes[i])

            self.imgs.append(img)
            self.initLandmarks.append(bestFit)
            self.gtLandmarks.append(groundTruth)

        self.initLandmarks = np.array(self.initLandmarks)
        self.gtLandmarks = np.array(self.gtLandmarks)
        print('Loading Images finished')
예제 #2
0
def image_landmark_generate(filename, landmark, is_fliplr=False):

    image = cv2.imread(filename, 1)
    image = np.mean(image, axis=2)
    image = image.astype(np.uint8)
    if is_fliplr:
        image = np.fliplr(image)
        landmark = mirrorShape(landmark, image.shape)
    return image, landmark
예제 #3
0
    def LoadImages(self):

        self.imgs = []
        self.initLandmarks = []
        self.gtLandmarks = []

        for i in range(len(self.filenames)):
            # 이 코드는 잘 작성되지 않았으며 self.color는 실제적인 의미가 없습니다. <<<  这段代码写得不好,self.color并没有实际意义
            img = ndimage.imread(self.filenames[i])
            if self.color:

                if len(img.shape) == 2:
                    img = np.dstack((img, img, img))
            else:
                # img = ndimage.imread(self.filenames[i], mode='L')
                if len(img.shape) > 2:
                    img = np.mean(img, axis=2)
            img = img.astype(np.uint8)

            if self.mirrors[i]:
                self.origLandmarks[i] = utils.mirrorShape(
                    self.origLandmarks[i], img.shape)
                img = np.fliplr(img)

            if not self.color:
                #     img = np.transpose(img, (2, 0, 1))
                # else:
                img = img[
                    np.
                    newaxis]  # Img는 모양 (H, W)에서 모양 (1, H, W)로 바뀝니다. <<< img从shape(H,W)变成shape(1,H,W)
                # img = np.transpose(img, (1, 2, 0))

            groundTruth = self.origLandmarks[i]

            if self.initialization == 'rect':
                bestFit = utils.bestFitRect(
                    groundTruth, self.meanShape
                )  # 랜드 마크에 의해 결정된 상자에 도구 모양을 맞추기 만하면됩니다. <<< 仅仅把meanshape适应进入由landmark确定的框中
            elif self.initialization == 'similarity':
                bestFit = utils.bestFit(
                    groundTruth, self.meanShape
                )  # gt에 대한 meanShape의 최상의 변환을 찾아 변환하십시오. <<< 找到meanShape到gt的最优变换,并变换之
            elif self.initialization == 'box':
                bestFit = utils.bestFitRect(
                    groundTruth, self.meanShape, box=self.boundingBoxes[i]
                )  # 감지 된 bbx에 의해 결정된 상자에 도구 모양을 맞 춥니 다. <<< 仅仅把meanshape适应进入由检测到的bbx确定的框中

            self.imgs.append(img)
            self.initLandmarks.append(bestFit)
            self.gtLandmarks.append(groundTruth)

        self.initLandmarks = np.array(self.initLandmarks)
        self.gtLandmarks = np.array(self.gtLandmarks)
예제 #4
0
    def LoadImages(self):
        self.imgs = []
        self.initLandmarks = []
        self.gtLandmarks = []

        for i in range(len(self.filenames)):  # 读取文件夹下面的每个图片
            img = ndimage.imread(self.filenames[i])  # 图片shape:539 * 410 * 3

            if self.color:
                if len(img.shape) == 2:
                    img = np.dstack((img, img, img))
            else:
                if len(img.shape) > 2:  # img的信息坐标轴个数,row,column,channel共3个坐标轴
                    img = np.mean(
                        img, axis=2
                    )  # Compute the arithmetic mean along the specified axis.将rgb数据求平均,融合成新的数据
            img = img.astype(np.uint8)

            if self.mirrors[i]:
                self.origLandmarks[i] = utils.mirrorShape(
                    self.origLandmarks[i], img.shape)
                img = np.fliplr(img)

            if self.color:
                img = np.transpose(img, (2, 0, 1))
            else:
                img = img[
                    np.
                    newaxis]  # 在第一维增加一个新的坐标轴,shape由539 * 410,变为1 * 539 * 410

            groundTruth = self.origLandmarks[i]  # 取到

            if self.initialization == 'rect':
                bestFit = utils.bestFitRect(
                    groundTruth, self.meanShape)  # 返回由平均特征点经过缩放和偏移,生成的初始特征点坐标。
            elif self.initialization == 'similarity':
                bestFit = utils.bestFit(groundTruth, self.meanShape)
            elif self.initialization == 'box':
                bestFit = utils.bestFitRect(groundTruth,
                                            self.meanShape,
                                            box=self.boundingBoxes[i])

            self.imgs.append(img)  # 把文件夹中的图片依次加入list中
            self.initLandmarks.append(
                bestFit)  # 把文件夹中的图片对应的初始landmark坐标依次加入list中
            self.gtLandmarks.append(groundTruth)
            if i % 500 == 0:
                print("the %dth pic in func LoadImages()" % i)

        self.initLandmarks = np.array(self.initLandmarks)
        self.gtLandmarks = np.array(self.gtLandmarks)
예제 #5
0
    def LoadImages(self):
        self.imgs = []
        self.initLandmarks = []
        self.gtLandmarks = []

        for i in range(len(self.filenames)):
            # 这段代码写得不好,self.color并没有实际意义
            img = ndimage.imread(self.filenames[i])
            if self.color:

                if len(img.shape) == 2:
                    img = np.dstack((img, img, img))
            else:
                # img = ndimage.imread(self.filenames[i], mode='L')
                if len(img.shape) > 2:
                    img = np.mean(img, axis=2)
            img = img.astype(np.uint8)

            if self.mirrors[i]:
                self.origLandmarks[i] = utils.mirrorShape(
                    self.origLandmarks[i], img.shape)
                img = np.fliplr(img)

            if not self.color:
                #     img = np.transpose(img, (2, 0, 1))
                # else:
                img = img[np.newaxis]  # img从shape(H,W)变成shape(1,H,W)
                # img = np.transpose(img, (1, 2, 0))

            groundTruth = self.origLandmarks[i]

            if self.initialization == 'rect':
                # 仅仅把meanshape适应进入由landmark确定的框中
                bestFit = utils.bestFitRect(groundTruth, self.meanShape)
            elif self.initialization == 'similarity':
                # 找到meanShape到gt的最优变换,并变换之
                bestFit = utils.bestFit(groundTruth, self.meanShape)
            elif self.initialization == 'box':
                # 仅仅把meanshape适应进入由检测到的bbx确定的框中
                bestFit = utils.bestFitRect(groundTruth,
                                            self.meanShape,
                                            box=self.boundingBoxes[i])

            self.imgs.append(img)
            self.initLandmarks.append(bestFit)
            self.gtLandmarks.append(groundTruth)

        self.initLandmarks = np.array(self.initLandmarks)
        self.gtLandmarks = np.array(self.gtLandmarks)
예제 #6
0
    def LoadImages(self):
        self.imgs = []
        self.initLandmarks = []
        self.gtLandmarks = []

        for i in range(len(self.filenames)):
            img = ndimage.imread(self.filenames[i])

            if self.color:
                if len(img.shape) == 2:
                    img = np.dstack((img, img, img))
            else:
                if len(img.shape) > 2:
                    img = np.mean(img, axis=2)
            img = img.astype(np.uint8)

            if self.mirrors[i]:
                self.origLandmarks[i] = utils.mirrorShape(
                    self.origLandmarks[i], img.shape)
                img = np.fliplr(img)

            if self.color:
                img = np.transpose(img, (2, 0, 1))
            else:
                img = img[np.newaxis]

            groundTruth = self.origLandmarks[i]

            if self.initialization == 'rect':
                bestFit = utils.bestFitRect(groundTruth, self.meanShape)
            elif self.initialization == 'similarity':
                bestFit = utils.bestFit(groundTruth, self.meanShape)
            elif self.initialization == 'box':
                bestFit = utils.bestFitRect(groundTruth,
                                            self.meanShape,
                                            box=self.boundingBoxes[i])

            self.imgs.append(img)
            self.initLandmarks.append(bestFit)
            self.gtLandmarks.append(groundTruth)

        self.initLandmarks = np.array(self.initLandmarks)
        self.gtLandmarks = np.array(self.gtLandmarks)