天天看点

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)

%%

继续阅读