Computer Vision_Image Segmentation

Contents

1 Function_segment_image

2 Function_convert_seg_to_boundaries

3 Function_evaluate

4 Function_show_results

5 Function_compare_segmentations

Result


1 Function_segment_image

% @ Name: segment_image (I)
% @ Author: Chengzhi Zhang
% @ Time: 2021/11/04
% @ Function: Edge Detection
% @ Version: Matlab R2021b 

function [seg] = segment_image (I)

% STEP 1 detect the image and convert the original image to grayscale image
[x y z] = size (I)
if z > 1
    I = rgb2gray (I);
end

% STEP 2 convert image to double precision
I = im2double (I);

% STEP 3 erodes the grayscale image I using the function imerode
% and use the original image minus eroded image
I1 = imerode (I, strel ('square', 3));
I2 = I - I1;

% STEP4 using Prewitt operator to detect the edge of image
% the average score of 12 test images can reach 0.67
seg = edge (I2, 'prewitt');
imagesc (seg);

end

2 Function_convert_seg_to_boundaries

function b=convert_seg_to_boundaries(seg)
%Performs conversion from an array containing region labels (seg) 
%to one containing the boundaries between the regions (b)

seg=padarray(seg,[1,1],'post','replicate');

b=abs(conv2(seg,[-1,1],'same'))+abs(conv2(seg,[-1;1],'same'))+abs(conv2(seg,[-1,0;0,1],'same'))+abs(conv2(seg,[0,-1;1,0],'same'));

b=im2bw(b(1:end-1,1:end-1),0);

3 Function_evaluate

function [f1score,TP,FP,FN]=evaluate(boundariesPred,boundariesHuman)
%Returns the f1score quantifying the quality of the match between predicted
%and human image segmentations.
%
%Note both inputs are assumed to show the boundaries between image
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值