补全代码import os image_files=os.listdir('./data/imgs') images=[] gts=[] masks=[] for i in image_files: images.append(os.path.join('./data/imgs',i)) gts.append(os.path.join('./data/gt',i)) for i in range(len(images)): ### YOUR CODE HERE # 10 point
时间: 2024-03-08 19:50:46 浏览: 197
解决python中os.listdir()函数读取文件夹下文件的乱序和排序问题
5星 · 资源好评率100%
```python
import os
import cv2
image_files=os.listdir('./data/imgs')
images=[]
gts=[]
masks=[]
for i in image_files:
images.append(os.path.join('./data/imgs',i))
gts.append(os.path.join('./data/gt',i))
for i in range(len(images)):
# 读取图像和掩膜
img = cv2.imread(images[i])
gt = cv2.imread(gts[i], cv2.IMREAD_GRAYSCALE)
# 计算掩膜
mask = (gt > 0).astype(int)
# 将图像和掩膜添加到列表中
images.append(img)
masks.append(mask)
# 打印图像和掩膜的数量
print("Number of images:", len(images))
print("Number of masks:", len(masks))
```
阅读全文