function Segment_demo (Action, Arguments, varargin)
global All_vars Biomed_on;
if size(All_vars, 2) > 0
eval (['global ', All_vars]);
end
% regions are represented as structures of:
% private chars:
% Number - region number
% Color - the original color to draw the region
% Line - the actual points as a line object
% Active - whether it was merged into another region
% From - which regions it was obtained from (by merging or cutting)
% public chars:
% Boundary (Boundary) given as set of points
% Area - total area of the regions, since computed anyway
% Inner point - telling where the interior of region is (Inner_pts)
% Shifts - a matrix of size 2 by 2 giving min, max x and y vals for boundary
% Region_matr - the filled with pixels boundary for various operations
% user defined chars:
if nargin < 1
warning off;
Common_vars =[' Gray_image Image Luv_image Image_is_gray ', ...
' Region_colors Bndred_regions Curr_pt Curr_pt_line ',...
' Slices Centers Store_mouse_pts ', ...
' Regions Region_menu_added Min_region_size ', ...
' Region_menu Main_figure Main_axis Marker_size ', ...
' Region_left Region_right Show_all_regions ', ...
' Instance Active_instances Biomed_on '];
Biomed_vars = [' Amnt_rot Window_regs_chosen Window1 Window2 '];
All_vars = [Common_vars, Biomed_vars];
eval (['global ', All_vars]);
Action = 'Initialize';
end
if strcmp(Action, 'Initialize')
if nargin < 2 % the very first call to it
Msg_box_hndl = msgbox('Welcome to the system ...', 'Welcome');
Child = get(Msg_box_hndl, 'Children'); % the OK button
set(Child(length(Child)), 'Style', 'Text', 'String', '');
Image_menu = uimenu(Msg_box_hndl, 'Label','&Image');
uimenu(Image_menu, 'Label', '&Open...', ...
'Callback', 'close; Segment_demo(''Read image'')', 'Accelerator', 'O');
uimenu(Image_menu, 'Label', '&Quit', ...
'Callback', 'close', 'Separator','on', 'Accelerator', 'Q');
Screen_size = get(0, 'ScreenSize');
Marker_size = round(max(Screen_size)/200);
else
I = varargin{length(varargin)}; % last argument always
if length(size(Arguments)) == 3 % color image
Image_is_gray{I} = 0;
Image{I} = Arguments;
else
Image_is_gray{I} = 1;
Image{I} = Arguments;
Gray_image{I} = double(Arguments);
end
if not(varargin{1}) % does not need new window
Kids = get(Main_axis{I}, 'Children');
for i=1:length(Kids)
if strcmp(get(Kids(i), 'Type'), 'line')
set(Kids(i), 'XData', 0, 'YData', 0, 'Visible', 'off');
end
end
Segment_demo('Refresh image', 0, I);
end
Regions{I} = {};
Bndred_regions{I} = 0;
Region_left{I} = 0; Region_right{I} = 0;
Store_mouse_pts{I} = 0; Curr_pt_line{I} = 0;
Show_all_regions{I} = 0; % will show only active regions by default
% Biomed vars go here
if Instance == 1
Window_regs_chosen = 0;
end
Amnt_rot{I} = 8;
% the list of colors
Region_colors{1, 1} = 'magenta';
Region_colors{1, 2} = 'yellow';
Region_colors{1, 3} = 'green';
Region_colors{1, 4} = 'red';
Region_colors{1, 5} = 'cyan';
Region_colors{1, 6} = 'blue';
Region_colors{1, 7} = 'black';
if varargin{1} % needs new window
Region_menu_added{I} = 0;
ButtonDown = sprintf('Segment_demo(''%s'',%d,%d)', 'Down', 0, I);
CloseReq = sprintf('Segment_demo(''%s'',%d,%d)', 'Exit', 0, I);
set(gcf, 'WindowButtonDownFcn', ButtonDown, 'MenuBar', 'none', ...
'CloseRequestFcn', CloseReq);
Main_figure{I} = gcf;
Main_axis{I} = gca;
Image_menu = uimenu('Label','&Image');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Read image', 0, I);
uimenu(Image_menu, 'Label', '&Open...', ...
'Callback', Callback, 'Accelerator', 'O');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Smooth prompt', 0, I);
uimenu(Image_menu, 'Label', 's&Mooth...', ...
'Callback', Callback, 'Accelerator', 'M');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Segment prompt', 0, I);
uimenu(Image_menu, 'Label', 'se&Gment...', ...
'Callback', Callback, 'Accelerator', 'G');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Crop', 0, I);
uimenu(Image_menu, 'Label', '&Crop...', ...
'Callback', Callback, 'Accelerator', 'C');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Refresh image', 0, I);
uimenu(Image_menu, 'Label', 'r&Efresh!', ...
'Callback', Callback, 'Accelerator', 'E');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Label prompt', 0, I);
uimenu(Image_menu, 'Label', 'l&abel', ...
'Callback', Callback, 'Accelerator', 'A');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Save image', 0, I);
uimenu(Image_menu, 'Label', '&Save as...', ...
'Callback', Callback, 'Accelerator', 'S');
Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Exit', 0, I);
uimenu(Image_menu, 'Label', '&Quit', ...
'Callback', Callback, 'Separator','on', 'Accelerator', 'Q');
Segment_demo('Show image', 1, I); % needs window size setting
else
Segment_demo('Show image', 0, I); % no window size setting
end
end
end
%-----------------------------------------
% exiting if desired, after warning
if strcmp(Action, 'Exit')
I = varargin{length(varargin)}; % last argument always
set(Main_figure{I}, 'CloseRequestFcn', 'closereq');
close;
Active_instances = Active_instances-1;
if Active_instances == 0
eval (['clear global ', All_vars]);
end
%-----------------------------------------
% keeping track of the pixel clicked onto by mouse
elseif strcmp(Action, 'Down') % request to pick region follows
I = varargin{length(varargin)}; % last argument always
Curr_pt_get{I} = get(gca, 'CurrentPoint');
Curr_pt_get{I} = round(Curr_pt_get{I}(1, 1:2));
Curr_pt_get{I} = [Curr_pt_get{I}(2); Curr_pt_get{I}(1)]; % switching x and y
if Store_mouse_pts{I}
Curr_pt{I} = [Curr_pt{I}, Curr_pt_get{I}];
else
Curr_pt{I} = Curr_pt_get{I};
end
if Curr_pt_line{I}
set(Curr_pt_line{I}, 'XData',Curr_pt{I}(2, :), 'YData',Curr_pt{I}(1, :));
else
Curr_pt_line{I} = ...
line('XData', Curr_pt{I}(2, :), 'YData', Curr_pt{I}(1, :), ...
'Marker', '.', 'Color', 'yellow', 'EraseMode', 'none');
end
%-----------------------------------------
% segmenting the image into a number of subregions by the subroutine
elseif strcmp(Action, 'Segment prompt')
I = varargin{length(varargin)}; % last argument always
Prompt = {...
'Window size (small window => small variation)', ...
'Color components to use (fewer => quicker)', ...
'Color group size (small size => fewer colors left)', ...
'Min region size (small size => more small regions)', ...
'Would you like to see separate layers?'};
if Image_is_gray{I}
Default = {20, 1, 200, 20, 'No'};
else
Default = {30, 2, 200, 20, 'No'};
end
Title = 'Segmentation parameters';
Line_number = 1;
Segment_input = My_inputdlg(Prompt, Title, Line_number, Default);
if size(Segment_input, 2) > 0
Segment_demo ('Initialize', Image{I}, 0, I); % does not need new wind
Segment_demo ('Segment', Segment_input, I);
end
%-----------------------------------------
% segmenting the image into a number of subregions by the subroutine
elseif strcmp(Action, 'Segment')
I = varargin{length(varargin)}; % last argument always
Segment_input = Arguments;
Window_radius = base2dec(Segment_input{1}, 10);
Components = base2dec(Segment_input{2}, 10);
% Components = round(max(Components, 2)); % for a while
Color_group = base2dec(Segment_input{3}, 10);
Min_region_size{I} = base2dec(Segment_input{4}, 10);
Plot_
- 1
- 2
- 3
- 4
- 5
- 6
前往页