This article refers to the following pages.
Download from the following site to use the data set called BSDS500.
https://github.com/BIDS/BSDS500 P. Arbelaez, M. Maire, C. Fowlkes and J. Malik, "Contour Detection and Hierarchical Image Segmentation," IEEE TPAMI, Vol. 33, No. 5, pp. 898-916, May 2011.
Only BSDS500 / data / images
is used this time, so only the necessary ones are taken out.
Move the files in test to train.
./data
.
└── BSDS500
└── images
├── train # train + test = 400 images
└── val # val = 100 images
Use the OpenCV imwrite function.
cv2.imwrite(<save_path>, <img>, [int(cv2.IMWRITE_JPEG_QUALITY), <jpeg_quality>])
** save_path **: destination path, ** img **: image, ** jpeg_quality **: JPEG image quality
.
├── create_jpeg_image.py
└── data
└── BSDS500
└── images
├── train
│ └── gnd
└── val
└── gnd
create_jpeg_image.py
import os
import cv2
import argparse
def save_jpeg_images(src_path, dst_path, q=100):
file_list = os.listdir(src_path)
dst_path = os.path.join(dst_path, 'q{}'.format(q))
os.makedirs(dst_path, exist_ok=True)
for file_name in file_list:
im = cv2.imread(os.path.join(src_path, file_name))
cv2.imwrite(os.path.join(dst_path, file_name), im, [int(cv2.IMWRITE_JPEG_QUALITY), q])
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--src_path', default='./data/BSDS500/images/val/gnd')
parser.add_argument('--dst_path', default='./data/BSDS500/images/val')
parser.add_argument('--q', type=int, default=10)
args = parser.parse_args()
save_jpeg_images(args.src_path, args.dst_path, args.q)
that's all
Recommended Posts