实例:彩色图像的锐化
clc;
clear;
%读取经典图像lena.jpg
A = imread('lena.jpg');
figure,imshow(A),title('原图像');
%提取三个通道的像素值
R_A = A(:,:,1);
G_A = A(:,:,2);
B_A = A(:,:,3);
figure
subplot(1,3,1),imshow(R_A),title('R通道');
subplot(1,3,2),imshow(G_A),title('G通道');
subplot(1,3,3),imshow(B_A),title('B通道');
%定义锐化算子
h1 = fspecial('sobel');
h2 = fspecial('prewitt');
%R通道锐化
R_h1 = imfilter(R_A, h1);
R_h2 = imfilter(R_A, h2);
figure,
subplot(1,2,1),imshow(R_h1),title('Sobel R通道锐化');
subplot(1,2,2),imshow(R_h2),title('Prewitt R通道锐化');
%G通道锐化
G_h1 = imfilter(G_A, h1);
G_h2 = imfilter(G_A, h2);
figure,
subplot(1,2,1),imshow(G_h1),title('Sobel G通道锐化');
subplot(1,2,2),imshow(G_h2),title('Prewitt G通道锐化');
%B通道锐化
B_h1 = imfilter(B_A, h1);
B_h2 = imfilter(B_A, h2);
figure,
subplot(1,2,1),imshow(B_h1),title('Sobel B通道锐化');
subplot(1,2,2),imshow(B_h2),title('Prewitt B通道锐化');
%合成三个通道的锐化结果
A_h1 = cat(3, R_h1, G_h1, B_h1);
A_h2 = cat(3, R_h2, G_h2, B_h2);
figure,
subplot(1,2,1),imshow(A_h1),title('Sobel 三通道合成');
subplot(1,2,2),imshow(A_h2),title('Prewitt 三通道合成');
实验结果:
原图像:
三通道分离:
R通道滤波结果:
G通道滤波结果:
B通道滤波结果:
滤波结果合成: