python 图片外围置零 np.pad操作

    技术2024-12-07  13

    python 图片外围置零 np.pad操作

    path1 = 'I:\\xj\\pillar_train_val_test\\val\\labels_half_new' path2 = 'I:\\xj\\pillar_train_val_test\\val\\labels_half_new_draw' for filename in os.listdir(path1): img = cv2.imread(os.path.join(path1, filename), 0) shape = img.shape img_new = img[2:shape[0]-2, 2:shape[1]-2] img_new = np.pad(img_new, ((2,2), (2,2)), 'constant',constant_values = (0,0)) cv2.imwrite(os.path.join(path2, filename), img_new) print (filename)
    Processed: 0.068, SQL: 9