clear all % clear all data RGB=imread('lake.bmp'); % load bitmap into RGB array fid=fopen('lake.coe','w'); % create and open lake.coe file in write mode fprintf(fid,'%s\r\n','MEMORY_INITIALIZATION_RADIX=2;'); fprintf(fid,'%s\r\n','MEMORY_INITIALIZATION_VECTOR='); % save information about radix and sentence preceding the data % vector for w=1:64 % loops for reading data from BMP file for k=1:64 % w - rows, k - kolumns clear r % clear g % clear r, g, b variables clear b % r=dec2bin((RGB(w,k,1)/32)-1,3); % conversion of decimal value % of red color (R) % to 3-bit binary value g=dec2bin((RGB(w,k,2)/32)-1,3); % conversion of decimal value % of green color (G) % to 3-bit binary value b=dec2bin((RGB(w,k,3)/64)-1,2); % conversion of decimal value % of blue color (B) % to 2-bit binary value fprintf(fid,'%s',r); % save binary data fprintf(fid,'%s',g); % of each color with new length fprintf(fid,'%s',b); % into COE file fprintf(fid,'\r\n'); % end file end end fclose(fid); % close COE file