I am trying to convert VIA (VGG Image Annotator) JSON file to Labelme JSON file, but the only problem is imageData attribute in Labelme. I am not able to upload my JSON file into Labelme tool without imageData. Does Anyone has idea how to get imageData or anything which is useful to solve this problem.
LabelMe is an actively developed open source graphical image annotation tool inspired by the app of the same name released in 2012 by MIT CSAIL. It is capable of annotating images for object detection, segmentation, and classification (along with polygon, circle, line, and point annotations).
Labelme is an open source annotation tool based on http://labelme.csail.mit.edu. It was written in Python to support manual image polygonal annotation for object detection, classification, and segmentation. Labelme lets you create various shapes, including polygons, circles, rectangles, lines, line strips, and points.
You were just not lucky enough to find this in Google :) . The functions can be found in , LabelMe's sources:
def img_b64_to_arr(img_b64):
f = io.BytesIO()
f.write(base64.b64decode(img_b64))
img_arr = np.array(PIL.Image.open(f))
return img_arr
def img_arr_to_b64(img_arr):
img_pil = PIL.Image.fromarray(img_arr)
f = io.BytesIO()
img_pil.save(f, format='PNG')
img_bin = f.getvalue()
if hasattr(base64, 'encodebytes'):
img_b64 = base64.encodebytes(img_bin)
else:
img_b64 = base64.encodestring(img_bin)
return img_b64
I had problems with theirs if hasattr(base64, 'encodebytes'):..., it generates superfluous \n and b' ', so I rewrote the second one as
import codecs
def encodeImageForJson(image):
img_pil = PIL.Image.fromarray(image, mode='RGB')
f = io.BytesIO()
img_pil.save(f, format='PNG')
data = f.getvalue()
encData = codecs.encode(data, 'base64').decode()
encData = encData.replace('\n', '')
return encData
First, you shoud install labelme
, then try the following:
data = labelme.LabelFile.load_image_file(img_path)
image_data = base64.b64encode(data).decode('utf-8')
Output is the same as JSON file by manual.
It is called base64 type of an image, you can turn image into base64 data by the following code:
import base64
encoded = base64.b64encode(open(img_path, "rb").read())
print(encoded)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With