完成实验四
This commit is contained in:
parent
d8f90dbc3c
commit
fbbdd89bf8
79
EXP_four.m
Normal file
79
EXP_four.m
Normal file
@ -0,0 +1,79 @@
|
||||
% 读取图片
|
||||
image = imread('EXP_3_4/test.jpg');
|
||||
image_airport = imread('EXP_3_4/airport.jpg');
|
||||
image_circuit = imread('EXP_3_4/circuit.png');
|
||||
image_circle = imread('EXP_3_4/circle.jpg');
|
||||
|
||||
% 灰度化
|
||||
image_gray = rgb2gray(image);
|
||||
image_airport_gray = rgb2gray(image_airport);
|
||||
image_circle_gray = rgb2gray(image_circle);
|
||||
|
||||
% log算法
|
||||
image_log = edge(image_gray, 'log');
|
||||
|
||||
% canny算法
|
||||
image_canny = edge(image_gray, 'canny');
|
||||
image_circuit_canny = edge(image_circuit, 'canny');
|
||||
|
||||
% 角点检测
|
||||
image_corners = corner(image_airport_gray, 'Harris');
|
||||
|
||||
% Hough参数
|
||||
[Hough, theta, rho] = hough(image_circuit_canny);
|
||||
|
||||
% Hough 峰值
|
||||
P = houghpeaks(Hough, 10, 'Threshold', ceil(0.3 * max(Hough(:)))); % 取前10个峰
|
||||
|
||||
% 峰值中提取图像中的直线
|
||||
lines = houghlines(image_circuit_canny, theta, rho, P, 'FillGap', 20, 'MinLength', 30);
|
||||
|
||||
% 圆特征提取
|
||||
[centers, radii] = imfindcircles(image_circle_gray, [50 100], 'ObjectPolarity', 'bright', 'Sensitivity', 0.92);
|
||||
|
||||
% 展示照片
|
||||
figure;
|
||||
subplot(1,3,1);
|
||||
imshow(image);
|
||||
title('Original Image'); % 原图
|
||||
subplot(1,3,2);
|
||||
imshow(image_log);
|
||||
title('Log Edge Detection'); % Log边缘检测
|
||||
subplot(1,3,3);
|
||||
imshow(image_canny);
|
||||
title('Canny Edge Detection'); % Canny边缘检测
|
||||
|
||||
figure;
|
||||
subplot(1,2,1);
|
||||
imshow(image_airport);
|
||||
title('Original Image'); % 原图
|
||||
subplot(1,2,2);
|
||||
imshow(image_airport);
|
||||
title('Corner Detection'); % 角点检测
|
||||
hold on;
|
||||
plot(image_corners(:,1), image_corners(:,2), 'r*');
|
||||
|
||||
% 显示图像与直线
|
||||
figure;
|
||||
imshow(image_circuit);
|
||||
hold on;
|
||||
title('Line Edge Detection'); %直线边缘检测
|
||||
|
||||
for k = 1:length(lines)
|
||||
xy = [lines(k).point1; lines(k).point2]; % 两端点
|
||||
plot(xy(:,1), xy(:,2), 'LineWidth', 2, 'Color', 'green');
|
||||
|
||||
% 可视化端点
|
||||
plot(xy(1,1), xy(1,2), 'x', 'Color', 'yellow');
|
||||
plot(xy(2,1), xy(2,2), 'x', 'Color', 'red');
|
||||
end
|
||||
|
||||
figure;
|
||||
subplot(1,2,1);
|
||||
imshow(image_circle);
|
||||
title('Original Image'); % 原图
|
||||
subplot(1,2,2);
|
||||
imshow(image_circle);
|
||||
title('Coin Edge Detection'); % 硬币边缘检测
|
||||
hold on;
|
||||
viscircles(centers, radii, 'EdgeColor', 'r');
|
Loading…
x
Reference in New Issue
Block a user