matlab将图像读写为二进制格式

记录下来,避免重复劳动,同时帮助像我一样需要帮助的人

clc;clear;close all
%% 写图像
img = imread('1.bmp');
fileID1=fopen('test.bin','w');
A = rgb2gray(img);
fwrite(fileID1,A');
fclose(fileID1);

%% 读图像
fileID2=fopen('test.bin','r');
B=fread(fileID2);
fclose(fileID2);
B = uint8(reshape(B,1024,768))';
%% 绘图
figure
subplot(1,2,1)
imshow(A)
subplot(1,2,2)
imshow(B)
%%

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章