【MATLAB】常用命令快速入门,国赛加油 (6)

image

% RGB的分离 R = pepper(:,:,1); G = pepper(:,:,2); B = pepper(:,:,3); subplot(2,2,1); imshow(pepper); title("original"); subplot(2,2,2); imshow(R); title("R"); subplot(2,2,3); imshow(G); title("G"); subplot(2,2,4); imshow(B); title("B");

image

% RGB的合并 subplot(1,1,1); rgb(:,:,1) = R; rgb(:,:,2) = G; rgb(:,:,3) = B; imshow(rgb);

image

彩色图转灰度图 % rgb2gray 彩色图转灰度图 pepper_gray = rgb2gray(pepper); imshow(pepper_gray)

image

二值化 [row, col] = size(pepper_gray); for i = 1:row for j = 1:col if pepper(i,j) > 128 pepper_gray(i,j) = 1; else pepper_gray(i,j) = 0; end end end figure; pepper_bw = logical(pepper_gray); imshow(pepper_bw);

image

% imbinarize 系统自带的二值化方式 % method -用于二值化图像的方法: 'global'(默认)| 'adaptive' % 'Sensitivity' -自适应阈值的敏感度因子: 0.50(默认)| [0,1]范围内的数值 % 'ForegroundPolarity' -确定哪些像素被视为前景像素: 'bright'(默认)| 'dark ' % 'bright': 前景比背景亮 % 'dark' : 前景比背景暗 pepper_gray = rgb2gray(pepper); bw = imbinarize(pepper_gray, "adaptive","ForegroundPolarity","dark","Sensitivity",0.4); imshow(bw)

image

二值化的应用:突出文字

I = imread('printedtext.png'); imshow(I);

image

bw = imbinarize(I,"adaptive","ForegroundPolarity","dark","Sensitivity",0.4); imshow(bw)

image

图像处理相关函数 调整图片大小 % imresize 调整图片大小 % I = imresize(pic, scale); scale为缩放倍数 % I = imresize(pic, [row col]); 调整大小为row*col I = imread("peppers.png"); imshow(I)

image

J = imresize(I, 0.5); imshow(J)

image

K = imresize(I, [200 200]); imshow(K)

image

旋转图像 % I = imrotate(pic,angle); angle为旋转的角度 J = imrotate(I, 45); imshow(J)

image

图像的加减乘除 % imadd() 两幅图像相加时,要求大小一致 % imsubtract() 矩阵的减法 % immultiply() 矩阵的点乘 % imdivide() 矩阵的点除 I = imread('rice.png'); imshow(I)

image

J = imread('cameraman.tif'); imshow(J)

image

K = imadd(I,J); imshow(K)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwydsz.html