Matlab 生成 圖片的coe檔案初始化xilinx rom

lenlendenuan發表於2015-04-27
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格式即可

相關文章