?? segmentscript.m
字號:
% SEGMENTSCRIPT Script to open image file, set initial circle, and
% run either traditional segmentation or active contours
% segmentation
display_it = 100;
movie_it = 100;
% grab the image filename and path
[ filename, pathname ] = uigetfile( '*', 'Select an image to segment' );
% if user cancelled dialog box then exit
if( filename == 0 )
return;
end;
% Scale the image by a user specified amount
while( 1 )
scalefactor = input( 'Enter scaling factor between 0 and 4: ');
if( isnumeric( scalefactor ) )
if( scalefactor > 0 & scalefactor <= 4 )
break;
end;
end;
end;
% otherwise open the image and display it
im = readimage( strcat( pathname, filename ));
im_resized = imresize( im, scalefactor );
imshow( uint8( im_resized ) );
% and get the user to click on the circle center
disp( 'Click on circle center' );
center = ginput( 1 );
% display the center and get the user to click again to define the
% radius
disp( 'Click again to define radius' );
hold on;
plot( center(1), center(2), 'go-' );
hold off;
radius = round( sqrt( sum( ( center - ginput( 1 ) ).^2 ) ) )
% Get the user to pick the method of segmentation
disp( 'Pick Segmentation Method' );
disp( '1. Level Sets using Edge Stopping Function' );
disp( '2. Level Sets using Active Contours without Edges' );
selection = 0;
while( selection ~= 1 & selection ~= 2 )
selection = input( 'Please pick (1) or (2): ' );
end;
% Get the user to pick whether the circle contains the object
disp( 'Choose whether or not entire object is inside circle' );
disp( '1. Completely Inside' );
disp( '2. Not Completely Inside' );
inside = 0;
while( inside ~= 1 & inside ~= 2 )
inside = input( 'Please pick (1) or (2): ' );
end;
moviename = filename( 1 : strfind( filename, '.' ) - 1 );
% and run the level set segmentation
if( selection == 1 )
phi = levelsetband( im_resized, circshift( center, [ 0, 1 ] ), radius, 2 - inside , display_it, movie_it, moviename );
else
phi = activecontour( im_resized, circshift( center, [ 0, 1 ] ), radius, 2 - inside, display_it, movie_it, moviename );
end;
% overlay the front on the original image
resized_phi = imresize( phi, size( im ) );
im_segmented = createimage( im, resized_phi );
% display the segmented image and save it to disk
clf; imshow( im_segmented ); drawnow;
imwrite( im_segmented, strcat( moviename, '_segmented.png' ) );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -