开发者

Matlab writing image data to a binary file

开发者 https://www.devze.com 2023-02-15 14:56 出处:网络
I am not very good at Matlab and I needed help with the following code. I have the image data from a set of images and I want to save these to a binary file along with a file signature showing how th

I am not very good at Matlab and I needed help with the following code.

I have the image data from a set of images and I want to save these to a binary file along with a file signature showing how the data has been saved in the file.

For example, say I have an image that is divided such that it is said to consist of 4 rows and 4 columns so that the image is made up of 16 smaller images. The image data for these smaller images is saved in a structure as follows:

data = struct('imageTitleFinal', {}, 'imageDataFinal', {});

for ro开发者_开发技巧ws = 1:numberOfRows
        for columns = 1:numberOfColumns
            data(rows,columns).imageTitleFinal = currentTile;
            data(rows,columns).imageDataFinal = currentStructure(rows,columns).imageData;
        end
end

I want to be able to write this image data for each of the smaller images to a binary file and be able to distinguish between the sets of image data within the file. Any help would be much appreciated.


If you HAD to write to a binary file for whatever reasons, you could potentially create your own 'header' for this data.

Write a fixed amount of meta-data for each 'smaller image', this data should have all the information to help you parse your image data. A simple way would be:

-I assume your 'title' is a char array -I assume your data file is a double array -The '|' is just a separator.

|A uint32 with the number of chars in your title|Your title data written as chars| A uint32 with the number of doubles in your data|All your data written as doubles|

Air code:

fopen in append mode
fwrite(fid, numel(title), 'uint32');
fwrite(fid, title,'char'); %assuming ASCII char set
fwrite(fid, numel(data), 'uint32');
fwrite(fid, data, 'double);

You can consider adding more 'meta-data', for example, the size of the data, if your 'smaller images' will not have uniform size.

0

精彩评论

暂无评论...
验证码 换一张
取 消