1、原理
许多图片处理工作都对图像类型有特定的要求。
其转换关系为下:
2、代码
clear all;
%读进图像
[filename, pathname] = uigetfile({'*.jpg'; '*.bmp'; '*.gif'}, '选择原图片');
picture = imread([pathname, filename]);
%真彩图像转换为索引图像——X
map=jet(256);
X=dither(picture,map);
%彩色图片转化为灰度图片——I
I = rgb2gray(picture);
%%真彩图片转化成二值图像——Q
level = graythresh(I);%使用最大类间方差法找到图片的一个合适的阈值
Q = im2bw(picture,level);%将灰度图像 picture 转换为二进制图像
figure(1)
subplot(1,4,1);
imshow(picture);
title('原图片');
subplot(1,4,2);
imshow(X);
title('索引图片');
subplot(1,4,3);
imshow(I);
title('灰度图片');
subplot(1,4,4);
imshow(Q);
title('二值图片');
3、结果