用MATLAB产生VIVADO可用的coe文件

%**************************************************************************
% Generate MIF file
%
%                               resevered by 
%                                   2015.11.09
%**************************************************************************


[FileName,PathName] = uigetfile('*.bmp','Select the *.bmp file'); 
f = fullfile(PathName,filesep,FileName);
fid = fopen(f,'r');
im=imread(f);
%fr=dec2bin(im(:),8);


[r,c,d]=size(im)
red=im;


red(:,:,1)= red(:,:,1);
red(:,:,2)= zeros(r,c);
red(:,:,3)= zeros(r,c);
red=uint8(red);
subplot(1,4,1)
imshow(red);


depth =64; %存储器的单元数
width =64;%数据宽度为8位
%N = 0 :255;
%s =sin(2*pi *N/256);%计算0 ~2*pi之间的sin值
fidc = fopen('64r.coe','wt')
%fprintf(fidc , 'depth = %d;\n',depth);
%fprintf(fidc, 'width = %d;\n',width);
fprintf(fidc, 'MEMORY_INITIALIZATION = 16;\n');
fprintf(fidc,'MEMORY_INITIALIZATION_VECTOR= \n');
%fprintf(fidc,'content begin\n');
%for x = 1 : depth
%    for y=1: width
%   fprintf(fidc,'%d:',(x-1));
%   fprintf(fidc,'%d',im(x,:));
%  fprintf(fidc,'%s,',dec2bin(im(x,y)));
%  fprintf(fidc,'\n');
%   fprintf(fidc,'%d:',(x-1));
%  fprintf(fidc,';\n');
%    end
%end


fprintf(fidc,'%x,\n',red(:,:,1));
%fprintf(fidc, 'end;');
fclose(fidc);
%imshow(uint8(im));

你可能感兴趣的:(用MATLAB产生VIVADO可用的coe文件)