AvgRGB_class.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:DenoiseAverage 作者: Pella86 项目源码 文件源码
def average_mean(self, aligned = True, debug = False, transition = True):
        ''' performs the mean of the images, aligned is True will use the
        aligned pictures while if false will use the original picture, 
        for the transition, each averaging step is printed out
        '''

        self.mylog.log("started the mean averaging procedure")

        sizedataset = len(self.imgs_names)

        if aligned:
            picture = self.get_alg_image(0)
        else:
            picture = self.get_image(0)       

        # initialize sum variable
        s = MyRGBImg(np.zeros(picture.data.shape))
        #s = color.rgb2lab(s.data)

        for i in range(sizedataset):
            if debug:
                self.mylog.log("Averaging image: " + str(i))
            #load the picture
            if aligned:
                picture = self.get_alg_image(i)
            else:
                picture = self.get_image(i)
            # convert both to lab
            #im = color.rgb2lab(picture.data)
            im = picture.data

            #perform operations
            s += im

            # if the transition is true show what happens to each picture
            if transition:
                tr = s / float(i + 1)
                #avg = MyRGBImg(color.lab2rgb(tr))
                avg = tr
                avg.save(join(self.subfolders["avg_transition"], "avg_tr_" + str(i) + ".png"))

        # calculate the average    
        s = s / float(sizedataset)
        #self.avg = MyRGBImg(color.lab2rgb(s))
        self.avg = s

        # small trick to align the image in the correct sense if they are 
        # squared
        if self.avg.data.shape[0] == self.avg.data.shape[1]:
            self.avg.rotate(90)
            self.avg.flip_V()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号