adjustIntensityRangeGui.m
上传用户:dasuixin
上传日期:2016-08-08
资源大小:66k
文件大小:9k
源码类别:

医药行业

开发平台:

Matlab

  1. function varargout = adjustIntensityRangeGui(varargin)
  2. % ADJUSTINTENSITYRANGEGUI M-file for adjustIntensityRangeGui.fig
  3. %      ADJUSTINTENSITYRANGEGUI, by itself, creates a new ADJUSTINTENSITYRANGEGUI or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = ADJUSTINTENSITYRANGEGUI returns the handle to a new ADJUSTINTENSITYRANGEGUI or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      ADJUSTINTENSITYRANGEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in ADJUSTINTENSITYRANGEGUI.M with the given input arguments.
  11. %
  12. %      ADJUSTINTENSITYRANGEGUI('Property','Value',...) creates a new ADJUSTINTENSITYRANGEGUI or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before adjustIntensityRangeGui_OpeningFunction gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to adjustIntensityRangeGui_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help adjustIntensityRangeGui
  23. % Last Modified by GUIDE v2.5 11-Aug-2004 09:30:47
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name',       mfilename, ...
  27.                    'gui_Singleton',  gui_Singleton, ...
  28.                    'gui_OpeningFcn', @adjustIntensityRangeGui_OpeningFcn, ...
  29.                    'gui_OutputFcn',  @adjustIntensityRangeGui_OutputFcn, ...
  30.                    'gui_LayoutFcn',  [] , ...
  31.                    'gui_Callback',   []);
  32. if nargin & isstr(varargin{1})
  33.     gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38.     gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. %--------------------------------------------------------
  42. % --- Executes just before adjustIntensityRangeGui is made visible.
  43. %--------------------------------------------------------
  44. function adjustIntensityRangeGui_OpeningFcn(hObject, eventdata, handles, varargin)
  45. % Choose default command line output for adjustIntensityRangeGui
  46. handles.output = hObject;
  47. hMainGui = getappdata(0,'hMainGui');
  48. intensityParam = getappdata(hMainGui,'intensityParam');
  49. set(handles.lowerEdit,'String',num2str(intensityParam.lowerLimit));
  50. set(handles.upperEdit,'String',num2str(intensityParam.upperLimit));
  51. handles.intensityParam = intensityParam;
  52. % Set the slider's value and step size
  53. handax=findobj(hMainGui,'tag','axes1');
  54. cimg = getimage(handax);
  55. cmin = intensityParam.minIntensity;
  56. cmax = intensityParam.maxIntensity;
  57. rng = cmax-cmin;
  58. if cmax == 0
  59.     cmin = 0; cmax = 1;
  60.     step_size = 1;
  61. elseif cmax <= 1
  62.     step_size = double(rng/256);
  63. else
  64.     step_size = 1/double(rng-1);
  65. end
  66. set(handles.lowerSlider,'Min',cmin,'Max',cmax,...
  67.     'Value', intensityParam.lowerLimit,'SliderStep',[step_size step_size]);
  68. set(handles.upperSlider,'Min',cmin,'Max',cmax,...
  69.     'Value',intensityParam.upperLimit,'SliderStep',[step_size step_size]);
  70. set(handles.upperEdit,'String',num2str(intensityParam.upperLimit));
  71. set(handles.lowerEdit,'String',num2str(intensityParam.lowerLimit));
  72. guidata(hObject, handles);
  73. %--------------------------------------------------------
  74. % --- Outputs from this function are returned to the command line.
  75. %--------------------------------------------------------
  76. function varargout = adjustIntensityRangeGui_OutputFcn(hObject, eventdata, handles)
  77. varargout{1} = handles.output;
  78. %--------------------------------------------------------
  79. % --- Executes during object creation, after setting all properties.
  80. %--------------------------------------------------------
  81. function lowerSlider_CreateFcn(hObject, eventdata, handles)
  82. usewhitebg = 1;
  83. if usewhitebg
  84.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  85. else
  86.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  87. end
  88. % --- Executes on slider movement.
  89. %--------------------------------------------------------
  90. function lowerSlider_Callback(hObject, eventdata, handles)
  91. lwLimit= round(get(hObject,'Value')); 
  92. upLimit = round(get(handles.upperSlider,'Value'));
  93. if lwLimit<upLimit
  94.     set(handles.lowerEdit,'String',num2str(lwLimit));
  95.     hMainGui = getappdata(0,'hMainGui');
  96.     handax=findobj(hMainGui,'tag','axes1');
  97.     ll = get(handax,'Clim');
  98.     set(handax,'Clim',[lwLimit ll(2)]);
  99.     handles.intensityParam.lowerLimit = lwLimit;
  100. else
  101.     errordlg('Lower limit cannot be larger than the upper');
  102. end
  103. guidata(hObject, handles);
  104. %--------------------------------------------------------
  105. % --- Executes during object creation, after setting all properties.
  106. function upperSlider_CreateFcn(hObject, eventdata, handles)
  107. usewhitebg = 1;
  108. if usewhitebg
  109.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  110. else
  111.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  112. end
  113. %--------------------------------------------------------
  114. % --- Executes on slider movement.
  115. %--------------------------------------------------------
  116. function upperSlider_Callback(hObject, eventdata, handles)
  117. upLimit= round(get(hObject,'Value')); 
  118. lwLimit = round(get(handles.lowerSlider,'Value'));
  119. if lwLimit < upLimit
  120.     set(handles.upperEdit,'String',num2str(upLimit));
  121.     hMainGui = getappdata(0,'hMainGui');
  122.     handax=findobj(hMainGui,'tag','axes1');
  123.     ll = get(handax,'Clim');
  124.     set(handax,'Clim',[ll(1) upLimit]);
  125.     handles.intensityParam.upperLimit = upLimit;
  126. else
  127.     errordlg('Lower limit cannot be larger than upper limit');
  128. end
  129. guidata(hObject, handles);
  130. %--------------------------------------------------------
  131. % --- Executes on button press in pushbuttonApply.
  132. %--------------------------------------------------------
  133. function pushbuttonApply_Callback(hObject, eventdata, handles)
  134. hMainGui = getappdata(0,'hMainGui');
  135. setappdata(hMainGui,'intensityParam',handles.intensityParam);
  136. % getappdata(hMainGui,'intensityParam')
  137. if ishandle(handles.figure1),
  138.     close(handles.figure1);
  139. end 
  140. %--------------------------------------------------------
  141. % --- Executes during object creation, after setting all properties.
  142. %--------------------------------------------------------
  143. function lowerEdit_CreateFcn(hObject, eventdata, handles)
  144. if ispc
  145.     set(hObject,'BackgroundColor','white');
  146. else
  147.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  148. end
  149. %--------------------------------------------------------
  150. %--------------------------------------------------------
  151. function lowerEdit_Callback(hObject, eventdata, handles)
  152. strg = get(hObject,'String');
  153. lwLimit =str2num(strg);
  154. upLimit = get(handles.upperSlider,'Value');
  155. maxLimit = get(handles.lowerSlider,'Max');
  156. if lwLimit <= maxLimit
  157.     if lwLimit < upLimit
  158.         set(handles.lowerSlider,'Value',lwLimit);
  159.         hMainGui = getappdata(0,'hMainGui');
  160.         handax=findobj(hMainGui,'tag','axes1');
  161.         ll = get(handax,'Clim');
  162.         set(handax,'CLim',[lwLimit ll(2)]);
  163.         handles.intensityParam.lowerLimit = lwLimit;
  164.     else
  165.         errordlg('Lower limit cannot be larger than upper limit');
  166.     end
  167. else
  168.     errordlg('Larger than maximum limit');
  169. end
  170. guidata(hObject, handles);
  171. %--------------------------------------------------------
  172. % --- Executes during object creation, after setting all properties.
  173. %--------------------------------------------------------
  174. function upperEdit_CreateFcn(hObject, eventdata, handles)
  175. if ispc
  176.     set(hObject,'BackgroundColor','white');
  177. else
  178.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  179. end
  180. %--------------------------------------------------------
  181. %--------------------------------------------------------
  182. function upperEdit_Callback(hObject, eventdata, handles)
  183. strg = get(hObject,'String');
  184. upLimit =str2num(strg);
  185. lwLimit = get(handles.lowerSlider,'Value');
  186. maxLimit = get(handles.lowerSlider,'Max');
  187. if upLimit <=maxLimit
  188.     if upLimit > lwLimit
  189.         set(handles.upperSlider,'Value',upLimit);
  190.         hMainGui = getappdata(0,'hMainGui');
  191.         handax=findobj(hMainGui,'tag','axes1');
  192.         ll = get(handax,'CLim');
  193.         set(handax,'CLim',[ll(1) upLimit]);
  194.         handles.intensityParam.upperLimit = upLimit;
  195.     else
  196.         errordlg('Lower limit cannot be larger than the upper');
  197.     end
  198. else
  199.     errordlg('Larger than maximum limit');
  200. end
  201. guidata(hObject, handles);
  202.     
  203. %--------------------------------------------------------
  204. % --- Executes on button press in pushbuttonCancel.
  205. function pushbuttonCancel_Callback(hObject, eventdata, handles)
  206. close(handles.figure1);