how to convert decimal values into 8bit binary values in a 256*256 matrix.

i have taken a 256*256 image and found each of the pixel values. now i need to convert each of these pixel values into 8 bit binary sequence and display it as a 256*256 matrix. i have a problem here...i have used a for loop to compute binary sequence of each value..but only the last value is displayed...please help..the code is as follows
>>a=imread('C:\Users\a.png');
>>disp(a);
>>for i=1:256
>>for j=1:256
>>b= de2bi(a(i,j),8);
>>disp(b)
>>end
>> end
thanks in advance..

 採用された回答

Pratik Bajaria
Pratik Bajaria 2014 年 8 月 12 日
編集済み: Pratik Bajaria 2014 年 8 月 12 日

0 投票

Its Pretty Simple. You have not made 'b' into an array. do it and its all done.
i.e. Change it to the following
a=imread('C:\Users\a.png'); disp(a); for i=1:256 for j=1:256 b(i,j,:) = de2bi(a(i,j),8); disp(b) end end
Please let me know if in case of further doubts.
Regards, Pratik

6 件のコメント

Abirami
Abirami 2014 年 8 月 12 日
thank u it worked...but im getting only one bit result for each....pls suggest any edits so that i get 8 bit sequence for each pixel value.....
Pratik Bajaria
Pratik Bajaria 2014 年 8 月 13 日
I think you might have skipped the 3rd dimension. Just take this code and copy paste it. It will work. a=imread('C:\Users\a.png'); disp(a); for i=1:256 for j=1:256 b(i,j,:) = de2bi(a(i,j),8); disp(b) end end
What i assume is that you might have skipped ' b(i,j,:) ' the colon is 3rd dimension, which is why you are getting only one bit. Change it and its done.
Please let me know in case of further doubts.
Regards, Pratik
Abirami
Abirami 2014 年 8 月 13 日
This code runs but no 8 bit sequences...pls help..thanks in advance
Pratik Bajaria
Pratik Bajaria 2014 年 8 月 13 日
Did you try the 3rd dimension thing? In the sense, the 8-bit sequence lies in b(i,j,:). i.e. all the 3rd dimension elements of i-th row and j-th column. so for a's i,jth pixels corresponding 8-bit sequence lies in b's i,j,:th entries. I hope i am clear now. Please let me know if it still is unclear.
Regards, Pratik
Abirami
Abirami 2014 年 8 月 13 日
Thank u so much....got the 8bit sequences...
diwa
diwa 2017 年 12 月 1 日
Plzz tell me how can I get maximum value among all these binary values of 8 bit

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2014 年 8 月 12 日

コメント済み:

2017 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by