How to convert 1D binary data matrix to 2D image matrix?
Show older comments
I have a one-dimensional matrix of size 256X256X8. It has a string of 0 and 1 of the said length. I want to form an 2D Image matrix of size 256x256 from the previous matrix with each eight bits in the original matrix representing an integer in the final matrix. Is there any way to do it?
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 4 Jan 2013
[ii,jj]=find(ones(256,256));
a=randi(2,256,256,8)-1;
b=cell2mat(arrayfun(@(x,y) a(x,y,1:8),ii,jj,'un',0)' );
out=bin2dec(num2str(reshape(b,256*256,8)));
res=zeros(256,256);
res(1:256*256)=out
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!