MATLAB Answers

How to extact bits from an image to a string separated with commas?

1 ビュー (過去 30 日間)
mikel mikel
mikel mikel 2021 年 6 月 17 日
編集済み: Jan 2021 年 6 月 18 日
Hello,
I am trying to get an image bits in a string separated with commas.
My code is the following:
Image = imread('calle1.png');
COL=640;
ROW=360;
a=zeros(1,COL*ROW);
n=1;
for i=1:1:ROW
for j=1:COL
a(1,n)=Image(i,j);
n=n+1;
end
end
% aCSV = regexprep(num2str(a), '\s*', ',');
allOneString = sprintf('%.0f,' , a);
allOneString = allOneString(1:end-1);% strip final comma
When I try to open the string it says: cannot display summaries of variables with more than 524288 elements. How can I do it?
Thanks

回答 (1 件)

Jan
Jan 2021 年 6 月 18 日
編集済み: Jan 2021 年 6 月 18 日
Your code produces a CHAR vector (a "string" is a different class). Now you explain, that there is an error, when you "try to open the string". But what does this mean? Where do you try this in which way? What do you want to see?
A hint: You can replace:
COL=640;
ROW=360;
a=zeros(1,COL*ROW);
n=1;
for i=1:1:ROW
for j=1:COL
a(1,n)=Image(i,j);
n=n+1;
end
end
by:
a = reshape(Image.', 1, []);
But there is no need to do this. Simply use:
Image = imread('calle1.png');
allOneString = sprintf('%d,', Image.');
allOneString(end) = [];

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by