在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2101|回复: 0

求大神指导 这个 程序 怎么改成 输出 3位的RGB 值

[复制链接]
发表于 2014-6-2 11:15:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
function img2 = IMG2coe8(imgfile,outfile)

img=imread('test3.jpg');
height = size(img,1);
width = size(img,2);
s = fopen('test3.coe','wb');
fprintf(s,'%s\n',';VGA Memory Map');
fprintf(s,'%s\n',';.COE file with hex coefficients');
fprintf(s,';Height: %d,Width: %d\n\n',height,width);
fprintf(s,'%s\n','memory_initialization_radix=16;');
fprintf(s,'%s\n','memory_initialization_vector=');

cnt = 0;
img2 =img;
for r=1 :height
    for c=1:width
        cnt = cnt+1;
        R = img(r,c,1);
        G = img(r,c,2);
        B = img(r,c,3);
        Rb = dec2bin(double(R),8);
        Gb = dec2bin(double(G),8);
        Bb = dec2bin(double(B),8);
        img2(r,c,1)=bin2dec([Rb(1:3) '00000']);
        img2(r,c,2)=bin2dec([Gb(1:3) '00000']);
        img2(r,c,3)=bin2dec([Bb(1:2) '00000']);
        Outbyte = [Rb(1:3) Gb(1:3) Bb(1:2)];
        if (Outbyte(1:4)=='0000')
            fprintf(s,'0%X',bin2dec(Outbyte));
        else
            fprintf(s,'%X',bin2dec(Outbyte));
        end
        if((c==width)&&(r==height))
            fprintf(s,'%c',';');
        else
            if(mod(cnt,32)==0)
                fprintf(s,'%c\n',',');
            else
                fprintf(s,'%c',',');
            end
        end
    end
end

fclose(s);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-28 06:01 , Processed in 0.021664 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表