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

📄 colorview.m

📁 基于matlab的反演程序,用于地球物理勘探中射线追踪及偏移成像程序.
💻 M
📖 第 1 页 / 共 2 页
字号:
function hfig=colorview(arg,himage,datamin,datamax,dismissMode) 
% COLORVIEW: puts up and interactive widget to manipulate colormaps
%
% hfig=colorview(haxes,himage,datamin,datamax,dismissMode)
% hfig=colorview(haxes,himage,datamin,datamax)
% colorview('refresh',himage,hcolorfig)
% bool=colorview('iscolor',hfig)
% hcoloraxes = colorview('coloraxes',hmasterfig,hcolorfig)
% vals= colorview('getvalues',hcolorfig)
%
% COLORVIEW is designed to be used by a parent figure window which has
% an image object (or objects) displayed and needs to give the user
% interactive control over the colormap and other color features.
% (If more than 1 image object, then the first is used to determine
% scaling and data range so it is best if they are similar. This
% is mainly intended to allow control of a color bar in the main 
% figure.)
% If the parent object has a pseudocolor display, then it should use
% PCOLORVIEW instead to achieve a similar functionality.
% COLORVIEW takes a handle to an axes object as its first argument
% and displays another figure window showing the colormap and
% color axis active in the window containing the axes.
% Facilities are provided to adjust, or change entirly, 
% the colormap and install it in the first window.
% The first two calling modes are used to initialize a COLORVIEW
% object and differ in that one always assumes the figure will
% simply become invisible when dismissed while the other offer
% the ability to kill the figure when dismissed. Both return
% the handle of the color figure so that the parent window
% can keep track of it. The third mode of calling is intended
% to be used by the parent window when the handle of the image
% object has changed (e.g. it has been redrawn) and an existing
% color figure needs to be notified. (This is only intended
% for situations in which the data has not changed.
% If the data has changed then the
% color figure should be closed and rebuilt)
%
% The fourth calling mode will determine whether the figure whose 
% handle is hfig is a colorview figure or not and return a boolean
% flag indicating this.
%
% The fifth mode is used to create a color axes in the masterfigure.
% One created, colorview will update it as well as the main image.
% If the handle of the created coloraxes is hcax, then calling
% colorview('deletecolor',hcax) will delete it. (Note this makes
% the colorview window inconsistent so you should kill it too when
% doing this)
%
% The sixth mode is used to determine the color scaling values for
% scaling an image in accordance with the colorview display. Normally
% colorview does this for you but there may be circumstances where
% it is necessary to do it yourself. In which case the scaling
% equation is
%	imagedata=(imagedata-vals(1))/(vals(2)-vals(1))*(nkols-1) +1;
%	where nkols is the length of the current colormap
%
%	haxes = handle to an axes object
%   himage = vector of handles of the image object in the
%		parent figure whose color is to be controlled
% 	datamin = true minumum of the data being displayed in the axes
% 	datamax = true maximum of the data being displayed in the axes 
%   dismissMode = 1 ... dismiss button sets figure's visible property
%						to 'off'
%		        = 0 ... dismiss button kills figure window
%	********** default = 1 ************
%   hcolorfig = handle of the color figure
%
%	hfig = handle of the color figure window
%
% G.F. Margrave, October 1993
%
% NOTE: It is illegal for you to use this software for a purpose other
% than non-profit education or research UNLESS you are employed by a CREWES
% Project sponsor. By using this software, you are agreeing to the terms
% detailed in this software's Matlab source file.
 
% BEGIN TERMS OF USE LICENSE
%
% This SOFTWARE is maintained by the CREWES Project at the Department
% of Geology and Geophysics of the University of Calgary, Calgary,
% Alberta, Canada.  The copyright and ownership is jointly held by 
% its author (identified above) and the CREWES Project.  The CREWES 
% project may be contacted via email at:  crewesinfo@crewes.org
% 
% The term 'SOFTWARE' refers to the Matlab source code, translations to
% any other computer language, or object code
%
% Terms of use of this SOFTWARE
%
% 1) Use of this SOFTWARE by any for-profit commercial organization is
%    expressly forbidden unless said organization is a CREWES Project
%    Sponsor.
%
% 2) A CREWES Project sponsor may use this SOFTWARE under the terms of the 
%    CREWES Project Sponsorship agreement.
%
% 3) A student or employee of a non-profit educational institution may 
%    use this SOFTWARE subject to the following terms and conditions:
%    - this SOFTWARE is for teaching or research purposes only.
%    - this SOFTWARE may be distributed to other students or researchers 
%      provided that these license terms are included.
%    - reselling the SOFTWARE, or including it or any portion of it, in any
%      software that will be resold is expressly forbidden.
%    - transfering the SOFTWARE in any form to a commercial firm or any 
%      other for-profit organization is expressly forbidden.
%
% END TERMS OF USE LICENSE

% user data assignments:
% figure = all of the graphics handles
%         [hcmaxLabel,hcmax,hcminLabel,hcmin,hbrighten,hdarken,
%         hinstall,hdismiss,hgrid,hax,hfigure,hmaps, hmapsLabel]
% axes = z vaues of fake grid
% hcmaxLabel = vector of handles of the images to be updated
% hcmax = handle of a second image that is also to be updated
% hcminLabel = handle of the fake color grid in the color window
% hcmin = [datamin datamax]
% hbrighten = none
% hdarken = none
% hinstall = none
% hauto = none
% hdismiss = dismissMode
% hmaps = original colormap
% hmapsLabel = none

% determine the type of argument passed
if( isstr(arg) )
	action = arg;
else
	haxes=arg;
	action = 'initialize';
end

if( strcmp(action,'initialize') )
	if( nargin < 5 ) dismissMode = 1; end
% get the figure window and the colormap
	hfigure = get(haxes,'Parent');
	clrmap = get(hfigure,'ColorMap'); 
% get the color axis limits
	clim = get(haxes,'Clim');
% open a new figure window
	pos=get(hfigure,'Position');
	units = get(hfigure,'Units');
	figwidth = 150;% in pixels
	figheight = 350;
 	hfig=figure('Units',units,'Position',[pos(1),pos(2),figwidth,figheight],...
		'ColorMap',clrmap,'menubar','none');
% make some data to show the colors
	x=[1 2 3 4 5];
	[m,n]=size(colormap);
 imagedata = get(himage(1),'cdata');
 ind=~isnan(imagedata);
 immin = floor(min(min(imagedata(ind))));
 immax = ceil(max(max(imagedata(ind))));
 z = (immax:-1.:immin)';
	y=linspace(datamax,datamin,length(z));
	y=y';
	z=z*ones(1,5);
% make some controls
	sep = 2;
	width = 70;
	height = 20;
	xnow= sep;
	ynow = figheight-height;
	hcmaxLabel = uicontrol('Style','Text','String','Color Max:',...
		'Position',[xnow,ynow,width,height],'userdata',himage);
	xnow = xnow+width+sep;
 maxsetting = m-abs( (m-1)*(immax-m)/(immax-immin) );
	hcmax = uicontrol('Style','slider','Position',[xnow,ynow,...
		width,height],'Min',1,'Max',m,...
		'Value',maxsetting,'Callback','colorview(''cmax'')');
	ynow=ynow-sep-height;
	xnow=sep;
	hcminLabel = uicontrol('Style','Text','String','Color Min:',...
		'Position',[xnow,ynow,width,height]);
	xnow = xnow+width+sep;
 minsetting = 1+abs( (m-1)*(1-immin)/(immax-immin) );
	hcmin = uicontrol('Style','slider','Position',[xnow,ynow,...
		width,height],'Min',1,'Max',m,...
		'Value',minsetting,'Callback','colorview(''cmin'')',...
		'userdata',[datamin datamax]);
	ynow=ynow-sep-height;
	xnow=sep;
hmapsLabel = uicontrol('style','text','string','Color Maps:',...
  'Position',[xnow,ynow,width,height]);
 xnow = xnow+width+sep;
 hmaps = uicontrol('style','popupmenu','string',...
  'original|hsv|gray|hot|cool|bone|copper|pink|jet|alpine',...
  'userdata',clrmap,'position',[xnow,ynow,width,height],...
  'callback','colorview(''maps'')');
	ynow=ynow-sep-height;
	xnow=sep;
	hbrighten=uicontrol('Style','pushbutton','String','Brighten',...
		'Position',[xnow,ynow,width,height],'Callback',...
		'colorview(''brighten'')');
	xnow=xnow+sep+width;
	hdarken=uicontrol('Style','pushbutton','String','Darken',...
		'Position',[xnow,ynow,width,height],'Callback',...
		'colorview(''darken'')');
	ynow=ynow-sep-height;
	xnow=sep;
	hinstall=uicontrol('Style','pushbutton','String','Doit',...
		'Position',[xnow,ynow,width,height],'Callback',...
		'colorview(''install'')');
	xnow=xnow+sep+width;
	hauto=uicontrol('Style','pushbutton','String','Auto Scale',...
		'Position',[xnow,ynow,width,height],'Callback',...
		'colorview(''autoscale'')');
	ynow=ynow-sep-height;
	xnow=sep;
	hdismiss=uicontrol('Style','pushbutton','String','Dismiss',...
		'Position',[xnow,ynow,width,height],'Callback',...
		'colorview(''dismiss'')','userdata',dismissMode);
	
% plot a grid
	hgrid=image(x,flipud(y),flipud(z));
	hax=get(hgrid,'Parent');
	%set(hax,'Units','pixels');
 	ytick = linspace(min(y),max(y),8);
 	fact = floor(log10(ytick(8)-ytick(1)));
 	fact = 10^(fact-2);
	ytick = fact*floor(ytick/fact); 
	set(hax,'XTick',[],'DataAspectRatiomode','auto','ytick',ytick,...
		'Position',[.4,.05,.4,.45],'Clim',clim,'userdata',z,'ydir',...
		'normal');

% store all of the graphics handles in the figure
	set(gcf,'UserData',[hcmaxLabel,hcmax,hcminLabel,hcmin,...
		hbrighten,hdarken,hinstall,hdismiss,hgrid,hax,hfigure,...
  hmaps, hmapsLabel]);
  return;
end

if( strcmp(action,'cmin')|strcmp(action,'cmax') )
% get the handles
	h=get(gcf,'UserData');
	hcmin=h(4);
 hcmax=h(2);
% get the new min & max from the sliders
	valmin = get(hcmin,'Value');
 valmax = get(hcmax,'value');

%get the colormap
clrmap = get(gcf,'colormap');
n=length(clrmap);

% get the data and scale it
 hgrid = h(9);
 z = get(hgrid,'cdata');
 zmax=max(z(:));zmin=min(z(:));
 z = (n-1)*(z-zmin)/(zmax-zmin)+1;
 z = (n-1)*(z-valmin)/(valmax-valmin)+1;

% reinstall the data
	set(hgrid,'cdata',z);
	return;
end

if( strcmp(action,'brighten') )

⌨️ 快捷键说明

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