├── README.md ├── 运行结果.png ├── 程序源码 ├── imEnhance.fig └── imEnhance.m └── Readme.txt /README.md: -------------------------------------------------------------------------------- 1 | # Matlab-- 2 | Matlab-图像处理系统,图像增强,图像去噪,图像加噪,图像旋转,甚至还会画爱心~ 3 | -------------------------------------------------------------------------------- /运行结果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linxia676/Matlab--/HEAD/运行结果.png -------------------------------------------------------------------------------- /程序源码/imEnhance.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linxia676/Matlab--/HEAD/程序源码/imEnhance.fig -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | 具体演示视频已上传b站:https://www.bilibili.com/video/BV15V4y1c7Fu/?vd_source=372676ef036f12df9fc1244231cb2ca9 -------------------------------------------------------------------------------- /程序源码/imEnhance.m: -------------------------------------------------------------------------------- 1 | function varargout = imEnhance(varargin) 2 | % IMENHANCE MATLAB code for imEnhance.fig 3 | % IMENHANCE, by itself, creates a new IMENHANCE or raises the existing 4 | % singleton*. 5 | % 6 | % H = IMENHANCE returns the handle to a new IMENHANCE or the handle to 7 | % the existing singleton*. 8 | % 9 | % IMENHANCE('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in IMENHANCE.M with the given input arguments. 11 | % 12 | % IMENHANCE('Property','Value',...) creates a new IMENHANCE or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before imEnhance_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to imEnhance_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 | 23 | % Edit the above text to modify the response to help imEnhance 24 | 25 | % Last Modified by GUIDE v2.5 18-Dec-2022 16:54:17 26 | 27 | % Begin initialization code - DO NOT EDIT 28 | gui_Singleton = 1; 29 | gui_State = struct('gui_Name', mfilename, ... 30 | 'gui_Singleton', gui_Singleton, ... 31 | 'gui_OpeningFcn', @imEnhance_OpeningFcn, ... 32 | 'gui_OutputFcn', @imEnhance_OutputFcn, ... 33 | 'gui_LayoutFcn', [] , ... 34 | 'gui_Callback', []); 35 | if nargin && ischar(varargin{1}) 36 | gui_State.gui_Callback = str2func(varargin{1}); 37 | end 38 | 39 | if nargout 40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 41 | else 42 | gui_mainfcn(gui_State, varargin{:}); 43 | end 44 | % End initialization code - DO NOT EDIT 45 | 46 | 47 | % --- Executes just before imEnhance is made visible. 48 | function imEnhance_OpeningFcn(hObject, eventdata, handles, varargin) 49 | % This function has no output args, see OutputFcn. 50 | % hObject handle to figure 51 | % eventdata reserved - to be defined in a future version of MATLAB 52 | % handles structure with handles and user data (see GUIDATA) 53 | % varargin command line arguments to imEnhance (see VARARGIN) 54 | 55 | axes(handles.axes6);%获取轴区域句柄 56 | x = -2 : 1 / 400 : 2; 57 | y = abs(x .^ (2/3)) + (0.99 * (3.3 - x .^ 2) .^ (1/2)) .* sin(4 * pi * x); 58 | plot(x, y, 'r'); 59 | 60 | % Choose default command line output for imEnhance 61 | handles.output = hObject; 62 | 63 | % Update handles structure 64 | guidata(hObject, handles); 65 | 66 | % UIWAIT makes imEnhance wait for user response (see UIRESUME) 67 | % uiwait(handles.figure1); 68 | 69 | 70 | % --- Outputs from this function are returned to the command line. 71 | function varargout = imEnhance_OutputFcn(hObject, eventdata, handles) 72 | % varargout cell array for returning output args (see VARARGOUT); 73 | % hObject handle to figure 74 | % eventdata reserved - to be defined in a future version of MATLAB 75 | % handles structure with handles and user data (see GUIDATA) 76 | 77 | % Get default command line output from handles structure 78 | varargout{1} = handles.output; 79 | 80 | 81 | % --- Executes on button press in pushbutton1. 82 | function pushbutton1_Callback(hObject, eventdata, handles) 83 | % hObject handle to pushbutton1 (see GCBO) 84 | % eventdata reserved - to be defined in a future version of MATLAB 85 | % handles structure with handles and user data (see GUIDATA) 86 | 87 | % 声明要用到的全局变量 88 | global Image_Original; 89 | global Image_Gray; 90 | global Latest_Image; 91 | 92 | [filename,pathname]=uigetfile('*.*','打开图像'); 93 | filepath=[pathname filename]; 94 | Image_Original=imread(filepath); 95 | 96 | if size(Image_Original, 3)>2 % 判断是否为彩色图像 97 | Image_Gray = rgb2gray(Image_Original); % 将彩色图像转换为灰度图像 98 | else 99 | Image_Gray = Image_Original; 100 | end 101 | Latest_Image = Image_Gray; % 保存最新图像,用于图片保存功能 102 | 103 | axes(handles.axes1);%获取轴区域句柄 104 | imshow(Image_Original); 105 | title('原图像', 'Fontsize', 12); 106 | axes(handles.axes2);%获取轴区域句柄 107 | imhist(Latest_Image); 108 | title('图像直方图', 'Fontsize', 12); 109 | axes(handles.axes3);%获取轴区域句柄 110 | imshow(Image_Gray); 111 | title('灰度图', 'Fontsize', 12); 112 | axes(handles.axes4);%获取轴区域句柄 113 | imshow(Image_Gray); 114 | title('灰度图', 'Fontsize', 12); 115 | axes(handles.axes5);%获取轴区域句柄 116 | imshow(Image_Gray); 117 | title('灰度图', 'Fontsize', 12); 118 | 119 | % --- Executes on button press in pushbutton2. 120 | function pushbutton2_Callback(hObject, eventdata, handles) 121 | % hObject handle to pushbutton2 (see GCBO) 122 | % eventdata reserved - to be defined in a future version of MATLAB 123 | % handles structure with handles and user data (see GUIDATA) 124 | global Latest_Image; 125 | imwrite(Latest_Image,'result.jpg'); %默认保存在当前文件夹中 126 | 127 | % --- Executes on button press in pushbutton3. 128 | function pushbutton3_Callback(hObject, eventdata, handles) 129 | % hObject handle to pushbutton3 (see GCBO) 130 | % eventdata reserved - to be defined in a future version of MATLAB 131 | % handles structure with handles and user data (see GUIDATA) 132 | global Image_Original;%声明全局变量 133 | global Image_Gray; 134 | global Latest_Image; 135 | 136 | if get(handles.radiobutton1,'value') 137 | radio_button = 1; 138 | elseif get(handles.radiobutton2,'value') 139 | radio_button = 2; 140 | elseif get(handles.radiobutton3,'value') 141 | radio_button = 3; 142 | elseif get(handles.radiobutton5,'value') 143 | radio_button = 5; 144 | elseif get(handles.radiobutton6,'value') 145 | radio_button = 6; 146 | elseif get(handles.radiobutton7,'value') 147 | radio_button = 7; 148 | end 149 | switch (radio_button) 150 | case 1 % 灰度图像取反 151 | Inverse_Image = imcomplement(Image_Gray); 152 | Latest_Image = Inverse_Image; % 保存最新图像,用于图片保存功能 153 | axes(handles.axes3); % 获取轴区域句柄 154 | imshow(Inverse_Image); 155 | title('灰度图取反图像'); 156 | case 2 % 彩色图像取反 157 | Color_Image(:,:,1)=255-Image_Original(:,:,1); 158 | Color_Image(:,:,2)=255-Image_Original(:,:,2); 159 | Color_Image(:,:,3)=255-Image_Original(:,:,3); 160 | Latest_Image = Color_Image;%保存最新图像,用于图片保存功能 161 | axes(handles.axes3); % 获取轴区域句柄 162 | imshow(Color_Image); 163 | title('彩色图取反图像'); 164 | case 3 % 直方图均衡化 165 | Histeq_Image = histeq(Image_Gray,16); 166 | axes(handles.axes3); % 获取轴区域句柄 167 | imshow(Histeq_Image); 168 | Latest_Image = Histeq_Image;%保存最新图像,用于图片保存功能 169 | title('灰度图直方图均衡化'); 170 | 171 | % case 4 % 直方图 172 | % axes(handles.axes3);%获取轴区域句柄 173 | % imhist(Latest_Image); 174 | % title('图像直方图'); 175 | 176 | case 5 % sobel算子锐化图像 177 | Sobel_Image = edge(Image_Gray,'sobel'); %sobel算子锐化 178 | axes(handles.axes3);%获取轴区域句柄 179 | imshow(Sobel_Image); 180 | Latest_Image = Sobel_Image;%保存最新图像,用于图片保存功能 181 | title('sobel算子锐化灰度图像'); 182 | 183 | case 6 % prewitt算子锐化图像 184 | Prewitt_Image = edge(Image_Gray,'prewitt'); %roberts算子锐化 185 | axes(handles.axes3);%获取轴区域句柄 186 | imshow(Prewitt_Image); 187 | Latest_Image = Prewitt_Image;%保存最新图像,用于图片保存功能 188 | title('prewitt算子锐化灰度图像'); 189 | 190 | case 7 % roberts算子锐化图像 191 | Roberts_Image = edge(Image_Gray,'roberts'); %roberts算子锐化 192 | axes(handles.axes3);%获取轴区域句柄 193 | imshow(Roberts_Image); 194 | Latest_Image = Roberts_Image;%保存最新图像,用于图片保存功能 195 | title('roberts算子锐化灰度图像'); 196 | end 197 | 198 | 199 | % --- Executes on button press in pushbutton4. 200 | function pushbutton4_Callback(hObject, eventdata, handles) 201 | % hObject handle to pushbutton4 (see GCBO) 202 | % eventdata reserved - to be defined in a future version of MATLAB 203 | % handles structure with handles and user data (see GUIDATA) 204 | global Image_Original;%再次声明全局变量 205 | global Image_Gray; 206 | global Latest_Image; 207 | global noise_enable; 208 | global Noise_Image; 209 | 210 | if get(handles.radiobutton8,'value') 211 | radio_button = 1; 212 | elseif get(handles.radiobutton9,'value') 213 | radio_button = 2; 214 | elseif get(handles.radiobutton10,'value') 215 | radio_button = 3; 216 | elseif get(handles.radiobutton11,'value') 217 | radio_button = 4; 218 | end 219 | switch radio_button 220 | case 1 % 高斯噪声 221 | Gaussian_Mean= str2num(get(handles.edit1,'String'));%均值 222 | Gaussian_Var= str2num(get(handles.edit2,'String'));%方差 223 | if(noise_enable == 1)%是否连续加入噪声 224 | Gaussian_Image = imnoise(Latest_Image,'gaussian',Gaussian_Mean,Gaussian_Var);%加入高斯噪声 225 | else%灰度图加入一次噪声 226 | Gaussian_Image = imnoise(Image_Gray,'gaussian',Gaussian_Mean,Gaussian_Var);%加入高斯噪声 227 | end 228 | Latest_Image = Gaussian_Image;%保存最新图像,用于图片保存功能 229 | axes(handles.axes4);%获取轴区域句柄 230 | imshow(Gaussian_Image); 231 | title('高斯噪声'); 232 | case 2 % 椒盐噪声 233 | Salt_Density = str2num(get(handles.edit3,'String'));%均值 234 | if(noise_enable == 1)%是否连续加入噪声 235 | Salt_Image = imnoise(Latest_Image,'salt & pepper',Salt_Density);%加入椒盐噪声 236 | else 237 | Salt_Image = imnoise(Image_Gray,'salt & pepper',Salt_Density);%加入椒盐噪声 238 | end 239 | Latest_Image = Salt_Image;%保存最新图像,用于图片保存功能 240 | axes(handles.axes4);%获取轴区域句柄 241 | imshow(Salt_Image); 242 | title('椒盐噪声'); 243 | case 3 % 泊松噪声 244 | Poisson_Probability= str2num(get(handles.edit4,'String'));%方差 245 | if(noise_enable == 1)%是否连续加入噪声 246 | Poisson_Image = imnoise(Latest_Image,'poisson');%加入泊松噪声 247 | else%灰度图加入一次噪声 248 | Poisson_Image = imnoise(Image_Gray,'poisson');%加入泊松噪声 249 | end 250 | Latest_Image = Poisson_Image;%保存最新图像,用于图片保存功能 251 | axes(handles.axes4);%获取轴区域句柄 252 | imshow(Poisson_Image); 253 | title('泊松噪声'); 254 | 255 | case 4%乘性噪声 256 | Multiplicative_Var= str2num(get(handles.edit5,'String'));%方差 257 | if(noise_enable == 1)%是否连续加入噪声 258 | Multiplicative_Image = imnoise(Latest_Image,'speckle',Multiplicative_Var);%加入乘性噪声 259 | else 260 | Multiplicative_Image = imnoise(Image_Gray,'speckle',Multiplicative_Var);%加入乘性噪声 261 | end 262 | Latest_Image = Multiplicative_Image;%保存最新图像,用于图片保存功能 263 | axes(handles.axes4);%获取轴区域句柄 264 | imshow(Multiplicative_Image); 265 | title('乘性噪声'); 266 | end 267 | Noise_Image = Latest_Image; 268 | 269 | % --- Executes on button press in checkbox1. 270 | function checkbox1_Callback(hObject, eventdata, handles) 271 | % hObject handle to checkbox1 (see GCBO) 272 | % eventdata reserved - to be defined in a future version of MATLAB 273 | % handles structure with handles and user data (see GUIDATA) 274 | global noise_enable; 275 | noise_enable = 0; 276 | if ( get(hObject,'Value') ) 277 | noise_enable = 1; 278 | else 279 | noise_enable = 0; 280 | end 281 | % Hint: get(hObject,'Value') returns toggle state of checkbox1 282 | 283 | 284 | 285 | function edit1_Callback(hObject, eventdata, handles) 286 | % hObject handle to edit1 (see GCBO) 287 | % eventdata reserved - to be defined in a future version of MATLAB 288 | % handles structure with handles and user data (see GUIDATA) 289 | 290 | % Hints: get(hObject,'String') returns contents of edit1 as text 291 | % str2double(get(hObject,'String')) returns contents of edit1 as a double 292 | 293 | 294 | % --- Executes during object creation, after setting all properties. 295 | function edit1_CreateFcn(hObject, eventdata, handles) 296 | % hObject handle to edit1 (see GCBO) 297 | % eventdata reserved - to be defined in a future version of MATLAB 298 | % handles empty - handles not created until after all CreateFcns called 299 | 300 | % Hint: edit controls usually have a white background on Windows. 301 | % See ISPC and COMPUTER. 302 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 303 | set(hObject,'BackgroundColor','white'); 304 | end 305 | 306 | 307 | 308 | function edit2_Callback(hObject, eventdata, handles) 309 | % hObject handle to edit2 (see GCBO) 310 | % eventdata reserved - to be defined in a future version of MATLAB 311 | % handles structure with handles and user data (see GUIDATA) 312 | 313 | % Hints: get(hObject,'String') returns contents of edit2 as text 314 | % str2double(get(hObject,'String')) returns contents of edit2 as a double 315 | 316 | 317 | % --- Executes during object creation, after setting all properties. 318 | function edit2_CreateFcn(hObject, eventdata, handles) 319 | % hObject handle to edit2 (see GCBO) 320 | % eventdata reserved - to be defined in a future version of MATLAB 321 | % handles empty - handles not created until after all CreateFcns called 322 | 323 | % Hint: edit controls usually have a white background on Windows. 324 | % See ISPC and COMPUTER. 325 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 326 | set(hObject,'BackgroundColor','white'); 327 | end 328 | 329 | 330 | 331 | function edit3_Callback(hObject, eventdata, handles) 332 | % hObject handle to edit3 (see GCBO) 333 | % eventdata reserved - to be defined in a future version of MATLAB 334 | % handles structure with handles and user data (see GUIDATA) 335 | 336 | % Hints: get(hObject,'String') returns contents of edit3 as text 337 | % str2double(get(hObject,'String')) returns contents of edit3 as a double 338 | 339 | 340 | % --- Executes during object creation, after setting all properties. 341 | function edit3_CreateFcn(hObject, eventdata, handles) 342 | % hObject handle to edit3 (see GCBO) 343 | % eventdata reserved - to be defined in a future version of MATLAB 344 | % handles empty - handles not created until after all CreateFcns called 345 | 346 | % Hint: edit controls usually have a white background on Windows. 347 | % See ISPC and COMPUTER. 348 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 349 | set(hObject,'BackgroundColor','white'); 350 | end 351 | 352 | 353 | 354 | function edit4_Callback(hObject, eventdata, handles) 355 | % hObject handle to edit4 (see GCBO) 356 | % eventdata reserved - to be defined in a future version of MATLAB 357 | % handles structure with handles and user data (see GUIDATA) 358 | 359 | % Hints: get(hObject,'String') returns contents of edit4 as text 360 | % str2double(get(hObject,'String')) returns contents of edit4 as a double 361 | 362 | 363 | % --- Executes during object creation, after setting all properties. 364 | function edit4_CreateFcn(hObject, eventdata, handles) 365 | % hObject handle to edit4 (see GCBO) 366 | % eventdata reserved - to be defined in a future version of MATLAB 367 | % handles empty - handles not created until after all CreateFcns called 368 | 369 | % Hint: edit controls usually have a white background on Windows. 370 | % See ISPC and COMPUTER. 371 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 372 | set(hObject,'BackgroundColor','white'); 373 | end 374 | 375 | 376 | 377 | function edit5_Callback(hObject, eventdata, handles) 378 | % hObject handle to edit5 (see GCBO) 379 | % eventdata reserved - to be defined in a future version of MATLAB 380 | % handles structure with handles and user data (see GUIDATA) 381 | 382 | % Hints: get(hObject,'String') returns contents of edit5 as text 383 | % str2double(get(hObject,'String')) returns contents of edit5 as a double 384 | 385 | 386 | % --- Executes during object creation, after setting all properties. 387 | function edit5_CreateFcn(hObject, eventdata, handles) 388 | % hObject handle to edit5 (see GCBO) 389 | % eventdata reserved - to be defined in a future version of MATLAB 390 | % handles empty - handles not created until after all CreateFcns called 391 | 392 | % Hint: edit controls usually have a white background on Windows. 393 | % See ISPC and COMPUTER. 394 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 395 | set(hObject,'BackgroundColor','white'); 396 | end 397 | 398 | 399 | 400 | function edit6_Callback(hObject, eventdata, handles) 401 | % hObject handle to edit6 (see GCBO) 402 | % eventdata reserved - to be defined in a future version of MATLAB 403 | % handles structure with handles and user data (see GUIDATA) 404 | 405 | % Hints: get(hObject,'String') returns contents of edit6 as text 406 | % str2double(get(hObject,'String')) returns contents of edit6 as a double 407 | 408 | 409 | % --- Executes during object creation, after setting all properties. 410 | function edit6_CreateFcn(hObject, eventdata, handles) 411 | % hObject handle to edit6 (see GCBO) 412 | % eventdata reserved - to be defined in a future version of MATLAB 413 | % handles empty - handles not created until after all CreateFcns called 414 | 415 | % Hint: edit controls usually have a white background on Windows. 416 | % See ISPC and COMPUTER. 417 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 418 | set(hObject,'BackgroundColor','white'); 419 | end 420 | 421 | 422 | 423 | function edit7_Callback(hObject, eventdata, handles) 424 | % hObject handle to edit7 (see GCBO) 425 | % eventdata reserved - to be defined in a future version of MATLAB 426 | % handles structure with handles and user data (see GUIDATA) 427 | 428 | % Hints: get(hObject,'String') returns contents of edit7 as text 429 | % str2double(get(hObject,'String')) returns contents of edit7 as a double 430 | 431 | 432 | % --- Executes during object creation, after setting all properties. 433 | function edit7_CreateFcn(hObject, eventdata, handles) 434 | % hObject handle to edit7 (see GCBO) 435 | % eventdata reserved - to be defined in a future version of MATLAB 436 | % handles empty - handles not created until after all CreateFcns called 437 | 438 | % Hint: edit controls usually have a white background on Windows. 439 | % See ISPC and COMPUTER. 440 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 441 | set(hObject,'BackgroundColor','white'); 442 | end 443 | 444 | 445 | % --- Executes on button press in pushbutton5. 446 | function pushbutton5_Callback(hObject, eventdata, handles) 447 | % hObject handle to pushbutton5 (see GCBO) 448 | % eventdata reserved - to be defined in a future version of MATLAB 449 | % handles structure with handles and user data (see GUIDATA) 450 | 451 | global Image_Original;%再次声明全局变量 452 | global Image_Gray; 453 | global Latest_Image; 454 | global filter_enable; 455 | global Noise_Image; 456 | 457 | if get(handles.radiobutton12,'value') 458 | radio_button = 1; 459 | elseif get(handles.radiobutton13,'value') 460 | radio_button = 2; 461 | elseif get(handles.radiobutton14,'value') 462 | radio_button = 3; 463 | end 464 | 465 | switch radio_button 466 | case 1 % 中值滤波 467 | Median_Num = str2num(get(handles.edit6,'String'));%中值模版大小 468 | if(filter_enable == 1)%是否连续加入噪声 469 | Median_Image = medfilt2(Latest_Image, [Median_Num Median_Num]); 470 | else%灰度图加入一次噪声 471 | Median_Image = medfilt2(Noise_Image, [Median_Num Median_Num]); 472 | end 473 | Latest_Image = Median_Image;%保存最新图像,用于图片保存功能 474 | axes(handles.axes5);%获取轴区域句柄 475 | imshow(Median_Image); 476 | title('中值滤波'); 477 | case 2 % 均值滤波 478 | Medfilt_Num = str2num(get(handles.edit7,'String')); 479 | H = fspecial('average',[Medfilt_Num Medfilt_Num]); 480 | if(filter_enable == 1)%是否连续加入噪声 481 | Medfilt_Image = uint8(filter2(H, Latest_Image)); 482 | else%灰度图加入一次噪声 483 | Medfilt_Image = uint8(filter2(H, Noise_Image)); 484 | end 485 | Latest_Image = Medfilt_Image;%保存最新图像,用于图片保存功能 486 | axes(handles.axes5);%获取轴区域句柄 487 | imshow(Medfilt_Image); 488 | title('均值滤波'); 489 | case 3 % 维纳滤波 490 | Wiener_Num = str2num(get(handles.edit8,'String')); 491 | if(filter_enable == 1)%是否连续加入噪声 492 | Wiener_Image = wiener2(Latest_Image, [Wiener_Num Wiener_Num]); 493 | else % 灰度图加入一次噪声 494 | Wiener_Image = wiener2(Noise_Image, [Wiener_Num Wiener_Num]); 495 | end 496 | Latest_Image = Wiener_Image; % 保存最新图像,用于图片保存功能 497 | axes(handles.axes5);%获取轴区域句柄 498 | imshow(Wiener_Image); 499 | title('维纳滤波'); 500 | end 501 | 502 | % --- Executes on button press in checkbox2. 503 | function checkbox2_Callback(hObject, eventdata, handles) 504 | % hObject handle to checkbox2 (see GCBO) 505 | % eventdata reserved - to be defined in a future version of MATLAB 506 | % handles structure with handles and user data (see GUIDATA) 507 | 508 | % Hint: get(hObject,'Value') returns toggle state of checkbox2 509 | global filter_enable; 510 | filter_enable = 0; 511 | if ( get(hObject,'Value') ) 512 | filter_enable = 1; 513 | else 514 | filter_enable = 0; 515 | end 516 | 517 | 518 | function edit11_Callback(hObject, eventdata, handles) 519 | % hObject handle to edit11 (see GCBO) 520 | % eventdata reserved - to be defined in a future version of MATLAB 521 | % handles structure with handles and user data (see GUIDATA) 522 | 523 | % Hints: get(hObject,'String') returns contents of edit11 as text 524 | % str2double(get(hObject,'String')) returns contents of edit11 as a double 525 | 526 | 527 | % --- Executes during object creation, after setting all properties. 528 | function edit11_CreateFcn(hObject, eventdata, handles) 529 | % hObject handle to edit11 (see GCBO) 530 | % eventdata reserved - to be defined in a future version of MATLAB 531 | % handles empty - handles not created until after all CreateFcns called 532 | 533 | % Hint: edit controls usually have a white background on Windows. 534 | % See ISPC and COMPUTER. 535 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 536 | set(hObject,'BackgroundColor','white'); 537 | end 538 | 539 | 540 | 541 | function edit13_Callback(hObject, eventdata, handles) 542 | % hObject handle to edit6 (see GCBO) 543 | % eventdata reserved - to be defined in a future version of MATLAB 544 | % handles structure with handles and user data (see GUIDATA) 545 | 546 | % Hints: get(hObject,'String') returns contents of edit6 as text 547 | % str2double(get(hObject,'String')) returns contents of edit6 as a double 548 | 549 | 550 | % --- Executes during object creation, after setting all properties. 551 | function edit13_CreateFcn(hObject, eventdata, handles) 552 | % hObject handle to edit6 (see GCBO) 553 | % eventdata reserved - to be defined in a future version of MATLAB 554 | % handles empty - handles not created until after all CreateFcns called 555 | 556 | % Hint: edit controls usually have a white background on Windows. 557 | % See ISPC and COMPUTER. 558 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 559 | set(hObject,'BackgroundColor','white'); 560 | end 561 | 562 | 563 | 564 | function edit14_Callback(hObject, eventdata, handles) 565 | % hObject handle to edit7 (see GCBO) 566 | % eventdata reserved - to be defined in a future version of MATLAB 567 | % handles structure with handles and user data (see GUIDATA) 568 | 569 | % Hints: get(hObject,'String') returns contents of edit7 as text 570 | % str2double(get(hObject,'String')) returns contents of edit7 as a double 571 | 572 | 573 | % --- Executes during object creation, after setting all properties. 574 | function edit14_CreateFcn(hObject, eventdata, handles) 575 | % hObject handle to edit7 (see GCBO) 576 | % eventdata reserved - to be defined in a future version of MATLAB 577 | % handles empty - handles not created until after all CreateFcns called 578 | 579 | % Hint: edit controls usually have a white background on Windows. 580 | % See ISPC and COMPUTER. 581 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 582 | set(hObject,'BackgroundColor','white'); 583 | end 584 | 585 | 586 | 587 | function edit8_Callback(hObject, eventdata, handles) 588 | % hObject handle to edit8 (see GCBO) 589 | % eventdata reserved - to be defined in a future version of MATLAB 590 | % handles structure with handles and user data (see GUIDATA) 591 | 592 | % Hints: get(hObject,'String') returns contents of edit8 as text 593 | % str2double(get(hObject,'String')) returns contents of edit8 as a double 594 | 595 | 596 | % --- Executes during object creation, after setting all properties. 597 | function edit8_CreateFcn(hObject, eventdata, handles) 598 | % hObject handle to edit8 (see GCBO) 599 | % eventdata reserved - to be defined in a future version of MATLAB 600 | % handles empty - handles not created until after all CreateFcns called 601 | 602 | % Hint: edit controls usually have a white background on Windows. 603 | % See ISPC and COMPUTER. 604 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 605 | set(hObject,'BackgroundColor','white'); 606 | end 607 | 608 | 609 | % --- Executes on button press in pushbutton6. 610 | function pushbutton6_Callback(hObject, eventdata, handles) 611 | % hObject handle to pushbutton6 (see GCBO) 612 | % eventdata reserved - to be defined in a future version of MATLAB 613 | % handles structure with handles and user data (see GUIDATA) 614 | global Image_Original;%声明全局变量 615 | global Image_Gray; 616 | global Latest_Image; 617 | axes(handles.axes2);%获取轴区域句柄 618 | imhist(Latest_Image); 619 | title('图像直方图'); 620 | 621 | % --- Executes on button press in pushbutton7. 622 | function pushbutton7_Callback(hObject, eventdata, handles) 623 | % hObject handle to pushbutton7 (see GCBO) 624 | % eventdata reserved - to be defined in a future version of MATLAB 625 | % handles structure with handles and user data (see GUIDATA) 626 | global Image_Gray; 627 | global Latest_Image; 628 | Latest_Image = Image_Gray; 629 | axes(handles.axes2);%获取轴区域句柄 630 | imhist(Latest_Image); 631 | title('图像直方图', 'Fontsize', 12); 632 | axes(handles.axes3);%获取轴区域句柄 633 | imshow(Image_Gray); 634 | title('灰度图', 'Fontsize', 12); 635 | axes(handles.axes4);%获取轴区域句柄 636 | imshow(Image_Gray); 637 | axes(handles.axes5);%获取轴区域句柄 638 | imshow(Image_Gray); 639 | 640 | % --- Executes on slider movement. 641 | function slider1_Callback(hObject, eventdata, handles) 642 | % hObject handle to slider1 (see GCBO) 643 | % eventdata reserved - to be defined in a future version of MATLAB 644 | % handles structure with handles and user data (see GUIDATA) 645 | T = get(handles.slider1, 'value'); 646 | set(handles.text14, 'String', num2str(uint8(T))); 647 | % Hints: get(hObject,'Value') returns position of slider 648 | % get(hObject,'Min') and get(hObject,'Max') to determine range of slider 649 | 650 | 651 | % --- Executes during object creation, after setting all properties. 652 | function slider1_CreateFcn(hObject, eventdata, handles) 653 | % hObject handle to slider1 (see GCBO) 654 | % eventdata reserved - to be defined in a future version of MATLAB 655 | % handles empty - handles not created until after all CreateFcns called 656 | 657 | % Hint: slider controls usually have a light gray background. 658 | if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 659 | set(hObject,'BackgroundColor',[.9 .9 .9]); 660 | end 661 | 662 | 663 | % --- Executes on button press in pushbutton9. 664 | function pushbutton9_Callback(hObject, eventdata, handles) 665 | % hObject handle to pushbutton9 (see GCBO) 666 | % eventdata reserved - to be defined in a future version of MATLAB 667 | % handles structure with handles and user data (see GUIDATA) 668 | global Latest_Image; 669 | global Image_Gray; 670 | 671 | if get(handles.radiobutton18,'value') %人工选取阈值 672 | d0 = get(handles.slider1, 'value'); 673 | Latest_Image = im2bw(Image_Gray, d0 / 255); 674 | elseif get(handles.radiobutton19,'value') % Ostu法 675 | T = graythresh(Image_Gray); 676 | Latest_Image = im2bw(Image_Gray, T); 677 | end 678 | axes(handles.axes3);%获取轴区域句柄 679 | imshow(Latest_Image); 680 | title('人工选取阈值', 'Fontsize', 12); 681 | 682 | 683 | % --- Executes on slider movement. 684 | function slider2_Callback(hObject, eventdata, handles) 685 | % hObject handle to slider2 (see GCBO) 686 | % eventdata reserved - to be defined in a future version of MATLAB 687 | % handles structure with handles and user data (see GUIDATA) 688 | global Image_Original;%声明全局变量 689 | global colour_enable; 690 | global Latest_Image; 691 | global Image_Gray; 692 | angle = int16(get(handles.slider2, 'value')); 693 | set(handles.text15, 'String', ['角度为',num2str(angle), '°']); 694 | if (colour_enable == 1) 695 | Latest_Image = imrotate(Image_Original, angle, 'bicubic', 'loose'); 696 | else 697 | Latest_Image = imrotate(Image_Gray, angle, 'bicubic', 'loose'); 698 | end 699 | 700 | axes(handles.axes4);%获取轴区域句柄 701 | imshow(Latest_Image); 702 | title('旋转后的图像', 'Fontsize', 12); 703 | % Hints: get(hObject,'Value') returns position of slider 704 | % get(hObject,'Min') and get(hObject,'Max') to determine range of slider 705 | 706 | 707 | % --- Executes during object creation, after setting all properties. 708 | function slider2_CreateFcn(hObject, eventdata, handles) 709 | % hObject handle to slider2 (see GCBO) 710 | % eventdata reserved - to be defined in a future version of MATLAB 711 | % handles empty - handles not created until after all CreateFcns called 712 | 713 | % Hint: slider controls usually have a light gray background. 714 | if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 715 | set(hObject,'BackgroundColor',[.9 .9 .9]); 716 | end 717 | 718 | 719 | % --- Executes on button press in checkbox3. 720 | function checkbox3_Callback(hObject, eventdata, handles) 721 | % hObject handle to checkbox3 (see GCBO) 722 | % eventdata reserved - to be defined in a future version of MATLAB 723 | % handles structure with handles and user data (see GUIDATA) 724 | global colour_enable; 725 | colour_enable = 0; 726 | if ( get(hObject,'Value') ) 727 | colour_enable = 1; 728 | else 729 | colour_enable = 0; 730 | end 731 | % Hint: get(hObject,'Value') returns toggle state of checkbox3 732 | 733 | 734 | % --- Executes on slider movement. 735 | function slider3_Callback(hObject, eventdata, handles) 736 | % hObject handle to slider3 (see GCBO) 737 | % eventdata reserved - to be defined in a future version of MATLAB 738 | % handles structure with handles and user data (see GUIDATA) 739 | axes(handles.axes6);%获取轴区域句柄 740 | a = get(handles.slider3 , 'Value'); 741 | if a < 11 % 参数小于11则显示爱心曲线 742 | x = -2 : 1 / 400 : 2; 743 | y = abs(x .^ (2/3)) + (0.99 * (3.3 - x .^ 2) .^ (1/2)) .* sin(a * pi * x); 744 | plot(x, y, 'r'); 745 | else % 参数大于11则显示三维爱心 746 | axes(handles.axes6); 747 | f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3; 748 | [x,y,z]=meshgrid(linspace(-3,3)); 749 | val=f(x,y,z); 750 | [p,v]=isosurface(x,y,z,val,0); 751 | patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat'); 752 | view(3);grid on;axis equal; 753 | set(handles.text16, 'String', 'Designed by Hao_XL'); 754 | end 755 | 756 | 757 | % Hints: get(hObject,'Value') returns position of slider 758 | % get(hObject,'Min') and get(hObject,'Max') to determine range of slider 759 | 760 | 761 | % --- Executes during object creation, after setting all properties. 762 | function slider3_CreateFcn(hObject, eventdata, handles) 763 | % hObject handle to slider3 (see GCBO) 764 | % eventdata reserved - to be defined in a future version of MATLAB 765 | % handles empty - handles not created until after all CreateFcns called 766 | 767 | % Hint: slider controls usually have a light gray background. 768 | if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 769 | set(hObject,'BackgroundColor',[.9 .9 .9]); 770 | end 771 | --------------------------------------------------------------------------------