Decoding base64 data from a txt/xml file. base64decode is slow.

8 次查看(过去 30 天)
I have a 2801x2801 sized image in a base64 notation that has been generated by some VB script and is then stored in an xml text file. I use the follwing code:
filename = 'measurement_data.txt'
xDoc = xmlread(filename);
% entries = TreeNode.getElementsByTagName('data');
entries = xDoc.getElementsByTagName('data');
% entries = entries1.getElementsByTagName('data');
data = zeros(52,52);
for k=1:entries.getLength-1
a = string(entries.item(k).getTextContent);
b = matlab.net.base64decode(strip(a,'right','='));
data(k,:) = typecast(b,'int16');
end
It takes between 20 and 30 seconds to read in the image and most of that time (99%) is spent using matlab.net.base64decode. It takes a little less than 10ms per call. I have attached a txt file with a smaller image (51x51) and for this image it only take 0.4 ms per call to base64decode. I am sure there must be a better/faster method. Any help is appreciated.
Thanks, Felix
  1 个评论
Arvind Narayanan
Arvind Narayanan 2017-10-27
Hi,
We would need the original image which you used to generate the XML file to be able to reproduce the issue. Currently, the code doesn't run for me as the image is missing, which leads to the b array being defined incorrectly. Am I missing something?

请先登录,再进行评论。

回答(1 个)

Felix123
Felix123 2017-11-2
Hey Arvind, thanks for having a look. The problem was, that I only put in a smaller image as an example, so I had to change the size of data. I updated the code and it should run now.
Felix

类别

Help CenterFile Exchange 中查找有关 Call Web Services from MATLAB Using HTTP 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by