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

조회 수: 7 (최근 30일)
Felix123
Felix123 2017년 10월 23일
답변: Felix123 2017년 11월 2일
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