필터 지우기
필터 지우기

how to convert decimal values into 8bit binary sequence and represent in a 256*256 matrix

조회 수: 32 (최근 30일)
hello
I have used the following code to represent decimal values in a matrix to 8bit binary sequences in place of each value. but im not able to get the 8 bit value...instead i get only one bit answer. also in case an 8bit sequence is obtained how should i represent each sequence separately? please help.
>>clc
>>clear all
>>close all
>>a=imread('C:\Users\Abzz\Desktop\lena.png');
>>imshow(a)
>>disp(a)
>>for i=1:1:256
>>for j=1:1:256
>>b(i,j,:)=dec2bin(a(i,j),8);
>>end
>>end
>>disp(b)
thanks in advance

채택된 답변

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2014년 8월 13일
Hi Abirami,
You are aware that you're making a 256 x 256 x 8 matrix(3D matrix), and that's how it showed on MALTAB when you have a 3D matrix.
A quick solution would be to store it in a cell, so change your code as such
b{i,j,1} = dec2bin(a(i,j),8);
Hope that helps. Good Luck.
  댓글 수: 3
c kdg
c kdg 2017년 4월 3일
How to copy the above output binary sequence to a text file from command window Please reply.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 13일
a=imread('C:\Users\Abzz\Desktop\lena.png');
b=cell2mat(arrayfun(@(x) reshape(dec2bin(x,8)-'0',1,1,8),a,'un',0));

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by