使用阈值平均算法对图像进行平滑处理

使用阈值平均算法对图像进行平滑处理和编程实现将彩色图像变换为单色图像(分别为R、G、B三种)

  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/7475476
  • 除此之外, 这篇博客: 图片数据集的均值与标准差计算中的 3. 求所有样本的R、G、B标准差 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • def get_image_pixel_std(img_dir, img_mean, img_list, img_size):
        R_squared_mean = 0
        G_squared_mean = 0
        B_squared_mean = 0
        count = 0
        image_mean = np.array(img_mean)
        # 循环读取所有图片
        for img_name in img_list:
            img_path = os.path.join(img_dir, img_name)
            if not os.path.isdir(img_path):
                image = cv2.imread(img_path)
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
                image = cv2.resize(image, (img_size, img_size))      # <class 'numpy.ndarray'>
                image = image - image_mean    # 零均值
                # 求单张图片的方差,并累加
                R_squared_mean += np.mean(np.square(image[:, :, 0]).flatten())
                G_squared_mean += np.mean(np.square(image[:, :, 1]).flatten())
                B_squared_mean += np.mean(np.square(image[:, :, 2]).flatten())
                count += 1
        # 求R、G、B的方差
        R_std = math.sqrt(R_squared_mean / count)
        G_std = math.sqrt(G_squared_mean / count)
        B_std = math.sqrt(B_squared_mean / count)
        print('R_std:{}, G_std:{}, B_std:{}'.format(R_std, G_std, B_std))
        RGB_std = [R_std, G_std, B_std]
        return RGB_std