RGB图像边缘检测

RGB图像边缘检测

实验图像

代码

%RGB图像边缘检测
%边缘检测
clear all
close all
clc

f = imread('图6-1.tif');%此时数据为uint8类型

f = im2double(f);       %数据类型转换成0-1的double
fR = f(:, :, 1); 
fG = f(:, :, 2); 
fB = f(:, :, 3); 

 [G_Rx,G_Ry]=gradient(fR);
 [G_Gx,G_Gy]=gradient(fG);
 [G_Bx,G_By]=gradient(fB);
 
 u = G_Rx +G_Gx +G_Bx;
 v = G_Ry +G_Gy +G_By;
 
G_xx = u.*u;
G_xy = u.*v;
G_yy = v.*v;
 
%计算theta
 
theta = 0.5*atan(2*G_xy./( G_xx-G_yy));%弧度制
 
F_theta = sqrt(0.5*(G_xx+G_yy)+( G_xx-G_yy).*cos(2*theta)+2*G_xy.*sin(2*theta));
 
F_theta =real(F_theta);
 
subplot(121)
imshow(f,[]);
title('原始图像');

subplot(122)
imshow( F_theta,[]);
title('边缘检测');

 

你可能感兴趣的:(rgb,matlab,边缘检测)