def open(self, filename):
p = self.preferences
# open in 8 bit?
if p.p8bit.value():
col = 0
else:
col = cv2.IMREAD_ANYDEPTH
if p.pGrey.value() and not p.pSplitColors.value():
col = col | cv2.IMREAD_GRAYSCALE
else:
col |= cv2.IMREAD_ANYCOLOR
# OPEN
img = cv2.imread(str(filename), col) # cv2.IMREAD_UNCHANGED)
if img is None:
raise Exception("image '%s' doesn't exist" % filename)
# crop
if p.pCrop.value():
r = (p.pCropX0.value(),
p.pCropX1.value(),
p.pCropY0.value(),
p.pCropY1.value())
img = img[r[0]:r[1], r[2]:r[3]]
# resize
if p.pResize.value():
img = cv2.resize(img, (p.pResizeX.value(), p.pResizeY.value()))
labels = None
if img.ndim == 3:
if p.pSplitColors.value():
img = np.transpose(img, axes=(2, 0, 1))
labels = ['blue', 'green', 'red']
else:
# rgb convention
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# change data type to float
img = self.toFloat(img)
return img, labels
评论列表
文章目录