MATLAB Answers

How do I create RAW image files in MATLAB?

108 views (last 30 days)
I would like to use MATLAB in order to create binary RAW-files to store images.
The images I try to create using FWRITE do not open properly in Adobe Photoshop.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Apr 2017
In order to create RAW-files for images in MATLAB, use the FWRITE function with 'uint8' or 'uint16' as the precision specifier, as in the example below (which creates a black image (all zeros) of size 100x100
 
cmodel=(zeros(300,100,1));
fid=fopen('blackimage.raw','w+');
cnt=fwrite(fid,cmodel,'uint8');
fclose(fid);
  1 Comment
Fady Samann
Fady Samann on 5 Sep 2020
the output image of this code is rotated by 90 degree and flipped compared to the original one!!!

Sign in to comment.

More Answers (1)

Fady Samann
Fady Samann on 5 Sep 2020
Edited: Fady Samann on 5 Sep 2020
To have the image in the correct postion, use matrix transpose in the fwrite.
cmodel=(zeros(300,100,1));
fid=fopen('blackimage.raw','w+');
cnt=fwrite(fid,cmodel.','uint8');
fclose(fid);

Tags

No tags entered yet.

Products


Release

R2006a

Community Treasure Hunt

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

Start Hunting!