Skip to content
Snippets Groups Projects
Commit 09dfbd63 authored by 何向东's avatar 何向东
Browse files

训练过程中裁切图像

parent 15e14537
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ import os
from PIL import Image
import cv2
import mindspore.dataset as ds
import random
class GetDatasetGenerator:
......@@ -16,12 +17,16 @@ class GetDatasetGenerator:
line = f.readline() # 读取下一行
def __getitem__(self, index):
size1 = 3400
size2 = 3600
r1 = random.randint(0, 6800 - size1)
r2 = random.randint(0, 7200 - size2)
image = np.float32(cv2.imread(self.path+"/JPEGImages/"+self.__data[index]+".bmp"))
image = image.swapaxes(1, 2).swapaxes(0, 1)
image = image[3, r1:r1+size1, r2:r2+size2]
mask = Image.open(self.path+"/SegmentationClass/"+self.__data[index]+".png")
mask = np.int32(np.asarray(mask))
print(image.shape)
print(mask.shape)
mask = mask[r1:r1+size1, r2:r2+size2]
return image, mask
def __len__(self):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment