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)
%%

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