I want to convert a matlab figure into a binary column vector as would be produced by fread

조회 수: 6 (최근 30일)
I have generated a plot in matlab:
fig = surf(peaks)
I need it to be in the form of a column vector in order to be used as input for the following base64 encoding function:
str64 = matlab.net.base64encode(im_uint8);
The way I am currently doing it is by first saving the plot as png and then reading the binary file as follow:
saveas(fig,'plot1.png')
fid = fopen( 'plot1.png', 'r' );
im = fread(fid);
im_uint8 = uint8(im);
fclose(fid);
Then I can easily call the encoding function. The thing is this saving/reading steps take quite sometimes and I would like to avoid them. I have tried without sucess so far to go from the variable fig above to the variable im.
Is there anyone with a solution for this?
PS: I do not have the image processing toolbox.

답변 (1개)

Image Analyst
Image Analyst 2022년 5월 3일
Perhaps you want this:
p = uint8(peaks(:)); % p will be a uint8 column vector of your data.
  댓글 수: 2
Tulkkas
Tulkkas 2022년 5월 3일
It is going into that direction but it misses I gues the PNG encoding. Basically your p vetor is of size 1406520x1 where the variable im that I read using fred is of size 23473x1. If I tried to encode the p as you proposed using base64 encoding, it does get properly decoded after.
Tulkkas
Tulkkas 2022년 5월 10일
Basically the end question, is there a way to encode a figure from matlab workspace using the base64 encoding without exporting first the figure in png or jpeg and read it after?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by