图像处理小技巧-图片切割

深度学习

图像处理 ...

前言

基于olivettifaces数据集

github地址


一、介绍

我们从网上下载olivettifaces图片包含400个57*47的小图,实际上我们需要对其做预处理,将其切分成400份

二、使用python实现

2.1 导入库

import cv2

2.2 全部程序

写一个分割数据集的程序
按照57*47的尺寸将其裁剪

import cv2
def split_to_dataset(img_path, save_path):
    olive = cv2.imread(img_path)
    if olive is None:
        raise Exception("can not open the olivettifaces dataset file.")
    for row in range(20):
        for column in range(20):
            img = olive[row * 57:(row + 1) * 57, column * 47:(column + 1) * 47]
            cv2.imwrite(img=img, filename=save_path + "/" + str(row) + "_" + str(column) + ".jpg")
split_to_dataset("F:\\face\\olivettifaces\\olivettifaces.jpg","F:\\face\\olivettifaces")

下面出示原图:在这里插入图片描述
以及切割后的图:
在这里插入图片描述

总结

期待大家和我交流,留言或者私信,一起学习,一起进步!

猜你喜欢

转载自blog.csdn.net/CltCj/article/details/118469215
今日推荐