I have the following base64 string which is an image: Link to base64 image and I wish to get back the image in Matlab. I used the following website to check if the image is valid: https://codebeautify.org/base64-to-image-converter and it worked without any problems.
When downloading the image after decoding it from the website, I get the following information:
The image has the size of 512x512 and a bit depth of 32bit. Furthermore, I know that this is a color image.
I have tried the approach mentioned here Decode base64 to RGB image in matlab which utilizes the Apache library. However, when using the following code:
result = native2unicode(base64.decode(uint8(img)).');
where img
is the base64 string, result will be a 599636
long char array. However, 512*512*3 = 786432
.
I am wondering how to proceed from here to get the 512*512 color image ?
Edit:
My current workaround is to write the base64 coded image to a text file, and read it out via python, and write it to the disk as image, and reload it in matlab. Which works, but is very very ugly. In Python it works with the simple script:
import base64
f = open('test.txt','r')
message = f.read()
print(message)
with open("imageToSave.png", "wb") as fh:
fh.write(base64.decodebytes(bytearray(message,'utf-8')))