📄 matlab.m
字号:
function varargout = matlab(varargin)% MATLAB M-file for matlab.fig% MATLAB, by itself, creates a new MATLAB or raises the existing% singleton*.%% H = MATLAB returns the handle to a new MATLAB or the handle to% the existing singleton*.%% MATLAB('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in MATLAB.M with the given input arguments.%% MATLAB('Property','Value',...) creates a new MATLAB or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before matlab_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to matlab_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help matlab% Last Modified by GUIDE v2.5 13-Jan-2009 00:40:56% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @matlab_OpeningFcn, ... 'gui_OutputFcn', @matlab_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before matlab is made visible.function matlab_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to matlab (see VARARGIN)% Choose default command line output for matlabhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes matlab wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = matlab_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes on button press in pushbutton1.% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);%b=rgb2gray(f);k=imfinfo(temp);height=k.Height;width=k.Width;c=1;gamma=10;for i = 1:height for j = 1:width powerlaw(i,j)=c*(f(i,j).^gamma); endend figure,imshow(f),figure,imshow(powerlaw);% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);%f = rgb2gray(f);k=imfinfo(temp);height=k.Height;width=k.Width;gray_slice =f;for i = 1:height for j = 1:width if(f(i,j)<256 && f(i,j)>50) gray_slice(i,j)=255; else gray_slice(i,j)=0; end endendfigure,imshow(f),figure,imshow(gray_slice)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);k=imfinfo(temp);height=k.Height;width=k.Width;pic = im2double(f);c=1;for i = 1:height for j = 1:width logtransform(i,j)=c*log(1+pic(i,j)); endendfigure,imshow(f),figure,imshow(logtransform);% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f); w4=fspecial('average');g4=imfilter(d,w4,'replicate');figure,imshow(f),figure,imshow(g4);% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f); w4=fspecial('average');g4=imfilter(d,w4,'replicate');figure,imshow(f),figure,imshow(g4);% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton7.% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);f=im2double(f);g=fspecial('laplacian',0);g2=f-imfilter(f,g,'replicate');figure,imshow(f),figure,imshow(g2);% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f);fn=imnoise(d,'salt & pepper',0.2);gm=medfilt2(fn,'symmetric');figure,imshow(f),figure,imshow(gm);% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f); g4=ordfilt2(d,1,ones(3,3));figure,imshow(f),figure,imshow(g4);% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f); w4=fspecial('unsharp',0);g4=imfilter(d,w4,'replicate');figure,imshow(f),figure,imshow(g4);% hObject handle to pushbutton11 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton12.function pushbutton12_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);d=im2double(f); w4=fspecial('sobel');g4=imfilter(d,w4,'replicate');figure,imshow(f),figure,imshow(g4);% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=5;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); H=double(D<=P); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g); % hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=5;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); n=2;H=1./(1+(D./P).^(2*n)); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g); % hObject handle to pushbutton14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=5;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); H=exp(-(D.^2)./(2*(P^2))); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g); % hObject handle to pushbutton15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=15;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); H=double(D>=P); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g);% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=80;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); n=2;H=1./(1+(P./D).^(2*n)); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g);% hObject handle to pushbutton17 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)[FileName,PathName] = uigetfile('*.jpg','Select an JPEG image');file= [PathName,FileName];img=imread(file);f=img; P=15;[M,N,O]=size(f); F=fft2(double(f)); u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.^2+V.^2); H=1.-(exp(-(D.^2)./(2*(P^2)))); G=F; for i = 1:O G(:,:,i) = H.*F(:,:,i); end g=uint8(real(ifft2(double(G)))); figure,imshow(f),figure,imshow(g);% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)[FileName,PathName]=uigetfile('*.jpg,''Select image:');temp=[PathName,FileName];f=imread(temp);%f = rgb2gray(f);k=imfinfo(temp);d=k.Height;e=k.Width;max_gray = max(max(f));max_gray = im2double(max_gray);pic = im2double(f);pic_negative=pic;for i = 1:d for j = 1:e pic_negative(i,j)= max_gray - pic(i,j); endendfigure,imshow(f),figure,imshow(pic_negative); % hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -