import cv2
import matplotlib.pyplot as plt
import numpy as np
import os
import glob
from PIL import Image
#加载图片
img = cv2.imread('./NWPU/image/airplane_001.jpg', cv2.IMREAD_UNCHANGED)
# file_path = "./NWPU/tra/" # 文件夹路径
# dirs = os.listdir(file_path)
# images_path = glob.glob(os.path.join(file_path + '*.jpg')) # 所有图片路径
# for image_path in images_path:
# img = cv2.imread(image_path)
img = cv2.resize(img, (255, 255), cv2.INTER_LINEAR)
#获取图片尺寸
height, width = img.shape[:2]
height = int(height)
width = int(width)
circleIn = np.zeros((height, width, 1), np.uint8)
for i in range(3):
for j in range(3):
circleIn = cv2.circle(circleIn, ((2*i+1)*42, (2*j+1)*42), 42, (1), -1)
# 原图与内显示模板融合
# 生成空白图片
imgIn = np.zeros((height, width, 4), np.uint8)
# 复制前3个通道
imgIn[:, :, 0] = np.multiply(img[:, :, 0], circleIn[:, :, 0])
imgIn[:, :, 1] = np.multiply(img[:, :, 1], circleIn[:, :, 0])
imgIn[:, :, 2] = np.multiply(img[:, :, 2], circleIn[:, :, 0])
# 设置α通道的不透明部分
circleIn[circleIn == 1] = 255
imgIn[:, :, 3] = circleIn[:, :, 0]
cv2.imwrite('./NWPU/out/1.jpg', imgIn)