Adding 0s and 1s to Bit Data

2 ビュー (過去 30 日間)
Matlab Student
Matlab Student 2016 年 10 月 18 日
コメント済み: Matlab Student 2016 年 10 月 19 日
I am using imgread to read binary 0,1 data and have to ultimately send it from an FPGA to a monitor using VGA Interface.The entire process would be greatly facilitated if I could add zeros to a 480x640 matrix(had to transpose original 640x480 because fprintf prints column wise ?).I want to know how to write 0 as 000 or 1 as 111 (corresponding to black and white RGB values)?
fid = fopen('3bitbinary.txt','w');
fprintf("","","");
fclose(fid);
Thanks!

採用された回答

Chaya N
Chaya N 2016 年 10 月 18 日
From what I understand, it sounds like you need to generate a m x n x 3 matrix and the easiest way might be to simply do a repmat of your matrix. It should look something like this:
output_matrix = repmat(input_matrix,1,1,3);
When writing to file, the values have to be written depth-wise so use:
fprintf('%d %d %d\n', permute(output_matrix,[3 2 1]))
I hope this helps!
  4 件のコメント
Chaya N
Chaya N 2016 年 10 月 18 日
Alternately, you could try the following:
fprintf('%d%d%d\n', permute(kron(input_matrix,[1 1 1]),[2 1]))
This works too.
Matlab Student
Matlab Student 2016 年 10 月 19 日
Wonderful! Thank you!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 19 日
Not sure what you're asking, but perhaps you're looking for padarray(). This function will add zeros to a layer around the outside edges of the image, whichever of the 4 sides you specify.

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by