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

2 views (last 30 days)
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

Answers (1)

Jan
Jan on 18 Jun 2021
Edited: Jan on 18 Jun 2021
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) = [];

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!