├── .gitattributes ├── GUI.fig ├── gui1.m ├── gui2.m ├── gui1.fig ├── gui2.fig ├── megui.fig ├── mygui.fig ├── GUI.m ├── megui.m └── mygui.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /GUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/GUI.fig -------------------------------------------------------------------------------- /gui1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/gui1.m -------------------------------------------------------------------------------- /gui2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/gui2.m -------------------------------------------------------------------------------- /gui1.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/gui1.fig -------------------------------------------------------------------------------- /gui2.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/gui2.fig -------------------------------------------------------------------------------- /megui.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/megui.fig -------------------------------------------------------------------------------- /mygui.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trist-wood/Digital-image-processing-system/HEAD/mygui.fig -------------------------------------------------------------------------------- /GUI.m: -------------------------------------------------------------------------------- 1 | function varargout = GUI(varargin) 2 | % GUI MATLAB code for GUI.fig 3 | % GUI, by itself, creates a new GUI or raises the existing 4 | % singleton*. 5 | % 6 | % H = GUI returns the handle to a new GUI or the handle to 7 | % the existing singleton*. 8 | % 9 | % GUI('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in GUI.M with the given input arguments. 11 | % 12 | % GUI('Property','Value',...) creates a new GUI or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before GUI_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to GUI_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 GUI 24 | 25 | % Last Modified by GUIDE v2.5 08-May-2024 15:20:41 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', @GUI_OpeningFcn, ... 32 | 'gui_OutputFcn', @GUI_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 GUI is made visible. 48 | function GUI_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 GUI (see VARARGIN) 54 | 55 | % Choose default command line output for GUI 56 | handles.output = hObject; 57 | 58 | % Update handles structure 59 | guidata(hObject, handles); 60 | 61 | % UIWAIT makes GUI wait for user response (see UIRESUME) 62 | % uiwait(handles.figure1); 63 | 64 | 65 | % --- Outputs from this function are returned to the command line. 66 | function varargout = GUI_OutputFcn(hObject, eventdata, handles) 67 | % varargout cell array for returning output args (see VARARGOUT); 68 | % hObject handle to figure 69 | % eventdata reserved - to be defined in a future version of MATLAB 70 | % handles structure with handles and user data (see GUIDATA) 71 | 72 | % Get default command line output from handles structure 73 | varargout{1} = handles.output; 74 | -------------------------------------------------------------------------------- /megui.m: -------------------------------------------------------------------------------- 1 | function varargout = megui(varargin) 2 | % MEGUI MATLAB code for megui.fig 3 | % MEGUI, by itself, creates a new MEGUI or raises the existing 4 | % singleton*. 5 | % 6 | % H = MEGUI returns the handle to a new MEGUI or the handle to 7 | % the existing singleton*. 8 | % 9 | % MEGUI('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in MEGUI.M with the given input arguments. 11 | % 12 | % MEGUI('Property','Value',...) creates a new MEGUI or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before megui_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to megui_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 megui 24 | 25 | % Last Modified by GUIDE v2.5 08-May-2024 17:54:22 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', @megui_OpeningFcn, ... 32 | 'gui_OutputFcn', @megui_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 megui is made visible. 48 | function megui_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 megui (see VARARGIN) 54 | 55 | % Choose default command line output for megui 56 | handles.output = hObject; 57 | 58 | % Update handles structure 59 | guidata(hObject, handles); 60 | 61 | % UIWAIT makes megui wait for user response (see UIRESUME) 62 | % uiwait(handles.figure1); 63 | 64 | 65 | % --- Outputs from this function are returned to the command line. 66 | function varargout = megui_OutputFcn(hObject, eventdata, handles) 67 | % varargout cell array for returning output args (see VARARGOUT); 68 | % hObject handle to figure 69 | % eventdata reserved - to be defined in a future version of MATLAB 70 | % handles structure with handles and user data (see GUIDATA) 71 | 72 | % Get default command line output from handles structure 73 | varargout{1} = handles.output; 74 | 75 | 76 | % -------------------------------------------------------------------- 77 | function File_Callback(hObject, eventdata, handles) 78 | % hObject handle to File (see GCBO) 79 | % eventdata reserved - to be defined in a future version of MATLAB 80 | % handles structure with handles and user data (see GUIDATA) 81 | 82 | 83 | % -------------------------------------------------------------------- 84 | function transformation_Callback(hObject, eventdata, handles) 85 | % hObject handle to transformation (see GCBO) 86 | % eventdata reserved - to be defined in a future version of MATLAB 87 | % handles structure with handles and user data (see GUIDATA) 88 | 89 | 90 | % -------------------------------------------------------------------- 91 | function enhancement_Callback(hObject, eventdata, handles) 92 | % hObject handle to enhancement (see GCBO) 93 | % eventdata reserved - to be defined in a future version of MATLAB 94 | % handles structure with handles and user data (see GUIDATA) 95 | 96 | 97 | % -------------------------------------------------------------------- 98 | function tuxiangfenge_Callback(hObject, eventdata, handles) 99 | % hObject handle to tuxiangfenge (see GCBO) 100 | % eventdata reserved - to be defined in a future version of MATLAB 101 | % handles structure with handles and user data (see GUIDATA) 102 | 103 | 104 | % -------------------------------------------------------------------- 105 | function tuxianglvbo_Callback(hObject, eventdata, handles) 106 | % hObject handle to tuxianglvbo (see GCBO) 107 | % eventdata reserved - to be defined in a future version of MATLAB 108 | % handles structure with handles and user data (see GUIDATA) 109 | 110 | 111 | % -------------------------------------------------------------------- 112 | function edge_Callback(hObject, eventdata, handles) 113 | % hObject handle to edge (see GCBO) 114 | % eventdata reserved - to be defined in a future version of MATLAB 115 | % handles structure with handles and user data (see GUIDATA) 116 | 117 | 118 | % -------------------------------------------------------------------- 119 | function Sobel_Callback(hObject, eventdata, handles) 120 | % hObject handle to Sobel (see GCBO) 121 | % eventdata reserved - to be defined in a future version of MATLAB 122 | % handles structure with handles and user data (see GUIDATA) 123 | global im; 124 | global out; 125 | 126 | rgb = im; 127 | mysize = size(rgb); 128 | if numel(mysize)>2 129 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 130 | else 131 | im1 = rgb; 132 | end 133 | 134 | out = edge(im1,'Sobel',0.06); 135 | axes(handles.axes2); 136 | imshow(out);title('Sobel算子边缘检测'); 137 | 138 | % -------------------------------------------------------------------- 139 | function Canny_Callback(hObject, eventdata, handles) 140 | % hObject handle to Canny (see GCBO) 141 | % eventdata reserved - to be defined in a future version of MATLAB 142 | % handles structure with handles and user data (see GUIDATA) 143 | global im; 144 | global out; 145 | 146 | rgb = im; 147 | mysize = size(rgb); 148 | if numel(mysize)>2 149 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 150 | else 151 | im1 = rgb; 152 | end 153 | 154 | out = edge(im1,'Canny',0.06); 155 | axes(handles.axes2); 156 | imshow(out);title('Canny算子边缘检测'); 157 | 158 | % -------------------------------------------------------------------- 159 | function Log_Callback(hObject, eventdata, handles) 160 | % hObject handle to Log (see GCBO) 161 | % eventdata reserved - to be defined in a future version of MATLAB 162 | % handles structure with handles and user data (see GUIDATA) 163 | global im; 164 | global out; 165 | 166 | rgb = im; 167 | mysize = size(rgb); 168 | if numel(mysize)>2 169 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 170 | else 171 | im1 = rgb; 172 | end 173 | 174 | out = edge(im1,'Log',0.012); 175 | axes(handles.axes2); 176 | imshow(out);title('Log算子边缘检测'); 177 | 178 | % -------------------------------------------------------------------- 179 | function Prewitt_Callback(hObject, eventdata, handles) 180 | % hObject handle to Prewitt (see GCBO) 181 | % eventdata reserved - to be defined in a future version of MATLAB 182 | % handles structure with handles and user data (see GUIDATA) 183 | global im; 184 | global out; 185 | 186 | rgb = im; 187 | mysize = size(rgb); 188 | if numel(mysize)>2 189 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 190 | else 191 | im1 = rgb; 192 | end 193 | 194 | out = edge(im1,'Prewitt',0.06); 195 | axes(handles.axes2); 196 | imshow(out);title('Prewitt算子边缘检测'); 197 | 198 | % -------------------------------------------------------------------- 199 | function Roberts_Callback(hObject, eventdata, handles) 200 | % hObject handle to Roberts (see GCBO) 201 | % eventdata reserved - to be defined in a future version of MATLAB 202 | % handles structure with handles and user data (see GUIDATA) 203 | global im; 204 | global out; 205 | 206 | rgb = im; 207 | mysize = size(rgb); 208 | if numel(mysize)>2 209 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 210 | else 211 | im1 = rgb; 212 | end 213 | 214 | out = edge(im1,'Roberts',0.06); 215 | axes(handles.axes2); 216 | imshow(out);title('Roberts算子边缘检测'); 217 | 218 | 219 | % -------------------------------------------------------------------- 220 | function zhongzhilvbo_Callback(hObject, eventdata, handles) 221 | % hObject handle to zhongzhilvbo (see GCBO) 222 | % eventdata reserved - to be defined in a future version of MATLAB 223 | % handles structure with handles and user data (see GUIDATA) 224 | global im; 225 | global out; 226 | 227 | rgb = im; 228 | mysize = size(rgb); 229 | if numel(mysize)>2 230 | im = rgb2gray(rgb); %将彩色图像转换为灰度图像 231 | else 232 | im = rgb; 233 | end 234 | fn=imnoise(im,'salt & pepper',0.2);%用函数imnosie产生椒盐噪声,0.2代表图中白点黑点出现的概率为0.2 235 | out = medfilt2(fn);%中值滤波 236 | axes(handles.axes2); 237 | imshow(out);title('中值滤波处理后的图像'); 238 | 239 | % -------------------------------------------------------------------- 240 | function batewosi_Callback(hObject, eventdata, handles) 241 | % hObject handle to batewosi (see GCBO) 242 | % eventdata reserved - to be defined in a future version of MATLAB 243 | % handles structure with handles and user data (see GUIDATA) 244 | global im; 245 | global out; 246 | 247 | rgb = im; 248 | mysize = size(rgb); 249 | if numel(mysize)>2 250 | I1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 251 | else 252 | I1 = rgb; 253 | end 254 | m = double(I1); 255 | f = fft2(m); 256 | f = fftshift(f); 257 | [N1,N2] = size(f); 258 | n1 = round(N1/2); 259 | n2 = round(N2/2); 260 | n = 2; 261 | d0 = 10; 262 | for i = 1:N1 263 | for j = 1:N2 264 | d = sqrt((i-n1)^2+(j-n2)^2); 265 | h = (1/(1+(d0/d)^(2*n)))+0.5; 266 | y(i,j) = h*f(i,j); 267 | end 268 | end 269 | y = ifftshift(y); 270 | A = ifft2(y); 271 | out = uint8(real(A)); 272 | axes(handles.axes2); 273 | imshow(out);title('巴特沃斯高通滤波后的图像'); 274 | 275 | % -------------------------------------------------------------------- 276 | function dian_Callback(hObject, eventdata, handles) 277 | % hObject handle to dian (see GCBO) 278 | % eventdata reserved - to be defined in a future version of MATLAB 279 | % handles structure with handles and user data (see GUIDATA) 280 | global im; 281 | global out; 282 | 283 | rgb = im; 284 | mysize = size(rgb); 285 | if numel(mysize)>2 286 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 287 | else 288 | im1 = rgb; 289 | end 290 | 291 | w = [-1 -1 -1;-1 8 -1;-1 -1 -1];%给定模板 292 | out = ordfilt2(im1,5*5,ones(5,5))-ordfilt2(im1,1,ones(5,5));%在这里采用了5*5模板进行差值处理 293 | T2 = max(out(:));%同理 294 | out = out>=T2/2;%同理 295 | axes(handles.axes2); 296 | imshow(out);title('点检测'); 297 | 298 | % -------------------------------------------------------------------- 299 | function xian_Callback(hObject, eventdata, handles) 300 | % hObject handle to xian (see GCBO) 301 | % eventdata reserved - to be defined in a future version of MATLAB 302 | % handles structure with handles and user data (see GUIDATA) 303 | global im; 304 | global out; 305 | 306 | rgb = im; 307 | mysize = size(rgb); 308 | if numel(mysize)>2 309 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 310 | else 311 | im1 = rgb; 312 | end 313 | 314 | w = [2 -1 -1;-1 2 -1;-1 -1 2]; % -45°方向检测线 315 | out = imfilter(double(im1),w); 316 | axes(handles.axes2); 317 | imshow(out);title('线检测'); 318 | 319 | % -------------------------------------------------------------------- 320 | function speckle_Callback(hObject, eventdata, handles) 321 | % hObject handle to speckle (see GCBO) 322 | % eventdata reserved - to be defined in a future version of MATLAB 323 | % handles structure with handles and user data (see GUIDATA) 324 | 325 | % -------------------------------------------------------------------- 326 | function huiduhua_Callback(hObject, eventdata, handles) 327 | % hObject handle to huiduhua (see GCBO) 328 | % eventdata reserved - to be defined in a future version of MATLAB 329 | % handles structure with handles and user data (see GUIDATA) 330 | global im 331 | global BW %定义全局变量 332 | axes(handles.axes2); 333 | BW=rgb2gray(im); 334 | im=BW; 335 | imshow(BW); 336 | 337 | % -------------------------------------------------------------------- 338 | function pinghualvbo_Callback(hObject, eventdata, handles) 339 | % hObject handle to pinghualvbo (see GCBO) 340 | % eventdata reserved - to be defined in a future version of MATLAB 341 | % handles structure with handles and user data (see GUIDATA) 342 | global im; 343 | global out; 344 | 345 | Inoised = imnoise(im,'gaussian',0.1,0.005);%对图像进行高斯噪声加噪 346 | %制定卷积核 347 | h=ones(3,3)/5; 348 | h(1,1) = 0; 349 | h(1,3) = 0; 350 | h(3,1) = 0; 351 | h(1,3) = 0; 352 | %平滑运算 353 | out = imfilter(Inoised,h); 354 | axes(handles.axes2); 355 | imshow(out);title('平滑滤波处理后的图像'); 356 | 357 | % -------------------------------------------------------------------- 358 | function ruihua_Callback(hObject, eventdata, handles) 359 | % hObject handle to ruihua (see GCBO) 360 | % eventdata reserved - to be defined in a future version of MATLAB 361 | % handles structure with handles and user data (see GUIDATA) 362 | global im; 363 | global out; 364 | 365 | rgb = im; 366 | mysize = size(rgb); 367 | if numel(mysize)>2 368 | I1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 369 | else 370 | I1 = rgb; 371 | end 372 | model=[-1,0,1; 373 | -2,0,2; 374 | -1,0,1]; 375 | [m,n]=size(I1); 376 | I2=double(I1); 377 | 378 | for i=2:m-1 379 | for j=2:n-1 380 | I2(i,j)=I1(i+1,j+1)+2*I1(i+1,j)+I1(i+1,j-1)-I1(i-1,j+1)-2*I1(i-1,j)-I1(i-1,j-1); 381 | end 382 | end 383 | I2 = I2 + double(I1); 384 | out = I2; 385 | axes(handles.axes2); 386 | imshow(uint8(out));title('锐化后的图像'); 387 | 388 | % -------------------------------------------------------------------- 389 | function xuanzhuan_Callback(hObject, eventdata, handles) 390 | % hObject handle to xuanzhuan (see GCBO) 391 | % eventdata reserved - to be defined in a future version of MATLAB 392 | % handles structure with handles and user data (see GUIDATA) 393 | global im 394 | global out %定义全局变量 395 | 396 | % A=getimage(handles.axes1); 397 | A = im; 398 | axes(handles.axes2); 399 | prompt = {'度数:'}; 400 | def={'90'}; 401 | answer = inputdlg(prompt,'请输入:',1,def); 402 | if ~isempty(answer) 403 | a = str2num(answer{1}); 404 | J = imrotate(A,360-a); 405 | out = J; 406 | axes(handles.axes2); 407 | imshow(out,[]);title('旋转后图像'); 408 | end 409 | 410 | % -------------------------------------------------------------------- 411 | function DFT_Callback(hObject, eventdata, handles) 412 | % hObject handle to DFT (see GCBO) 413 | % eventdata reserved - to be defined in a future version of MATLAB 414 | % handles structure with handles and user data (see GUIDATA) 415 | global im 416 | global out 417 | 418 | rgb = im; 419 | mysize = size(rgb); 420 | if numel(mysize)>2 421 | im = rgb2gray(rgb); %将彩色图像转换为灰度图像 422 | else 423 | im = rgb; 424 | end 425 | 426 | I1 = im2double(im); 427 | I2 = fft2(I1); 428 | I3 = fftshift(I2); 429 | out = log(abs(I3)+1); 430 | axes(handles.axes2); 431 | imshow(out,[]);title('离散傅里叶变换'); 432 | 433 | % -------------------------------------------------------------------- 434 | function Open_Callback(hObject, eventdata, handles) 435 | % hObject handle to Open (see GCBO) 436 | % eventdata reserved - to be defined in a future version of MATLAB 437 | % handles structure with handles and user data (see GUIDATA) 438 | global im %定义一个全局变量im 439 | global im2 440 | [filename,pathname]=... 441 | uigetfile({'*.*';'*.bmp';'*.tif';'*.png'},'select picture'); %选择图片路径 442 | str=[pathname filename]; %合成路径+文件名 443 | im=imread(str); %读取图片 444 | im2=im; 445 | axes(handles.axes1); %使用第一个axes 446 | imshow(im); %显示图片 447 | 448 | % -------------------------------------------------------------------- 449 | function Save_Callback(hObject, eventdata, handles) 450 | % hObject handle to Save (see GCBO) 451 | % eventdata reserved - to be defined in a future version of MATLAB 452 | % handles structure with handles and user data (see GUIDATA) 453 | global BW 454 | set(handles.axes2,'HandleVisibility','ON'); 455 | axes(handles.axes2); 456 | [filename,pathname]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'save image as'); 457 | file=strcat(pathname,filename); 458 | BW=getimage(gca); 459 | imwrite(BW,file); 460 | set(handles.axes2,'HandleVisibility','Off'); 461 | 462 | % -------------------------------------------------------------------- 463 | function Quit_Callback(hObject, eventdata, handles) 464 | % hObject handle to Quit (see GCBO) 465 | % eventdata reserved - to be defined in a future version of MATLAB 466 | % handles structure with handles and user data (see GUIDATA) 467 | close(gcf) %关闭当前Figure窗口句柄 468 | 469 | 470 | % --- Executes during object creation, after setting all properties. 471 | function axes1_CreateFcn(hObject, eventdata, handles) 472 | % hObject handle to axes1 (see GCBO) 473 | % eventdata reserved - to be defined in a future version of MATLAB 474 | % handles empty - handles not created until after all CreateFcns called 475 | set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色 476 | set(gca,'YColor',get(gca,'Color')); 477 | 478 | set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度 479 | set(gca,'YTickLabel',[]); 480 | % Hint: place code in OpeningFcn to populate axes1 481 | 482 | 483 | % --- Executes during object creation, after setting all properties. 484 | function axes2_CreateFcn(hObject, eventdata, handles) 485 | % hObject handle to axes2 (see GCBO) 486 | % eventdata reserved - to be defined in a future version of MATLAB 487 | % handles empty - handles not created until after all CreateFcns called 488 | set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色 489 | set(gca,'YColor',get(gca,'Color')); 490 | 491 | set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度 492 | set(gca,'YTickLabel',[]); 493 | % Hint: place code in OpeningFcn to populate axes2 494 | -------------------------------------------------------------------------------- /mygui.m: -------------------------------------------------------------------------------- 1 | function varargout = mygui(varargin) 2 | % MYGUI MATLAB code for mygui.fig 3 | % MYGUI, by itself, creates a new MYGUI or raises the existing 4 | % singleton*. 5 | % 6 | % H = MYGUI returns the handle to a new MYGUI or the handle to 7 | % the existing singleton*. 8 | % 9 | % MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in MYGUI.M with the given input arguments. 11 | % 12 | % MYGUI('Property','Value',...) creates a new MYGUI or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before mygui_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to mygui_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 mygui 24 | 25 | % Last Modified by GUIDE v2.5 02-May-2024 21:20:43 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', @mygui_OpeningFcn, ... 32 | 'gui_OutputFcn', @mygui_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 mygui is made visible. 48 | function mygui_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 mygui (see VARARGIN) 54 | 55 | % Choose default command line output for mygui 56 | handles.output = hObject; 57 | 58 | % Update handles structure 59 | guidata(hObject, handles); 60 | 61 | % UIWAIT makes mygui wait for user response (see UIRESUME) 62 | % uiwait(handles.figure1); 63 | 64 | 65 | % --- Outputs from this function are returned to the command line. 66 | function varargout = mygui_OutputFcn(hObject, eventdata, handles) 67 | % varargout cell array for returning output args (see VARARGOUT); 68 | % hObject handle to figure 69 | % eventdata reserved - to be defined in a future version of MATLAB 70 | % handles structure with handles and user data (see GUIDATA) 71 | 72 | % Get default command line output from handles structure 73 | varargout{1} = handles.output; 74 | 75 | 76 | % -------------------------------------------------------------------- 77 | function file_Callback(hObject, eventdata, handles) 78 | % hObject handle to file (see GCBO) 79 | % eventdata reserved - to be defined in a future version of MATLAB 80 | % handles structure with handles and user data (see GUIDATA) 81 | 82 | 83 | % -------------------------------------------------------------------- 84 | function open_Callback(hObject, eventdata, handles) 85 | % hObject handle to open (see GCBO) 86 | % eventdata reserved - to be defined in a future version of MATLAB 87 | % handles structure with handles and user data (see GUIDATA) 88 | global im %定义一个全局变量im 89 | global im2 90 | [filename,pathname]=... 91 | uigetfile({'*.*';'*.bmp';'*.tif';'*.png'},'select picture'); %选择图片路径 92 | str=[pathname filename]; %合成路径+文件名 93 | im=imread(str); %读取图片 94 | im2=im; 95 | axes(handles.axes1); %使用第一个axes 96 | imshow(im); %显示图片 97 | 98 | 99 | % -------------------------------------------------------------------- 100 | function save_Callback(hObject, eventdata, handles) 101 | % hObject handle to save (see GCBO) 102 | % eventdata reserved - to be defined in a future version of MATLAB 103 | % handles structure with handles and user data (see GUIDATA) 104 | global BW 105 | set(handles.axes2,'HandleVisibility','ON'); 106 | axes(handles.axes2); 107 | [filename,pathname]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'save image as'); 108 | file=strcat(pathname,filename); 109 | BW=getimage(gca); 110 | imwrite(BW,file); 111 | set(handles.axes2,'HandleVisibility','Off'); 112 | 113 | % -------------------------------------------------------------------- 114 | function quit_Callback(hObject, eventdata, handles) 115 | % hObject handle to quit (see GCBO) 116 | % eventdata reserved - to be defined in a future version of MATLAB 117 | % handles structure with handles and user data (see GUIDATA) 118 | close(gcf) %关闭当前Figure窗口句柄 119 | 120 | 121 | % -------------------------------------------------------------------- 122 | function transformation_Callback(hObject, eventdata, handles) 123 | % hObject handle to transformation (see GCBO) 124 | % eventdata reserved - to be defined in a future version of MATLAB 125 | % handles structure with handles and user data (see GUIDATA) 126 | 127 | 128 | % -------------------------------------------------------------------- 129 | function enhancement_Callback(hObject, eventdata, handles) 130 | % hObject handle to enhancement (see GCBO) 131 | % eventdata reserved - to be defined in a future version of MATLAB 132 | % handles structure with handles and user data (see GUIDATA) 133 | 134 | 135 | % -------------------------------------------------------------------- 136 | function Denoising_Callback(hObject, eventdata, handles) 137 | % hObject handle to Denoising (see GCBO) 138 | % eventdata reserved - to be defined in a future version of MATLAB 139 | % handles structure with handles and user data (see GUIDATA) 140 | 141 | 142 | % -------------------------------------------------------------------- 143 | function Canny_Callback(hObject, eventdata, handles) 144 | % hObject handle to Canny (see GCBO) 145 | % eventdata reserved - to be defined in a future version of MATLAB 146 | % handles structure with handles and user data (see GUIDATA) 147 | global im; 148 | global out; 149 | 150 | rgb = im; 151 | mysize = size(rgb); 152 | if numel(mysize)>2 153 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 154 | else 155 | im1 = rgb; 156 | end 157 | 158 | out = edge(im1,'Canny',0.06); 159 | axes(handles.axes2); 160 | imshow(out);title('Canny算子边缘检测'); 161 | 162 | % -------------------------------------------------------------------- 163 | function xuanzhuan_Callback(hObject, eventdata, handles) 164 | % hObject handle to xuanzhuan (see GCBO) 165 | % eventdata reserved - to be defined in a future version of MATLAB 166 | % handles structure with handles and user data (see GUIDATA) 167 | global im 168 | global out %定义全局变量 169 | 170 | % A=getimage(handles.axes1); 171 | A = im; 172 | axes(handles.axes2); 173 | prompt = {'度数:'}; 174 | def={'90'}; 175 | answer = inputdlg(prompt,'请输入:',1,def); 176 | if ~isempty(answer) 177 | a = str2num(answer{1}); 178 | J = imrotate(A,360-a); 179 | out = J; 180 | axes(handles.axes2); 181 | imshow(out,[]);title('旋转后图像'); 182 | end 183 | 184 | % -------------------------------------------------------------------- 185 | function DFT_Callback(hObject, eventdata, handles) 186 | % hObject handle to DFT (see GCBO) 187 | % eventdata reserved - to be defined in a future version of MATLAB 188 | % handles structure with handles and user data (see GUIDATA) 189 | global im 190 | global out 191 | 192 | rgb = im; 193 | mysize = size(rgb); 194 | if numel(mysize)>2 195 | im = rgb2gray(rgb); %将彩色图像转换为灰度图像 196 | else 197 | im = rgb; 198 | end 199 | 200 | I1 = im2double(im); 201 | I2 = fft2(I1); 202 | I3 = fftshift(I2); 203 | out = log(abs(I3)+1); 204 | axes(handles.axes2); 205 | imshow(out,[]);title('离散傅里叶变换'); 206 | 207 | 208 | % -------------------------------------------------------------------- 209 | function Untitled_2_Callback(hObject, eventdata, handles) 210 | % hObject handle to Untitled_2 (see GCBO) 211 | % eventdata reserved - to be defined in a future version of MATLAB 212 | % handles structure with handles and user data (see GUIDATA) 213 | 214 | 215 | % -------------------------------------------------------------------- 216 | function Untitled_3_Callback(hObject, eventdata, handles) 217 | % hObject handle to Untitled_3 (see GCBO) 218 | % eventdata reserved - to be defined in a future version of MATLAB 219 | % handles structure with handles and user data (see GUIDATA) 220 | global im 221 | global BW %定义全局变量 222 | axes(handles.axes2); 223 | BW=rgb2gray(im); 224 | im=BW; 225 | imshow(BW); 226 | 227 | % -------------------------------------------------------------------- 228 | function Sobel_Callback(hObject, eventdata, handles) 229 | % hObject handle to Sobel (see GCBO) 230 | % eventdata reserved - to be defined in a future version of MATLAB 231 | % handles structure with handles and user data (see GUIDATA) 232 | global im; 233 | global out; 234 | 235 | rgb = im; 236 | mysize = size(rgb); 237 | if numel(mysize)>2 238 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 239 | else 240 | im1 = rgb; 241 | end 242 | 243 | out = edge(im1,'Sobel',0.06); 244 | axes(handles.axes2); 245 | imshow(out);title('Sobel算子边缘检测'); 246 | 247 | % -------------------------------------------------------------------- 248 | function Log_Callback(hObject, eventdata, handles) 249 | % hObject handle to Log (see GCBO) 250 | % eventdata reserved - to be defined in a future version of MATLAB 251 | % handles structure with handles and user data (see GUIDATA) 252 | global im; 253 | global out; 254 | 255 | rgb = im; 256 | mysize = size(rgb); 257 | if numel(mysize)>2 258 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 259 | else 260 | im1 = rgb; 261 | end 262 | 263 | out = edge(im1,'Log',0.012); 264 | axes(handles.axes2); 265 | imshow(out);title('Log算子边缘检测'); 266 | 267 | % -------------------------------------------------------------------- 268 | function Prewitt_Callback(hObject, eventdata, handles) 269 | % hObject handle to Prewitt (see GCBO) 270 | % eventdata reserved - to be defined in a future version of MATLAB 271 | % handles structure with handles and user data (see GUIDATA) 272 | global im; 273 | global out; 274 | 275 | rgb = im; 276 | mysize = size(rgb); 277 | if numel(mysize)>2 278 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 279 | else 280 | im1 = rgb; 281 | end 282 | 283 | out = edge(im1,'Prewitt',0.06); 284 | axes(handles.axes2); 285 | imshow(out);title('Prewitt算子边缘检测'); 286 | 287 | % -------------------------------------------------------------------- 288 | function Roberts_Callback(hObject, eventdata, handles) 289 | % hObject handle to Roberts (see GCBO) 290 | % eventdata reserved - to be defined in a future version of MATLAB 291 | % handles structure with handles and user data (see GUIDATA) 292 | global im; 293 | global out; 294 | 295 | rgb = im; 296 | mysize = size(rgb); 297 | if numel(mysize)>2 298 | im1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 299 | else 300 | im1 = rgb; 301 | end 302 | 303 | out = edge(im1,'Roberts',0.06); 304 | axes(handles.axes2); 305 | imshow(out);title('Roberts算子边缘检测'); 306 | 307 | 308 | % -------------------------------------------------------------------- 309 | function gaosi_noise_Callback(hObject, eventdata, handles) 310 | % hObject handle to gaosi_noise (see GCBO) 311 | % eventdata reserved - to be defined in a future version of MATLAB 312 | % handles structure with handles and user data (see GUIDATA) 313 | global im 314 | global out %定义全局变量 315 | 316 | I = im2double(im); 317 | J = imnoise(I,'gaussian'); 318 | out = J; 319 | axes(handles.axes2); 320 | imshow(out);title('添加高斯噪声后的图像'); 321 | 322 | % -------------------------------------------------------------------- 323 | function posong_noise_Callback(hObject, eventdata, handles) 324 | % hObject handle to posong_noise (see GCBO) 325 | % eventdata reserved - to be defined in a future version of MATLAB 326 | % handles structure with handles and user data (see GUIDATA) 327 | global im 328 | global out %定义全局变量 329 | 330 | I = im2double(im); 331 | J = imnoise(I,'poisson'); 332 | out = J; 333 | axes(handles.axes2); 334 | imshow(out);title('添加泊松噪声后的图像'); 335 | 336 | % -------------------------------------------------------------------- 337 | function salt_Callback(hObject, eventdata, handles) 338 | % hObject handle to salt (see GCBO) 339 | % eventdata reserved - to be defined in a future version of MATLAB 340 | % handles structure with handles and user data (see GUIDATA) 341 | global im 342 | global out %定义全局变量 343 | 344 | I = im2double(im); 345 | J = imnoise(I,'salt'); 346 | out = J; 347 | axes(handles.axes2); 348 | imshow(out);title('添加盐噪声后的图像'); 349 | 350 | % -------------------------------------------------------------------- 351 | function speckle_Callback(hObject, eventdata, handles) 352 | % hObject handle to speckle (see GCBO) 353 | % eventdata reserved - to be defined in a future version of MATLAB 354 | % handles structure with handles and user data (see GUIDATA) 355 | global im 356 | global out %定义全局变量 357 | 358 | I = im2double(im); 359 | J = imnoise(I,'speckle'); 360 | out = J; 361 | axes(handles.axes2); 362 | imshow(out);title('添加胡椒噪声后的图像'); 363 | 364 | 365 | % -------------------------------------------------------------------- 366 | function Untitled_4_Callback(hObject, eventdata, handles) 367 | % hObject handle to Untitled_4 (see GCBO) 368 | % eventdata reserved - to be defined in a future version of MATLAB 369 | % handles structure with handles and user data (see GUIDATA) 370 | 371 | 372 | % -------------------------------------------------------------------- 373 | function zhongzhilvbo_Callback(hObject, eventdata, handles) 374 | % hObject handle to zhongzhilvbo (see GCBO) 375 | % eventdata reserved - to be defined in a future version of MATLAB 376 | % handles structure with handles and user data (see GUIDATA) 377 | global im; 378 | global out; 379 | 380 | rgb = im; 381 | mysize = size(rgb); 382 | if numel(mysize)>2 383 | im = rgb2gray(rgb); %将彩色图像转换为灰度图像 384 | else 385 | im = rgb; 386 | end 387 | fn=imnoise(im,'salt & pepper',0.2);%用函数imnosie产生椒盐噪声,0.2代表图中白点黑点出现的概率为0.2 388 | out = medfilt2(fn);%中值滤波 389 | axes(handles.axes2); 390 | imshow(out);title('中值滤波处理后的图像'); 391 | 392 | 393 | % -------------------------------------------------------------------- 394 | function batewosi_Callback(hObject, eventdata, handles) 395 | % hObject handle to batewosi (see GCBO) 396 | % eventdata reserved - to be defined in a future version of MATLAB 397 | % handles structure with handles and user data (see GUIDATA) 398 | global im; 399 | global out; 400 | 401 | rgb = im; 402 | mysize = size(rgb); 403 | if numel(mysize)>2 404 | I1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 405 | else 406 | I1 = rgb; 407 | end 408 | m = double(I1); 409 | f = fft2(m); 410 | f = fftshift(f); 411 | [N1,N2] = size(f); 412 | n1 = round(N1/2); 413 | n2 = round(N2/2); 414 | n = 2; 415 | d0 = 10; 416 | for i = 1:N1 417 | for j = 1:N2 418 | d = sqrt((i-n1)^2+(j-n2)^2); 419 | h = (1/(1+(d0/d)^(2*n)))+0.5; 420 | y(i,j) = h*f(i,j); 421 | end 422 | end 423 | y = ifftshift(y); 424 | A = ifft2(y); 425 | out = uint8(real(A)); 426 | axes(handles.axes2); 427 | imshow(out);title('巴特沃斯高通滤波后的图像'); 428 | 429 | 430 | % --- Executes during object creation, after setting all properties. 431 | function axes1_CreateFcn(hObject, eventdata, handles) 432 | % hObject handle to axes1 (see GCBO) 433 | % eventdata reserved - to be defined in a future version of MATLAB 434 | % handles empty - handles not created until after all CreateFcns called 435 | set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色 436 | set(gca,'YColor',get(gca,'Color')); 437 | 438 | set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度 439 | set(gca,'YTickLabel',[]); 440 | % Hint: place code in OpeningFcn to populate axes1 441 | 442 | 443 | % --- Executes during object creation, after setting all properties. 444 | function axes2_CreateFcn(hObject, eventdata, handles) 445 | % hObject handle to axes2 (see GCBO) 446 | % eventdata reserved - to be defined in a future version of MATLAB 447 | % handles empty - handles not created until after all CreateFcns called 448 | set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色 449 | set(gca,'YColor',get(gca,'Color')); 450 | 451 | set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度 452 | set(gca,'YTickLabel',[]); 453 | % Hint: place code in OpeningFcn to populate axes2 454 | 455 | 456 | % -------------------------------------------------------------------- 457 | function Untitled_5_Callback(hObject, eventdata, handles) 458 | % hObject handle to Untitled_5 (see GCBO) 459 | % eventdata reserved - to be defined in a future version of MATLAB 460 | % handles structure with handles and user data (see GUIDATA) 461 | global im; 462 | global out; 463 | 464 | Inoised = imnoise(im,'gaussian',0.1,0.005);%对图像进行高斯噪声加噪 465 | %制定卷积核 466 | h=ones(3,3)/5; 467 | h(1,1) = 0; 468 | h(1,3) = 0; 469 | h(3,1) = 0; 470 | h(1,3) = 0; 471 | %平滑运算 472 | out = imfilter(Inoised,h); 473 | axes(handles.axes2); 474 | imshow(out);title('平滑滤波处理后的图像'); 475 | 476 | 477 | % -------------------------------------------------------------------- 478 | function Untitled_6_Callback(hObject, eventdata, handles) 479 | % hObject handle to Untitled_6 (see GCBO) 480 | % eventdata reserved - to be defined in a future version of MATLAB 481 | % handles structure with handles and user data (see GUIDATA) 482 | global im 483 | global im2 484 | global BW %定义全局变量 485 | BW=im2; 486 | im=im2; 487 | axes(handles.axes2); 488 | imshow(BW); 489 | 490 | 491 | % -------------------------------------------------------------------- 492 | function Untitled_7_Callback(hObject, eventdata, handles) 493 | % hObject handle to Untitled_7 (see GCBO) 494 | % eventdata reserved - to be defined in a future version of MATLAB 495 | % handles structure with handles and user data (see GUIDATA) 496 | global im; 497 | global out; 498 | 499 | rgb = im; 500 | mysize = size(rgb); 501 | if numel(mysize)>2 502 | I1 = rgb2gray(rgb); %将彩色图像转换为灰度图像 503 | else 504 | I1 = rgb; 505 | end 506 | model=[-1,0,1; 507 | -2,0,2; 508 | -1,0,1]; 509 | [m,n]=size(I1); 510 | I2=double(I1); 511 | 512 | for i=2:m-1 513 | for j=2:n-1 514 | I2(i,j)=I1(i+1,j+1)+2*I1(i+1,j)+I1(i+1,j-1)-I1(i-1,j+1)-2*I1(i-1,j)-I1(i-1,j-1); 515 | end 516 | end 517 | I2 = I2 + double(I1); 518 | out = I2; 519 | axes(handles.axes2); 520 | imshow(uint8(out));title('锐化后的图像'); 521 | --------------------------------------------------------------------------------