bitmap to RGB array

I have written the following code to input a bitmap image and output a '.ppm' file. For this I first read the rgb values and then output them to a ppm file. I manually add P3 133 100 %dimensions of the image 255 to the top of the .ppm file. Still, .ppm file is incorrect. Do, I need to do anything else to extract rgb values in an array from bitmap image.
I=imread('butterfly.bmp','bmp');
[n,m]=size(I); %n=100; m=133
fName = 'test.ppm';
fid = fopen(fName,'w');
for i=1:1:n
for j=1:1:m
fprintf(fid,'%3d ',I(i,j));
if(mod(j,3) == 0)
fprintf(fid,' ');
end
end if true
% code
end
fprintf(fid,'\n');
end

 採用された回答

Image Analyst
Image Analyst 2012 年 11 月 4 日

0 投票

I don't know why you want ppm in the first place. What's wrong with the original bmp or an increasingly more common PNG? Anyway, if you need ppm, why not just use imwrite, which can write that format?
imwrite(I, 'butterfly.ppm');

その他の回答 (1 件)

Akshay Singh
Akshay Singh 2012 年 11 月 4 日

0 投票

Thank you very much for the help. So silly of me to forget imwrite. :(

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by