フィルターのクリア

Load and display bitmap file using Fread

12 ビュー (過去 30 日間)
Tina
Tina 2021 年 11 月 13 日
コメント済み: Tina 2021 年 11 月 14 日
Bmp files have header usually of 54 bytes.How can i get rid of it to display my bmp by using fread.i tried by following code.but the image i get has disorted color.How can i get rid of header and reshape in a way that color dont get disturbed
fid=fopen("m.bmp",'rb')
f=fread(fid,'uint8')
a=reshape(f,512,512,3)

採用された回答

Walter Roberson
Walter Roberson 2021 年 11 月 14 日
編集済み: Walter Roberson 2021 年 11 月 14 日
Pixel Data
an array of bytes that defines the bitmap bits. These are the actual image data, represented by consecutive rows, or "scan lines," of the bitmap. Each scan line consists of consecutive bytes representing the pixels in the scan line, in left-to-right order. The system maps pixels beginning with the bottom scan line of the rectangular region and ending with the top scan line.
[...]
RGB values are stored backwards i.e. BGR.
(I interpret this as meaning that you have the B, G, R for the left-bottom pixel, then the B, G, R for the one to the right of that, and so on, then the B, G, R for the second-from the bottom left pixel, and so on. Eventually the end of the file would be B, G, R for the top right corner.)
  1 件のコメント
Tina
Tina 2021 年 11 月 14 日
Thankyou

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

その他の回答 (1 件)

Rik
Rik 2021 年 11 月 13 日
You should reshape the data, not the fid. To remove the first 54 bytes you can use fseek, or just skip it from your array:
fid=fopen("m.bmp",'rb');
f=fread(fid,'uint8');
fclose(fid);
a=reshape(f(55:end),512,512,3);
  2 件のコメント
Tina
Tina 2021 年 11 月 13 日
I tried doing this but the image I get had all of the color are scattered . When I compared it with imread() .the arrangements of value inside the variable were very different.
Rik
Rik 2021 年 11 月 14 日
Then the arrangement might be different from what reshape assumes. Have you tried different orientations?

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by