基于Matlab实现图像前景目标边缘检测

1. 实现内容:对原始图像进行前景目标提取后进行边缘检测

2. 实现步骤:

3. 编码实现 

3.1 加载图像

clear all;
clc;
img = imread('C:\Temp\2008_006325.jpg');

3.2 RDB转灰度图

img1 = rgb2gray(img);
figure(1);
imhist(img1); % 观察灰度直方图,谷中间值约120,确定阈值T=120

 3.3 前景目标提取

img2 = im2bw(img1,120/255); %im2bw函数需要将灰度值转换到[0,1]范围内,提取前景目标

3.4 目标边缘检测

img3=edge(img2,'sobel');

3.5 绘图合并展示

figure(2);
subplot(2,2,1);
imshow(img);
title('原始图像');

subplot(2,2,2);
imshow(img1);
title('RGB转灰度图像');

subplot(2,2,3);
imshow(img2);
title('提取前景目标图像'); 

subplot(2,2,4);
imshow(img3);
title('前景目标边缘检测图像');

猜你喜欢

转载自blog.csdn.net/z1099043492/article/details/127111180