目的:
一、介紹數字圖像
- 介紹數字圖像
- 讀取和展示數字圖像
- 圖像的四則運算
數字圖像的分類:
- Binary:每個像素只有黑色和白色
- Grayscale:每個像素是灰色,範圍是0到255
- True color or RGB:每個像素有特定的顏色,顏色包含red、green和blue。
Binary image:圖像的像素值只有0和1,即黑和白
Greyscale image:圖像的像素是在0-255之間。
Color image: 有三個通道,分別是R、G、B合在一起的圖像
二、讀取和展示數字圖像
- Read an image:imread()
- Show an image:imshow()
clear,close all
I = imread('pout.tif'); % 讀取圖片,存儲爲矩陣I
imshow(I); % 展示圖片
將像素值爲偶數的改爲0
clear all
I = imread('haha.png');
figure(1)
imshow(I);
for i=1:size(I,1)
for j=1:size(I,2)
if (rem(i,2)==0 && rem(j,2)==0)
I(i,j) = 0;
end
end
end
figure(2)
imshow(I)
查看圖片的信息:
imageinfo('haha.png')
imtool('haha.png')
三、圖像的處理
濾波器處理圖像:Gaussian filter,median filter,Wiener filter:
圖像的四則運算:+ - * /
圖像的相關操作:
Image Multiplication: immultiply()
%% 讓圖像更亮
I = imread('haha.png');
subplot(1,2,1);imshow(I);
J = immultiply(I, 1.5); % 每個像素乘1.5
subplot(1,2,2);imshow(J);
Image Histogram:imhist()
I = imread('pout.tif');
imhist(I);
Histogram Equalization:histeq()
Geometric Transformation:改變圖像的形狀,例如:旋轉
Image Rotation: imrotate()
%% 旋轉
I = imread('haha.png');
subplot(1,2,1);imshow(I);
J = imrotate(I, 35, 'bilinear');
subplot(1,2,2);imshow(J);
size(I);
size(J);
存儲圖像:imwrite()
支持格式:‘bmp', 'gif', 'hdf', 'jpg', 'jpeg', 'jp2', 'jpx', 'pcx', 'pnm', 'ppm', 'ras', 'tif', 'tiff', 'xwd'
imwrite(I, 'pout2.png');