Realization of Image Foreground Object Edge Detection Based on Matlab

1. Implementation content: edge detection after foreground target extraction on the original image

2. Implementation steps:

3. Coding implementation 

3.1 Loading images

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

3.2 RDB to grayscale image

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

 3.3 Foreground Object Extraction

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

3.4 Object edge detection

img3=edge(img2,'sobel');

3.5 Merge display of drawings

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('前景目标边缘检测图像');

Guess you like

Origin blog.csdn.net/z1099043492/article/details/127111180