⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segment_demo.m

📁 mean shift
💻 M
📖 第 1 页 / 共 4 页
字号:
      'String', 'OK', 'Style', 'Pushbutton', 'Callback', Callback, ...
      'Units', 'Normalized', 'Position', [0.1 0.3 0.3 0.4]);


%-----------------------------------------
elseif strcmp(Action, 'Region color')
	I = varargin{length(varargin)};		% last argument always
	Index_color = get(Arguments, 'Value');
	Index_string = get(Arguments, 'String');
	close;	% input window
	Regions{I}{Region_left{I}}.Private.Color = Index_string{Index_color};
	Segment_demo('Draw boundary', Region_left{I}, I);
	Region_left{I} = 0;


%-----------------------------------------
elseif strcmp(Action, 'Select left region')
	I = varargin{length(varargin)};		% last argument always
  	Curr_pt_local = get(gca, 'CurrentPoint');
  	Curr_pt_local = round(Curr_pt_local(1, 1:2));
	Curr_pt_local = Curr_pt_local(2:-1:1);
	for i=Bndred_regions{I}:-1:1
		Min_x = Regions{I}{i}.Public.Shifts(1, 1);
		Min_y = Regions{I}{i}.Public.Shifts(2, 1);
		Max_x = Regions{I}{i}.Public.Shifts(1, 2);
		Max_y = Regions{I}{i}.Public.Shifts(2, 2);
		if Curr_pt_local(1) >= Min_x & Curr_pt_local(1) <= Max_x
		if Curr_pt_local(2) >= Min_y & Curr_pt_local(2) <= Max_y
			if Regions{I}{i}.Public.Region_matr(...
				Curr_pt_local(1)-Min_x+1, Curr_pt_local(2)-Min_y+1) > 0
				% then the region has been found
   			if Region_left{I}									% was assigned some value
      			if not(Region_left{I} == Region_right{I})
         			Segment_demo('Draw boundary', Region_left{I}, I);
      			end
   			end
				if Region_left{I} == i		% this was selected, now is deselected
					Region_left{I} = 0;
				else
   				Region_left{I} = i;
   				Segment_demo('Draw boundary', Region_left{I}, 'white', I);
				end
				break;
			end
		end
		end
	end


%-----------------------------------------
elseif strcmp(Action, 'Select right region')
	I = varargin{length(varargin)};		% last argument always
  	Curr_pt_local = get(gca, 'CurrentPoint');
  	Curr_pt_local = round(Curr_pt_local(1, 1:2));
	Curr_pt_local = Curr_pt_local(2:-1:1);
	for i=Bndred_regions{I}:-1:1
		Min_x = Regions{I}{i}.Public.Shifts(1, 1);
		Min_y = Regions{I}{i}.Public.Shifts(2, 1);
		Max_x = Regions{I}{i}.Public.Shifts(1, 2);
		Max_y = Regions{I}{i}.Public.Shifts(2, 2);
		if Curr_pt_local(1) >= Min_x & Curr_pt_local(1) <= Max_x
		if Curr_pt_local(2) >= Min_y & Curr_pt_local(2) <= Max_y
			if Regions{I}{i}.Public.Region_matr(...
				Curr_pt_local(1)-Min_x+1, Curr_pt_local(2)-Min_y+1) > 0
				% then the region has been found
   			if Region_right{I}									% was assigned some value
      			if not(Region_left{I} == Region_right{I})
         			Segment_demo('Draw boundary', Region_right{I}, I);
      			end
   			end
				if Region_right{I} == i		% this was selected, now is deselected
					Region_right{I} = 0;
				else
   				Region_right{I} = i;
   				Segment_demo('Draw boundary', Region_right{I}, 'white', I);
				end
				break;
			end
		end
		end
	end

%----------------------------------------
elseif strcmp(Action, 'Disable region')
	I = varargin{length(varargin)};		% last argument always
	if Arguments == 0		% call from interactive input
		close;			% prompt
		Arguments = Region_left{I};
		Region_left{I} = 0;
	end
  	Regions{I}{Arguments}.Private.Active = 0;
  	Segment_demo('Draw boundary', Arguments,  'none', I);
	Segment_demo('Refresh image', 0, I);


%-----------------------------------------
elseif strcmp(Action, 'Find boundary')
	I = varargin{length(varargin)};		% last argument always
 	Rows = size(Image{I}, 1);
  	Cols = size(Image{I}, 2);
  	if length(Curr_pt{I}) > 0	% was defined
     if ((Curr_pt{I}(1) > 0) & (Curr_pt{I}(2) > 0) & ...
           (Curr_pt{I}(1) < Rows) & (Curr_pt{I}(2) < Cols))
        for i=1:size(Slices{I}, 3)
           if Slices{I}(Curr_pt{I}(1), Curr_pt{I}(2), i) > 0	% in this slice
              [Boundary, Area] = Extract_region_reg(Slices{I}(:, :, i) == ...
                 Slices{I}(Curr_pt{I}(1),Curr_pt{I}(2), i), Min_region_size{I});
              break;
           end
        end
     end
     
     if exist('Boundary', 'var')
     if size(Boundary, 2) > 1
     		Bndred_regions{I} = Bndred_regions{I}+1;
        	Regions{I}{Bndred_regions{I}}.Private.Number = Bndred_regions{I};
        	Regions{I}{Bndred_regions{I}}.Public.Boundary = Boundary;
        	Min_x = min(Boundary(1, :));  Max_x = max(Boundary(1, :));
        	Min_y = min(Boundary(2, :));  Max_y = max(Boundary(2, :));
        	Regions{I}{Bndred_regions{I}}.Public.Shifts = ...
		  		[Min_x, Max_x; Min_y, Max_y];
        	Regions{I}{Bndred_regions{I}}.Public.Inner_pts = ...
		  		[Curr_pt{I}(1); Curr_pt{I}(2)];
		   Regions{I}{Bndred_regions{I}}.Public.Region_matr = ...
				Region_matrix(Regions{I}{Bndred_regions{I}}.Public);
        	Regions{I}{Bndred_regions{I}}.Private.Color = ...
         	Region_colors{1, 1+rem(Bndred_regions{I}-1, size(Region_colors, 2))};
        % Regions{I}{Bndred_regions{I}}.Private.Color = ...
        %   global_color;
        	Regions{I}{Bndred_regions{I}}.Private.Line = 0;
		  	Regions{I}{Bndred_regions{I}}.Private.From = [];
		  % setting up variables for region info values
        	Regions{I}{Bndred_regions{I}}.Public.Area = -99;
        	Regions{I}{Bndred_regions{I}}.Public.Volume= -99;
        	Regions{I}{Bndred_regions{I}}.Public.Avg_intensity = -99;
        	Menu_children = get(Region_menu{I}, 'Children');
        	for i=1:length(Menu_children)
           	set (Menu_children(i), 'Enable', 'on');
        	end
        	Segment_demo('Draw boundary first time', Bndred_regions{I}, I);
        	Segment_demo('Enable region', Bndred_regions{I}, I);
    end
    end
  end
  
  
%-----------------------------------------
elseif strcmp(Action, 'Save boundary prompt')
	I = varargin{length(varargin)};		% last argument always
	Operation_prompt;		% the common piece
	if Interactive 
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Save boundary', 0, I);
		if Ok_button
			set(Ok_button, 'Callback', Callback);
		end
	else
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Save boundary', 1, I);
		eval(Callback);
	end


%----------------------------------------
elseif strcmp(Action, 'Save boundary')
	I = varargin{length(varargin)};		% last argument always
	if Arguments == 0		% from interactive
		close;	% prompt
	end
   Filter = '*.rgn';
   [File_name, Path_name] = uiputfile(Filter, 'Save to ...');
   if File_name(1) > 0
      File_name = [Path_name, File_name];
      fid = fopen(File_name, 'w');
      fprintf(fid, '%d %d\n', Regions{I}{Region_left{I}}.Public.Inner_pts(1:2));
		fprintf(fid, '%d %d\n', 0, 0);	% the separation for Inner pts
      fprintf (fid, '%d %d\n', Regions{I}{Region_left{I}}.Public.Boundary);
      fclose(fid);
   end
   Segment_demo('Draw boundary', Region_left{I}, I);
   Region_left{I} = 0;
   
   
%-----------------------------------------
elseif strcmp(Action, 'Compare window regions prompt')
	I = varargin{length(varargin)};		% last argument always
	if not(Window_regs_chosen)				% need to open one more window
   	Operation_prompt;						% the common piece
		if Interactive 
			Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare window regions', 0, I);
			if Ok_button
				set(Ok_button, 'Callback', Callback);
			end
		else
			Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare window regions', 1, I);
			eval(Callback);
		end
	else
		Operation_prompt_right;
		if Interactive 
			Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare window regions', 0, I);
			if Ok_button
				set(Ok_button, 'Callback', Callback);
			end
		else
			Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare window regions', 1, I);
			eval(Callback);
		end
	end

%-----------------------------------------
elseif strcmp(Action, 'Compare window regions')
	I = varargin{length(varargin)};		% last argument always
	if Arguments == 0		% interactive input
   	close;
	end
	if not(Window_regs_chosen)		% need to open one more window
   	msgbox('Please choose another region', 'Another');
		Window1 = I;
		Window_regs_chosen = 1;
	else
		Window2 = I;
		% computing chars if needed
		if Regions{Window1}{Region_left{Window1}}.Public.Area < 0
			Segment_demo('Intensity 3-d', Region_left{Window1}, Window1);
		end
		if Regions{Window2}{Region_right{Window2}}.Public.Area < 0
			Segment_demo('Intensity 3-d', Region_right{Window2}, Window2);
		end
		[Bdry_dist, Reg_dist] = ...
			Svd_dist_reg(Regions{Window1}{Region_left{Window1}}.Public, ...
				Regions{Window2}{Region_right{Window2}}.Public);
   	Msg = [sprintf('Boundary difference: %6.2f\n\n', Bdry_dist), ...
   		sprintf('Region  difference: %6.2f\n\n', Reg_dist), ...
			sprintf('Areas ratio: %6.2f\n\n', ...
				Regions{Window1}{Region_left{Window1}}.Public.Area/...
				Regions{Window2}{Region_right{Window2}}.Public.Area), ...
			sprintf('Volumes ratio: %6.2f\n\n', ...
				Regions{Window1}{Region_left{Window1}}.Public.Volume/...
				Regions{Window2}{Region_right{Window2}}.Public.Volume), ...
			sprintf('Avg intensities ratio: %6.2f', ...
				Regions{Window1}{Region_left{Window1}}.Public.Avg_intensity/...
				Regions{Window2}{Region_right{Window2}}.Public.Avg_intensity)
			];
		Wind_name = sprintf('%d and %d regions differences and ratios', ...
			Region_left{Window1}, Region_right{Window2});
   	msgbox(Msg, Wind_name);

   	Segment_demo('Draw boundary', Region_left{Window1}, Window1);
   	Segment_demo('Draw boundary', Region_right{Window2}, Window2);
   	Region_left{Window1} = 0; Region_right{Window2} = 0;
		Window_regs_chosen = 0;
	end


%-----------------------------------------
elseif strcmp(Action, 'Compare image regions prompt')
	I = varargin{length(varargin)};		% last argument always
   Operation_prompt;			% the common piece
   Right_button;				% one more button here	if Interactive 
	if Interactive
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare image regions', 0, I);
		if Ok_button
			set(Ok_button, 'Callback', Callback);
		end
	else
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare image regions', 1, I);
		eval(Callback);
	end

%-----------------------------------------
elseif strcmp(Action, 'Compare image regions')
	I = varargin{length(varargin)};		% last argument always
	if Arguments == 0							% interactive call
   	close;	% prompt
   end
	if Region_right{I} ==  0
		return;
	end
	[Bdry_dist, Reg_dist] = ...
		Svd_dist_reg(Regions{I}{Region_left{I}}.Public, ...
			Regions{I}{Region_right{I}}.Public);
	% computing chars if needed
	if Regions{I}{Region_left{I}}.Public.Area < 0
		Segment_demo('Intensity 3-d', Region_left{I}, I);
	end
	if Regions{I}{Region_right{I}}.Public.Area < 0
		Segment_demo('Intensity 3-d', Region_right{I}, I);
	end
	[Bdry_dist, Reg_dist] = ...
		Svd_dist_reg(Regions{I}{Region_left{I}}.Public, ...
			Regions{I}{Region_right{I}}.Public);
  	Msg = [sprintf('Boundary difference: %6.2f\n\n', Bdry_dist), ...
  		sprintf('Region  difference: %6.2f\n\n', Reg_dist), ...
		sprintf('Areas ratio: %6.2f\n\n', ...
			Regions{I}{Region_left{I}}.Public.Area/...
			Regions{I}{Region_right{I}}.Public.Area), ...
		sprintf('Volumes ratio: %6.2f\n\n', ...
			Regions{I}{Region_left{I}}.Public.Volume/...
			Regions{I}{Region_right{I}}.Public.Volume), ...
		sprintf('Avg intensities ratio: %6.2f', ...
			Regions{I}{Region_left{I}}.Public.Avg_intensity/...
			Regions{I}{Region_right{I}}.Public.Avg_intensity)
		];
	Wind_name = sprintf('%d and %d regions differences and ratios', ...
		Region_left{I}, Region_right{I});
  	msgbox(Msg, Wind_name);

   Segment_demo('Draw boundary', Region_left{I}, I);
   Segment_demo('Draw boundary', Region_right{I}, I);
   Region_left{I} = 0; Region_right{I} = 0;


%-----------------------------------------
elseif strcmp(Action, 'Compare disk regions prompt')
	I = varargin{length(varargin)};		% last argument always
   Operation_prompt;			% the common piece
	if Interactive 
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare disk regions', 0, I);
		if Ok_button
			set(Ok_button, 'Callback', Callback);
		end
	else
		Callback=sprintf('Segment_demo(''%s'',%d,%d)', 'Compare disk regions', 1, I);
		eval(Callback);
	end

%-----------------------------------------
elseif strcmp(Action, 'Compare disk regions')
	I = varargin{length(varargin)};		% last argument always
	if Arguments == 0		% interactive input
   	close;	% prompt
	end
   Filter = '*.rgn';
   [File_name, Path_name] = uigetfile(Filter, 'Compare to ...');
   if File_name(1) > 0
      File_name = [Path_name, File_name];
      fid = fopen(File_name, 'r');
		k = 0;
		Pt_scanned(1:2, 1) = fscanf(fid, '%d', [2, 1]);
		while sum(Pt_scanned) > 0
			k = k+1;
      	Region2.Public.Inner_pts(:, k) = Pt_scanned;
			Pt_scanned(1:2, 1) = fscanf(fid, '%d', [2, 1]);
		end
      Region2.Public.Boundary = fscanf(fid, '%d', [2, inf]);
		Min_x = min(Region2.Public.Boundary(1, :));  
		Max_x = max(Region2.Public.Boundary(1, :));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -