-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake algorithm
43 lines (34 loc) · 1.19 KB
/
snake algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function sneaker(org_image,n)
I=rgb2gray(org_image) ;
imshow(I)
str = 'Click to select initial contour location. Double-click to confirm and proceed.';
title(str,'Color','b','FontSize',12);
disp(sprintf('\nNote: Click close to object boundaries for more accurate result.'));
% Select region interactively
mask = roipoly;
figure,
imshow(mask)
title('Initial MASK');
% Segment the image using active contours
maxIterations = n; % More iterations may be needed to get accurate segmentation.
bw = activecontour(I, mask, maxIterations, 'Chan-Vese');
org_med_noise= imnoise(I,'gaussian',0, 0.01);
org_high_noise= imnoise(I,'gaussian',0, 0.02);
% Display segmented image
figure;
subplot(1,3,1) ;
imshow(bw)
title('No noise');
global noice; global mednc ; global highnc ;
noice= double(bw(:,:,1));
subplot(1,3,2);
seg_med= activecontour(org_med_noise, mask, maxIterations, 'Chan-Vese');
imshow(seg_med);
title('Moderate noise');
mednc = double(seg_med(:,:,1));
subplot(1,3,3)
seg_high = activecontour(org_high_noise, mask, maxIterations, 'Chan-Vese');
imshow(seg_high);
title('High noise');
highnc = double(seg_high(:,:,1));
end