MATLAB学习(3)

MATLAB学习(3)

大家好,又见面了,我是全栈君,祝每个程序员都可以多学几门语言。

matlab读取图像并转化为灰度图像

image = imread('C:\Users\Administrator\Desktop\图像降噪\src\original image\100.png');
image = rgb2gray(image);
image = imread('C:\Users\Administrator\Desktop\图像降噪\src\original image\1.bmp');
image = rgb2gray(image);
//% figure ,imshow(image);
//% dlmwrite('filename.txt', image, ',', 0, 0) 
//% image = image';
figure ,imshow(image);
fid  = fopen('exp.txt','w');    fprintf(fid,'%x ',image);    fclose(fid); //%将图像iamge依照十六进制写入exp.txt 文件
fid1 = fopen('exp.txt','r');  varargout = fscanf(fid1, '%x',[256,256]);    fclose (fid1);     
varargout =  uint8(round(varargout))                      //%将读取的图像double类型转换为uint8
figure,imshow(varargout),title('show varargout');
fid2 = fopen('exp1.txt','w');   fprintf(fid2,'%d ',image);   fclose(fid2); //%将图像iamge依照十  进制写入exp1.txt文件
A =load('exp1.txt');                                                       //%读取exp.txt数据
image2 = zeros(256,256,'uint8');
for i = 1 : 256
    for j = 1 : 256
        image2(j,i) = A((i-1)*256+j);                                      //%读取一维数组1x65535 到矩阵【256 256】
    end
end
figure,imshow(image2),title('show image2');


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/118720.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号