使用其他渠道保存图像OpenCV

时间:2018-12-30 07:50:37

标签: python opencv

我正在尝试保存此图像enter image description here

使用此代码:

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)

但是图像显示如下: enter image description here

这与默认保存通道有关吗? 如何保存使用imshow()打印的完全相同的图片。

致谢

0 个答案:

没有答案