当前位置:网站首页>Matlab: convert PNG pictures into txt files

Matlab: convert PNG pictures into txt files

2022-07-23 13:51:00 Liu Yaner

Preface

Text

clc;
clear;
close all;

a=imread('che.png');
% Extract the three channel information of the image 
channel_R=a;
channel_G=a;
channel_B=a;

% Separate 3 Values for channels =0, Extract R、G、B passageway 
%R
channel_R(:,:,2)=0;
channel_R(:,:,3)=0;
gray_R=rgb2gray(channel_R);% Convert to grayscale value 
bin_R=dec2bin(gray_R');% Convert to binary  dlmwrite('E:\FPGA\picture_tuuuuu\che_R.txt',bin_R,'delimiter','','newline','pc');
%G
channel_G(:,:,1)=0;
channel_G(:,:,3)=0;
gray_G=rgb2gray(channel_G);
bin_G=dec2bin(gray_G'); dlmwrite('E:\FPGA\picture_tuuuuu\che_G.txt',bin_G,'delimiter','','newline','pc');
%B
channel_B(:,:,1)=0;
channel_B(:,:,2)=0;
gray_B=rgb2gray(channel_B);
bin_B=dec2bin(gray_B'); dlmwrite('E:\FPGA\picture_tuuuuu\che_B.txt',bin_B,'delimiter','','newline','pc');

%  Display images 
subplot(2,2,1);
imshow(channel_R,[]);
title('R passageway ');
subplot(2,2,2);
imshow(channel_G,[]);
title('G passageway ');
subplot(2,2,3);
imshow(channel_B,[]);
title('B passageway ');
subplot(2,2,4);
imshow(a,[]);
title(' Original picture ');

原网站

版权声明
本文为[Liu Yaner]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230719461857.html