使用此代码:
def get_inputs(filename, pred_folder, truth_folder=None, extend_mask_folder=None):
fid = filename.split(".")[0]
inputs = []
pred = cv2.imread(path.join(pred_folder, filename), cv2.IMREAD_UNCHANGED)
pred_msk = pred / 255.
pred_msk = pred_msk[..., 0] * (1 - pred_msk[..., 1])
pred_msk = 1 * (pred_msk > 0.5)
pred_msk = pred_msk.astype(np.uint8)
y_pred = measure.label(pred_msk, neighbors=8, background=0)
props = measure.regionprops(y_pred)
for i in range(len(props)):
if props[i].area < 10:
y_pred[y_pred == i + 1] = 0
y_pred = measure.label(y_pred, neighbors=8, background=0)
nucl_msk = (255 - pred[..., 0])
nucl_msk = nucl_msk.astype('uint8')
y_pred = watershed(nucl_msk, y_pred, mask=((pred[..., 0] > pixels_threshold)), watershed_line=True)
to_save = y_pred * 255
cv2.imwrite(path.join(postprocess_labels, '{0}.tif'.format(fid)), y_pred * 255)
这与默认保存通道有关吗?
如何保存使用imshow()
打印的完全相同的图片。
致谢