?? mydip.asv
字號:
function varargout = MyDIP(varargin)
% MYDIP M-file for MyDIP.fig
% MYDIP, by itself, creates a new MYDIP or raises the existing
% singleton*.
%
% H = MYDIP returns the handle to a new MYDIP or the handle to
% the existing singleton*.
%
% MYDIP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYDIP.M with the given input arguments.
%
% MYDIP('Property','Value',...) creates a new MYDIP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MyDIP_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MyDIP_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help MyDIP
% Last Modified by GUIDE v2.5 18-Nov-2006 20:20:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MyDIP_OpeningFcn, ...
'gui_OutputFcn', @MyDIP_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if 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 MyDIP is made visible.
function MyDIP_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% 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 MyDIP (see VARARGIN)
% Choose default command line output for MyDIP
handles.output = hObject;
handles.flag=logical(0);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MyDIP wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MyDIP_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 structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function openfile_Callback(hObject, eventdata, handles)
% hObject handle to openfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%file = uigetfile({'*.bmp';'*.*'},'Image File Selector');
[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.jpeg'},'Pick an image-file');
if isequal(filename,0) | isequal(pathname,0)
disp('User pressed cancel');
else
disp(['User selected ', fullfile(pathname, filename)])
end
x=imread(filename);
[width,height,Cnums]=size(x);
a=log2(width);
b=log2(height);
axes(handles.axes2);
imshow(zeros([256,256]));
if (Cnums~=1)
if (width>256)|(height>256)
W=max(width,height);
else
W=256;
end
for m=1:W
for n=1:W
if (m<=width)&(n<=height)
extendx(m,n,:)=x(m,n,:);
else
extendx(m,n,:)=realmax;
end
end
end
axes(handles.axes1);
Imshow(extendx);
handles.rgb=x;
msgbox('Please transform it to a monochrome image or it can not be processed correctly','fileopening','warning');
elseif (width>256)|(height>256)
W=max(width,height);
for m=1:W
for n=1:W
if (m<=width)&(n<=height)
extendx(m,n)=x(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes1);
Imshow(extendx);
msgbox('The height or width is larger than 256 or they are both larger than 256!','fileopening','warning')
elseif (width<256)|(height<256)
for m=1:256
for n=1:256
if (m<=width)&(n<=height)
extendx(m,n)=x(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes1);
Imshow(extendx);
msgbox('The height or width is less than 256 or they are both less than 256!','fileopening','warning');
else
axes(handles.axes1);
Imshow(x);
end
handles.imdata=x;
handles.reload=handles.imdata;
guidata(hObject, handles);
% --------------------------------------------------------------------
function RGBtoGray_Callback(hObject, eventdata, handles)
% hObject handle to RGBtoGray (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
RGB=handles.rgb;
[M,N,C]=size(RGB);
T = inv([1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703]);
coef = T(1,:)';
for j=1:M
for k=1:N
Gray(j,k)=RGB(j,k,1)*coef(1)+RGB(j,k,2)*coef(2)+RGB(j,k,3)*coef(3);
end
end
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=Gray(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes1);
Imshow(extendx);
handles.imdata=Gray;
guidata(hObject, handles);
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function FFT_Callback(hObject, eventdata, handles)
% hObject handle to FFT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=handles.imdata;
tic;
[M,N]=size(f);
y=fft2(f);
Time=toc;
Result=log(abs(fftshift(y))+1);
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=Result(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[8,12]);
handles.ft=y;
handles.imdata=log(abs(fftshift(y))+1);
guidata(hObject, handles);
% --------------------------------------------------------------------
function IFFT_Callback(hObject, eventdata, handles)
% hObject handle to IFFT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=handles.ft;
tic;
[M,N]=size(f);
y=ifft2(f);
Time=toc;
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=abs(y(m,n));
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[min(min(abs(y))),max(max(abs(y)))]);
handles.imdata=abs(y);
guidata(hObject, handles);
% --------------------------------------------------------------------
function Centered_Callback(hObject, eventdata, handles)
% hObject handle to Centered (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic;
d=handles.imdata;
f1=double(d);
[M,N]=size(d);
y=1:N;
for v=1:N
g1(y,v)=exp(-j*2*pi*v*y/N);
end
g=f1*g1;
x=1:M;
for u=1:M
g3(x,u)=exp(-j*2*pi*u*x/M);
end
g2=g3*g;
F=g2;
handles.dft=F;
handles.ft=F;
F=fftshift(F);
Time=toc;
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=log(abs(F(m,n)));
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[8,12]);
handles.imdata=log(abs(F));
guidata(hObject,handles);
% --------------------------------------------------------------------
function UnCentered_Callback(hObject, eventdata, handles)
% hObject handle to UnCentered (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d=handles.imdata;
f1=double(d);
[M,N]=size(d);
tic;
y=1:N;
for v=1:N
g1(y,v)=exp(-j*2*pi*v*y/N);
end
g=f1*g1;
x=1:M;
for u=1:M
g3(x,u)=exp(-j*2*pi*u*x/M);
end
g2=g3*g;
F=g2;
Time=toc;
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=log(abs(F(m,n)));
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[8,12]);
handles.dft=F;
handles.ft=F;
handles.imdata=log(abs(F));
guidata(hObject,handles);
% --------------------------------------------------------------------
function IDFT_Callback(hObject, eventdata, handles)
% hObject handle to IDFT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic;
f=handles.dft;
f1=double(f);
[M,N]=size(f);
tic;
y=1:N;
for v=1:N
g1(y,v)=exp(j*2*pi*v*y/N);
end
x=1:M;
for u=1:M
g3(x,u)=exp(j*2*pi*u*x/M);
end
g2=g3*f1*g1;
F=abs(g2);
Time=toc;
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=F(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2);
imshow(extendx,[min(min(F)),max(max(F))]);
handles.imdata=F;
guidata(hObject, handles);
% -------------------------------------------------------------------
function DST_Callback(hObject, eventdata, handles)
% hObject handle to DST (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic;
f=handles.imdata;
f1=double(f);
[M,N]=size(f);
v=[1:N];
for y=[1:N]
g1(y,v)=sin(pi*v*y/(N+1));
end
u=[1:M];
for x=[1:M]
g2(x,u)=sin(pi*u*x/(M+1));
end
F1=g2*f1*g1;
F=sqrt(2/(M+1))*sqrt(2/(N+1))*F1;
Time=toc;
set(handles.edit1,'string',Time);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=log(abs(F(m,n)));
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2),imshow(extendx,[3,6]);
handles.dstdata=F;
handles.imdata=log(abs(F));
guidata(hObject, handles);
% --------------------------------------------------------------------
function IDST_Callback(hObject, eventdata, handles)
% hObject handle to IDST (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic;
f=handles.dstdata;
f1=double(f);
[M,N]=size(f);
y=[1:N];
for v=[1:N]
g1(v,y)=sin(pi*v*y/(N+1));
end
y=[1:M];
for v=[1:M]
g2(v,y)=sin(pi*v*y/(M+1));
end
F1=g2*f1*g1;
F=sqrt(2/(M+1))*sqrt(2/(N+1))*F1;
Time=toc;
set(handles.edit1,'string',Time);
F=uint8(F);
extendx=double(zeros(256));
if (M<=256)&(N<=256)
W=256;
else
W=max(M,N);
end
for m=1:W
for n=1:W
if (m<=M)&(n<=N)
extendx(m,n)=F(m,n);
else
extendx(m,n)=realmax;
end
end
end
axes(handles.axes2),imshow(extendx,[min(min(F)),max(max(F))]);
handles.imdata=F;
guidata(hObject, handles);
% --------------------------------------------------------------------
function DHT_Callback(hObject, eventdata, handles)
% hObject handle to DHT (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 + -