Matlab基础:图像类型的转换

%% 学习目标:图像类型的转换

%% 将索引图像转化为RGB图像 
clear all;
close all;
[X,map] = imread('trees.tif','tif');  %读取索引图像
RGB = ind2rgb(X,map);%把索引图像转换成RGB格式。
figure;
imshow(RGB);
%set(gcf,'position',[500,500,600,600]);

%% 将RGB图像转换成索引图像
clear all;
close all;
RGB = imread('peppers.png'); %读取RGB图像
[X,map] = rgb2ind(RGB,12); %将RGB图像转换为索引图像, 调色板大小是12行,行越大越清晰。
figure;
imshow(X,map);

%% 将RGB图像转换为灰度图像
clear all;
close all;
RGB = imread('peppers.png','png');
I = rgb2gray(RGB);
figure;
imshow(I);

%% 将索引图像转换为灰度图像
clear all;
close all;
[X,map] = imread('trees.tif','tif');
newmap = rgb2gray(map);%只将调色板转换为灰度,实际上map中存的就是rgb。
figure;
imshow(X,newmap);

%% 将索引图像转换为灰度图像
clear all;
close all;
[X,map] = imread('trees.tif','tif');
I = ind2gray(X,map);
figure;
imshow(I);

%% 将灰度图像转换为索引图像
clear all;
close all;
X = imread('rice.png'); %读取一个灰度图像
Y = grayslice(X,12);  %将灰度图像转换为索引图像
figure;
imshow(Y,jet(12));  %通过调色板jet给图像上颜色

%% 将RGB图像转换为二值图像
clear all;
close all;
RGB = imread('peppers.png','png');
bw = im2bw(RGB,0.4); % 归一化阀值是0.4 (大于0.4为1,否则为0)  二值图像只有黑色和白色
figure;
imshow(bw);

%% 将数据矩阵转换为灰度图像
clear all;
close all;
A = rand(400,400); % 建立一个数据矩阵
I = mat2gray(A); %将数据矩阵转换为灰度图像
figure;
imshow(I);




 

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值