Contents
2 Function_convert_seg_to_boundaries
5 Function_compare_segmentations
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