Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary segmentation,mcc for category is nan #70

Open
idazhuang opened this issue Jan 26, 2022 · 0 comments
Open

binary segmentation,mcc for category is nan #70

idazhuang opened this issue Jan 26, 2022 · 0 comments

Comments

@idazhuang
Copy link

idazhuang commented Jan 26, 2022

UD1XBYJ1CQ )(3(N5M$0W
I want to do edge segmentation of rocks,but got this error.
before this,I did the region segmentation of rocks in the same rock picture. Didn’t get this error.

I used the following method to transform json to label.

ensure_dir(INPUT_DIR)

# ensure_dir(OUTPUT_DIR)
category_types = ["background", "chips"]
# empty_dir(OUTPUT_DIR)
# empty_dir(label_DIR)
# empty_dir(side_DIR)
""" Browse through all marked json files """
for file in iglob(INPUT_DIR + '/*.json'):
    with open(file, 'r', encoding='utf-8') as f:

        """ Load json files """
        data = json.load(f)

        """ Save image file """
        j_name = file.split("\\")[-1]
        ts = j_name.split(".")
        title = ts[0]
        file_name = join(img_DIR, "%s.jpg"%title)
        print(file_name, file)
        img_ori = cv2.imread(file_name, cv2.IMREAD_GRAYSCALE)  #3通道变灰度图单通道
        #cv2.imshow('a',img_ori)
        size_ori = img_ori.shape
        #print(size_ori)
        """ Get image width x height """
        mask = np.zeros((size_ori[0], size_ori[1]), dtype="uint8") #全黑图
        sideImg = np.zeros((size_ori[0], size_ori[1]), dtype="uint8")

        """ Process each shape (annotation) """
        for shape in data['shapes']:
            category = shape["label"]
            points = shape["points"]
            # 填充
            points_array = np.array(points, dtype=np.int32)
            mask = cv2.fillPoly(mask, [points_array], (255, 255, 255), category_types.index(category))
            sideImg = cv2.drawContours(sideImg, [points_array], -1, (255, 255, 255), 3, category_types.index(category))



        # cv2.imshow("mak:", mask)
        # cv2.polylines
        save_name = join(label_DIR, title) + ".png"
        cv2.imwrite(save_name, mask)
        save_name = join(side_DIR, title) + ".png"
        cv2.imwrite(save_name, sideImg)

image
image

Anyone met the same error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant