matlab读取RGB888或RGB565像素文件并绘图

1、matlab下,通过读取txt文件中的RGB888格式的像素文件绘图,并将其转换为RGB565格式后再绘图。代码如下:

clear all;
close all;
a=textread('E:\matlab\rst.txt','%6s')';%以字符形式打开文件 
Images_Dec=hex2dec(a)'; %16进制转化为10进制数,存入Images_Dec矩阵 
for i=1:576
    for j=1:1440
        for k=1:3
            A(i,j,k)=Images_Dec((i-1)*1440*3+(j-1)*3+k);
        end
    end
end


fr=A(:,:,1);
fg=A(:,:,2);
fb=A(:,:,3);
ar=fr*(31/255);
ag=fg*(63/255);
ab=fb*(31/255);
imgRGB565 = cat(3,ar,ag,ab);  %# Concatenate along the third dimension
%imwrite(imgRGB565,'myImage.bmp');   %# Output the image to a file
subplot(2,1,1);
imshow(A);
subplot(2,1,2);
imshow(imgRGB565);

rst.txt中文件内容如下图所示:



2、matlab下,通过读取txt文件中的RGB565格式的像素文件,从中解析出RGB888像素后绘图,并将其转换为RGB565格式后再绘图。代码如下:

clear all;
close all;
a=textread('E:\matlab\a.txt','%4s')';%以字符形式打开文件 
Images_Dec=hex2dec(a)'; %16进制转化为10进制数,存入Images_Dec矩阵 


A=zeros(576,720);
for i=1:576
    for j=1:720
        A(i,j)=Images_Dec((i-1)*720+j);
    end
end


imgR = bitshift(bitand(A,63488),-8);  %# Red component
imgG = bitshift(bitand(A,2016),-3);   %# Green component
imgB = bitshift(bitand(A,31),3);      %# Blue component
im888 = cat(3,imgR,imgG,imgB); 


ar=imgR*(31/255);
ag=imgG*(63/255);
ab=imgB*(31/255);
imgRGB565 = cat(3,ar,ag,ab);  %# Concatenate along the third dimension


subplot(2,1,1);
imshow(imgRGB565);
subplot(2,1,2);
imshow(im888);

a.txt中文件的内容如下:



  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值