Matlab 生成 图片的coe文件初始化xilinx rom

a=imread('flower.jpg');
g=rgb2gray(a);
gb=zeros(256,256);
gc=cell(256,256);

%gb=dec2bin(gt,8);
%d=str2double(gb);
for i=1:256
     for j=1:256
         gc(i,j)=  cellstr(dec2bin(g(i,j),8));
     end
end

file=fopen('rom64_512.txt','w+');
fprintf(file,'memory_initialization_radix = 2; \n');
fprintf(file,'memory_initialization_vector = \n');
for i=1:16
    for j=1:8:249
        for k=j:j+7
           fprintf(file,'%s',gc{i,k});
        end
         fprintf(file,',');
    end
end

fclose(file);

生成txt文件打开把最后的逗号改为分号,保存为coe格式即可

你可能感兴趣的:(matlab)