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

How do you convert the polygons from .json format to .mat file used in DOOBNet ? #1

Closed
MichaelRamamonjisoa opened this issue Mar 13, 2019 · 3 comments

Comments

@MichaelRamamonjisoa
Copy link

Hello,

Thank you for your labeling tool and your paper DOOBNet.
I have labeled a few of my images, but I would like to extract them as orientation and edge images as you did in your paper.

Do you have some code to do this ?

Thanks !

@GuoxiaWang
Copy link
Owner

@MichaelRamamonjisoa
Yes, I have the code. If you need, I can push the code to the Repo. But the code in my disk, so I need to find out.

If you can not to wait, you can write the orientation conversion code by yourself according to the code atan formulas. For the edge image, you just need draw the polygons on a binary image.

Thank you for reading my paper, I hope my paper and label tool can help you!

@MichaelRamamonjisoa
Copy link
Author

Thank you for your reply. I have indeed drawn boundaries as you said. However I did not try to export orientations, since I do not need it yet. I'd be glad if you could push your code to the Repo since I will probably use it for next work.

I have another request, which I can put in another issue if you want since it will probably require a specific commit.

@GuoxiaWang
Copy link
Owner

@MichaelRamamonjisoa

I have found the calculation code of orientations from my driven disk. Here is the code snippet, and I will don't push the code to the Repo:

def get_edge_and_ori_map(obj):

    imsize = (obj.imgHeight, obj.imgWidth)
    edge_map = np.zeros(imsize, dtype=np.uint8)
    ori_map = np.zeros(imsize, dtype=np.float32)

    for edge in obj.boundaries.polygon:
        npix = len(edge)
        for idx, pt in enumerate(edge):
            
            # First, we calculate orientation
            idx0 = max(idx-5, 0)
            pt0 = edge[idx0]
            idx1 = min(idx+5, npix-1)
            pt1 = edge[idx1]

            theta = math.atan2(pt1.y-pt0.y, pt1.x-pt0.x)
            ori_map[pt.y][pt.x] = theta
            edge_map[pt.y][pt.x] = 1

    return edge_map, ori_map

and you can invoke the function like this:

    from lib.annotation import *

    ann = Annotation()
    ann.fromJsonFile(json_file_name)
    edge_map, ori_map = get_edge_and_ori_map(ann)

    height, width = edge_map.shape
    label = np.zeros((1, 2, height, width), dtype=np.float32)
    label[0, 0, ...] = edge_map
    label[0, 1, ...] = ori_map

    with h5py.File(h5_filename, 'w') as f:
        f['label'] = label

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

2 participants