www.gusucode.com > MATLAB算法演示图像方面程序源码 > MATLAB算法演示图像方面程序源码/MyDIP.m
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. % 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 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 gray 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) tic; f=handles.imdata; [Ms,Ns]=size(f); a=fix(log2(Ms)); b=fix(log2(Ns)); r=max(a,b); W=2^r; for m=1:W for n=1:W if m<Ms&n<Ns f1(m,n)=double(f(m,n)); else f1(m,n)=255; end end end j=1:W; for i=r:-1:1; y(:,i)=rem(j,2); j=fix(j/2); end v=y'; g1=y*v; g=(-1).^(rem(g1,2)); F=g*f1*g/(W*W); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (W<=256) Wh=256; else Wh=W; end for m=1:Wh for n=1:Wh if (m<=W)&(n<=W) extendx(m,n)=F(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx); handles.dhtdata=F;handles.gh=g; handles.imdata=F; guidata(hObject, handles); % -------------------------------------------------------------------- function IDHT_Callback(hObject, eventdata, handles) % hObject handle to IDHT (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.dhtdata; [M,N]=size(f); f1=double(f); g=handles.gh; F=g*f1*g; Time=toc; extendx=double(zeros(256)); if (M<=256) Wh=256; else Wh=M; end for m=1:Wh for n=1:Wh 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))]); set(handles.edit1,'string',Time); handles.imdata=F; guidata(hObject, handles); % --------------------------------------------------------------- function DWashT_Callback(hObject, eventdata, handles) % hObject handle to DWashT (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; [Ms,Ns]=size(f); a=fix(log2(Ms)); b=fix(log2(Ns)); r=max(a,b); W=2^r; for m=1:W for n=1:W if m<Ms&n<Ns f1(m,n)=double(f(m,n)); else f1(m,n)=255; end end end j=1:W; for i=a:-1:1; y(:,i)=rem(j,2); j=fix(j/2); end v=(fliplr(y))'; g1=y*v; g=(-1).^(rem(g1,2)); F=g*f1*g/(W*W); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (W<=256) Wh=256; else Wh=W; end for m=1:Wh for n=1:Wh if (m<=W)&(n<=W) extendx(m,n)=F(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx); handles.dwtdata=F;handles.gw=g; handles.imdata=F; guidata(hObject, handles); % -------------------------------------------------------------------- function IDWashT_Callback(hObject, eventdata, handles) % hObject handle to IDWashT (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) f=handles.dwtdata; tic; [M,N]=size(f); f1=double(f); g=handles.gw; F=g*f1*g; Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (M<=256) Wh=256; else Wh=M; end for m=1:Wh for n=1:Wh 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 DCT_Callback(hObject, eventdata, handles) % hObject handle to DCT (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)=cos((2*y-1)*(v-1)*pi/(2*N)); end v=[1:M]; for y=[1:M] g2(y,v)=cos((2*y-1)*(v-1)*pi/(2*M)); end F1=sqrt(2/N)*f1*g1; F2=sqrt(2/M)*g2*F1; F3=F2; F3(1,:)=sqrt(1/N)*F2(1,:)/(sqrt(2/N)); F=F3; F(:,1)=sqrt(1/M)*F3(:,1)/(sqrt(2/M)); 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.dctdata=F; handles.imdata=log(abs(F)); guidata(hObject, handles); % -------------------------------------------------------------------- function IDCT_Callback(hObject, eventdata, handles) % hObject handle to IDCT (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) f=handles.dctdata; tic; f1=double(f); [M,N]=size(f); y=[1:N]; for v=[1:N] g1(v,y)=cos((2*y-1)*(v-1)*pi/(2*N)); end y=[1:M]; for v=[1:M] g2(v,y)=cos((2*y-1)*(v-1)*pi/(2*M)); end F1=sqrt(2/N)*f1*g1; F2=sqrt(2/M)*g2*F1; F3=F2; F3(1,:)=sqrt(1/N)*F2(1,:)/(sqrt(2/N)); F=F3; F(:,1)=sqrt(1/M)*F3(:,1)/(sqrt(2/M)); 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 AddNoise_Callback(hObject, eventdata, handles) % hObject handle to AddNoise (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; [M,N]=size(f); f1=imnoise(f,'salt & pepper',0.04); 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)=f1(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f1)),max(max(f1))]); handles.imdata=f1; guidata(hObject, handles); % -------------------------------------------------------------------- function GuassianNoise_Callback(hObject, eventdata, handles) % hObject handle to GuassianNoise (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; [M,N]=size(f); f1=imnoise(f,'gaussian',0.04); 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)=f1(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f1)),max(max(f1))]); handles.imdata=f1; guidata(hObject, handles); % -------------------------------------------------------------------- function Averaging_Callback(hObject, eventdata, handles) % hObject handle to Averaging (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; f2=double(f); [M,N]=size(f); f3=zeros([M,N]); for x=2:(M-1); for y=2:(N-1); f3(x,y)=(f2(x-1,y-1)+f2(x,y-1)+f2(x+1,y-1)+f2(x-1,y)+f2(x,y)+f2(x+1,y)+f2(x-1,y+1)+f2(x,y+1)+f2(x+1,y+1))/9; end end 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)=f3(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f3)),max(max(f3))]); handles.imdata=f3; guidata(hObject, handles); % -------------------------------------------------------------------- function NeibAveraging_Callback(hObject, eventdata, handles) % hObject handle to NeibAveraging (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; f2=double(f); [row,col]=size(f); f3=zeros([row,col]); for x=2:(row-1); for y=2:(col-1); f3(x,y)=(f2(x-1,y-1)+f2(x,y-1)+f2(x+1,y-1)+f2(x-1,y)+f2(x+1,y)+f2(x-1,y+1)+f2(x,y+1)+f2(x+1,y+1))/8; end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f3(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f3)),max(max(f3))]); handles.imdata=f3; guidata(hObject, handles); % -------------------------------------------------------------------- function MedianFilter_Callback(hObject, eventdata, handles) % hObject handle to MedianFilter (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; f2=double(f); [row,col]=size(f); f3=zeros([row,col]); for x=2:(row-1); for y=2:(col-1); f3(x,y)=median([f2(x-1,y-1),f2(x,y-1),f2(x+1,y-1),f2(x-1,y),f2(x,y),f2(x+1,y),f2(x-1,y+1),f2(x,y+1),f2(x+1,y+1)]); end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f3(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f3)),max(max(f3))]); handles.imdata=f3; guidata(hObject, handles); % -------------------------------------------------------------------- function LowBWS_Callback(hObject, eventdata, handles) % hObject handle to LowBWS (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; f2=double(f); [row,col]=size(f); g=fft2(f2); g=fftshift(g); nn=256; d0=40; nx=fix(row/2); ny=fix(col/2); for i=1:row for j=1:col d=sqrt((i-nx)^2+(j-ny)^2); h=1/(1+0.414*(d/d0)^(2*nn)); result(i,j)=h*g(i,j); end end result=ifftshift(result); f3=ifft2(result); f4=abs(f3); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f4(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f4)),max(max(f4))]); handles.imdata=f4; guidata(hObject, handles); % -------------------------------------------------------------------- function Robert_Callback(hObject, eventdata, handles) % hObject handle to Robert (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); [row,col]=size(f); f2=zeros([row,col]); for x=2:(row-1); for y=2:(col-1); f2(x,y)=sqrt((abs(f1(x,y)-f1(x+1,y+1)))^2+(abs(f1(x+1,y)-f1(x,y+1)))^2); end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f2(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(2)),max(max(f2))]); handles.imdata=f2; guidata(hObject, handles); % -------------------------------------------------------------------- function Sobel_Callback(hObject, eventdata, handles) % hObject handle to Sobel (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); [row,col]=size(f); f2=zeros([row,col]); for x=2:(row-1); for y=2:(col-1); c=2; s1=(f1(x-1,y+1)+c*f1(x,y-1)+f1(x+1,y+1))-(f1(x-1,y-1)+c*f1(x,y-1)+f1(x+1,y-1)); s2=(f1(x-1,y-1)+c*f1(x-1,y)+f1(x-1,y+1))-(f1(x+1,y+1)+c*f1(x+1,y)+f1(x+1,y-1)); f2(x,y)=sqrt(s1*s1+s2*s2); end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f2(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(f2)),max(max(f2))]); handles.imdata=f2; guidata(hObject, handles); % -------------------------------------------------------------------- function Laplacian_Callback(hObject, eventdata, handles) % hObject handle to Laplacian (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); [row,col]=size(f); f2=zeros([row,col]); for x=2:(row-1) for y=2:(col-1) f2(x,y)=f1(x-1,y)+f1(x+1,y)+f1(x,y-1)+f1(x,y+1)-4*f1(x,y); end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f2(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[0,255]); handles.imdata=f2; guidata(hObject, handles); % -------------------------------------------------------------------- function Canny_Callback(hObject, eventdata, handles) % hObject handle to Canny (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=edge(f,'canny',0.2); [row,col]=size(f1); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f1(m,n); else extendx(m,n)=1; end end end axes(handles.axes2),imshow(extendx); handles.imdata=f1; guidata(hObject, handles); % -------------------------------------------------------------------- function HighBWS_Callback(hObject, eventdata, handles) % hObject handle to HighBWS (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; f2=double(f); [row,col]=size(f); g=fft2(f2); g=fftshift(g); nn=256; d0=40; nx=fix(row/2); ny=fix(col/2); for i=1:row for j=1:col d=sqrt((i-nx)^2+(j-ny)^2); h=1/(1+0.414*(d0/d)^(2*nn)); result(i,j)=h*g(i,j); end end result=ifftshift(result); f3=ifft2(result); f4=f2-abs(f3); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f4(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[0,255]); handles.imdata=f4; guidata(hObject, handles); % -------------------------------------------------------------------- function ColorGrayCut_Callback(hObject, eventdata, handles) % hObject handle to ColorGrayCut (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; [row,col]=size(f); f2=double(f); f3=zeros(row,col,3); for x=1:row; for y=1:col; if f2(x,y)>160 f3(x,y,1)=f2(x,y)+1; f3(x,y,2)=0; f3(x,y,3)=0; else if f2(x,y)>80 f3(x,y,2)=f2(x,y)+1; f3(x,y,1)=0; f3(x,y,3)=0; else f3(x,y,3)=f2(x,y)+1; f3(x,y,1)=0; f3(x,y,2)=0; end end end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W,3])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n,:)=f3(m,n,:); else extendx(m,n,:)=realmax; end end end axes(handles.axes2),imshow(extendx); handles.imdata=f3; guidata(hObject, handles); % -------------------------------------------------------------------- function ColorSynthesize_Callback(hObject, eventdata, handles) % hObject handle to ColorSynthesize (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; [row,col]=size(f); f2=double(f); f3=zeros(row,col,3); for x=1:row; for y=1:col; f3(x,y,1)=255*sin(2*pi*f2(x,y)/255); f3(x,y,2)=255*sin(2*pi*f2(x,y)/255+pi/4); f3(x,y,3)=255*sin(2*pi*f2(x,y)/255+pi/2); end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W,3])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n,:)=f3(m,n,:); else extendx(m,n,:)=realmax; end end end axes(handles.axes2),imshow(extendx,[]); handles.imdata=f3; guidata(hObject, handles); % -------------------------------------------------------------------- function Inverse_Callback(hObject, eventdata, handles) % hObject handle to Inverse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; y=255-x; [row,col]=size(x); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function HisteQ_Callback(hObject, eventdata, handles) % hObject handle to HisteQ (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; N=256; [row,col]=size(x); p=zeros(N); for i=1:row*col; p(x(i)+1)=p(x(i)+1)+1; end p=(double(p))/(row*col); for k=2:N p(k)= p(k) + p(k-1) ; end s=fix(256*p); for i=1:row*col; x(i)=s(x(i)+1)-1; end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(x)),max(max(x))]); handles.imdata=x; guidata(hObject, handles); % -------------------------------------------------------------------- function AllGrayT_Callback(hObject, eventdata, handles) % hObject handle to AllGrayT (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; [row,col]=size(f); f1=double(f); prompt={'the min graylevel for output image(0~255):' 'the max graylevel for output image(0~255):'}; name='Input for ContrastStretching'; numlines=1; defaultanswer={'0' '255'}; anss=inputdlg(prompt,name,numlines,defaultanswer); b=str2num(anss{1}); a=str2num(anss{2}); fminGray=min(min(f1)); fmaxGray=max(max(f1)); g=double(zeros([row,col])); for x=1:row for y=1:col g(x,y)=[(a-b)*(f1(x,y)-fminGray)/(fmaxGray-fminGray)]+b; end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[0,255]); handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function ContrastStretching_Callback(hObject, eventdata, handles) % hObject handle to ContrastStretching (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; [row,col]=size(f); f1=double(f); N=256; prompt={'the x of the first point:' 'the y of the first point:' 'the x of the second point:' 'the y of the second point:' 'the maximum graylevel for output image:'}; name='Input for ContrastStretching'; numlines=1; defaultanswer={'80' '70' '170' '180' '255'}; anss=inputdlg(prompt,name,numlines,defaultanswer); x1=str2num(anss{1}); y1=str2num(anss{2}); x2=str2num(anss{3}); y2=str2num(anss{4}); gmaxGray=str2num(anss{5}); fmaxGray=max(max(f1)); for x=1:row for y=1:col if f1(x,y)<=x1 g(x,y)=x2*f1(x,y)/x1; else if (f1(x,y)>x1)&(f1(x,y)<=x2) g(x,y)=(y2-y1)*(f1(x,y)-x1)/(x2-x1)+y1; else g(x,y)=(gmaxGray-y2)*(f1(x,y)-x2)/(fmaxGray-x2); end end end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(g)),max(max(g))]); handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function Thresholding_Callback(hObject, eventdata, handles) % hObject handle to Thresholding (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; prompt={'Threshold(0~255):'}; name='Input for Thresholding'; numlines=1; defaultanswer={'50'}; anss=inputdlg(prompt,name,numlines,defaultanswer); th=str2num(anss{1}); [row,col]=size(x); for i=1:row*col; if x(i)>th x(i)=256; else x(i)=0; end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[]); handles.imdata=x; guidata(hObject, handles); % -------------------------------------------------------------------- function LogT_Callback(hObject, eventdata, handles) % hObject handle to LogT (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; [row,col]=size(f); mode.WindowStyle='modal'; mode.Interpreter='tex'; msgbox('g(x,y)=a+(ln[f(x,y)+1])/(b*ln(c))','the formul','mode'); prompt={'parameter a:' 'parameter b:' 'parameter c:'}; name='Input for LOG tranformation'; numlines=1; defaultanswer={'0' '1' '10'}; anss=inputdlg(prompt,name,numlines,defaultanswer); a=str2num(anss{1}); b=str2num(anss{2}); c=str2num(anss{3}); f1=double(f); N=256; g=a*ones([row,col])+log(f1+ones([row,col]))/(b*log(c)); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(g)),max(max(g))]); handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function ExpT_Callback(hObject, eventdata, handles) % hObject handle to ExpT (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); [row,col]=size(f); mode.WindowStyle='modal'; mode.Interpreter='tex'; msgbox('g(x,y)=b^(c*[f(x,y)-a])','the formula','mode'); prompt={'parameter a:' 'parametr b:' 'parameter c:'}; name='Input for Exp tranformation'; numlines=1; defaultanswer={'0' '2' '0.04'}; anss=inputdlg(prompt,name,numlines,defaultanswer); a=str2num(anss{1}); b=str2num(anss{2}); c=str2num(anss{3}); N=256; g=b.^(c*(f1-a*ones([row,col])))-1; Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2),imshow(extendx,[min(min(g)),max(max(g))]); handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function Untitled_28_Callback(hObject, eventdata, handles) % hObject handle to Untitled_28 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_27_Callback(hObject, eventdata, handles) % hObject handle to Untitled_27 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_26_Callback(hObject, eventdata, handles) % hObject handle to Untitled_26 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_29_Callback(hObject, eventdata, handles) % hObject handle to Untitled_29 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_30_Callback(hObject, eventdata, handles) % hObject handle to Untitled_30 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_31_Callback(hObject, eventdata, handles) % hObject handle to Untitled_31 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_32_Callback(hObject, eventdata, handles) % hObject handle to Untitled_32 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_33_Callback(hObject, eventdata, handles) % hObject handle to Untitled_33 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_34_Callback(hObject, eventdata, handles) % hObject handle to Untitled_34 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_35_Callback(hObject, eventdata, handles) % hObject handle to Untitled_35 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_36_Callback(hObject, eventdata, handles) % hObject handle to Untitled_36 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_37_Callback(hObject, eventdata, handles) % hObject handle to Untitled_37 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_38_Callback(hObject, eventdata, handles) % hObject handle to Untitled_38 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % st2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % -------------------------------------------------------------------- function MovingNoise_Callback(hObject, eventdata, handles) % hObject handle to MovingNoise (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); handles.source=x; f=double(x); prompt={'Distance:' 'Angle(-180~180):'}; name='Input for movement blurring'; numlines=1; defaultanswer={'30' '45'}; anss=inputdlg(prompt,name,numlines,defaultanswer); len=str2num(anss{1}); angle=str2num(anss{2}); mPSF=fspecial('motion',len,angle); y=imfilter(f,mPSF,'circular','conv'); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.P=mPSF; handles.blurred=y; handles.inverseblurred=y; handles.flag=logical(0); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function MovingPlusnoise_Callback(hObject, eventdata, handles) % hObject handle to MovingPlusRandomnoise (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); f=x; prompt={'Distance:' 'Angle(-180~180):'}; name='Input for movement blurring with noise'; numlines=1; defaultanswer={'30' '45'}; anss=inputdlg(prompt,name,numlines,defaultanswer); len=str2num(anss{1}); angle=str2num(anss{2}); mPSF=fspecial('motion',len,angle); y=imfilter(f,mPSF,'circular','conv'); noise=imnoise(zeros(size(y)),'gaussian',0,0.1); noiseadded=imadd(y,im2uint8(noise)); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=noiseadded(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.P=mPSF; handles.noi=noise; handles.blurred=noiseadded; handles.inverseblurred=y; handles.flag=logical(1); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function InverseFilter_Callback(hObject, eventdata, handles) % hObject handle to InverseFilter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handls nduee) tic; g=handles.blurred; [row,col]=size(g); PSF=handles.P; y=deconvwnr(g,PSF); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % ------------------------------------------------------------------- function WinnerFilter_Callback(hObject, eventdata, handles) % hObject handle to WinnerFilter (see GCBO) % eventdata reerved - to be defined in a future version of MALAB % handles structure with handles and user data (see GUIDATA) tic; blurred=handles.inverseblurred; g=handles.blurred; [row,col]=size(g); f=handles.source; PSF=handles.P; if handles.flag==logical(0) y=deconvwnr(g,PSF); else noise=handles.noi; NP=abs(fft2(noise)).^2; ncorr=fftshift(real(ifft2(NP))); IP=abs(fft2(im2double(blurred))).^2; icorr=fftshift(real(ifft2(IP))); y=deconvwnr(g,PSF,ncorr,icorr); handes.flag=logical(0); end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function Untitled_40_Callback(hObject, eventdata, handles) % hObject handle to Untitled_40 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_45_Callback(hObject, eventdata, handles) % hObject handle to Untitled_45 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_43_Callback(hObject, eventdata, handles) % hObject handle to Untitled_43 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_42_Callback(hObject, eventdata, handles) % hObject handle to Untitled_42 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_46_Callback(hObject, eventdata, handles) % hObject handle to Untitled_46 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_47_Callback(hObject, eventdata, handles) % hObject handle to Untitled_47 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_48_Callback(hObject, eventdata, handles) % hObject handle to Untitled_48 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_44_Callback(hObject, eventdata, handles) % hObject handle to Untitled_44 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Gradient_Callback(hObject, eventdata, handles) % hObject handle to Gradient (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; [row,col]=size(f); prompt={'Threshold(0~255):'}; name='Input for Gradient Sharping'; numlines=1; defaultanswer={'10'}; anss=inputdlg(prompt,name,numlines,defaultanswer); th=str2num(anss{1}); f1=double(f); f2=zeros(row,col); for x=2:(row-1) for y=2:(col-1) g=abs(f1(x,y)-f1(x+1,y))+abs(f1(x,y)-f1(x,y+1)); if g>=th f2(x,y)=g; else f2(x,y)=f1(x,y); end end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f2(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(f2)),max(max(f2))]); handles.imdata=f2; guidata(hObject, handles); % -------------------------------------------------------------------- function Prewitt_Callback(hObject, eventdata, handles) % hObject handle to Prewitt (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; [row,col]=size(f); f1=edge(f,'prewitt'); Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f1(m,n); else extendx(m,n)=1; end end end axes(handles.axes2),imshow(extendx); handles.imdata=f1; guidata(hObject, handles); % -------------------------------------------------------------------- function GrayThreshold_Callback(hObject, eventdata, handles) % hObject andle to GrayThreshold (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; N=256; [row,col]=size(x); th=0; p=zeros(N); for i=1:row*col p(fix(x(i)+1))=p(fix(x(i)+1))+1; end p1=zeros(N); p1(1)=p(1); for i=2:N p1(i)=p(i)-p(i-1); end p2=zeros(N); p2(1)=p1(1); for i=2:N p2(i)=p1(i)-p1(i-1); end for i=1:N if p2(i)>=0 th=p2(i); end end for i=1:row*col; if x(i)>th x(i)=256; else x(i)=0; end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros(W)); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[0,255]); msgbox('If the result is not satisfying,there maybe more than two peak values in the Histogram? ','Help','help'); handles.imdata=x; guidata(hObject, handles); % -------------------------------------------------------------------- function Untitled_51_Callback(hObject, eventdata, handles) % hObject handle to Untitled_51 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_49_Callback(hObject, eventdata, handles) % hObject handle to Untitled_49 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function ImageMove_Callback(hObject, eventdata, handles) % hObject handle to ImageMove (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); prompt={'pixels of horizontal displacement:' 'pixels of vertical displacement:'}; name='Input for Geometric Transformation'; numlines=1; defaultanswer={'50' '50'}; anss=inputdlg(prompt,name,numlines,defaultanswer); x0=str2num(anss{1}); y0=str2num(anss{2}); T=[1 0 0;0 1 0;x0 y0 1]; tform=maketform('affine',T); g=imtransform(x,tform,'XData',[1 col],'YData',[1 row],'FillValue',0.5); Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(g)),max(max(g))]); handles.imdata=g; guidata(hObject, handles); % -------------------------------------------- function HorizontalTransform_Callback(hObject, eventdata, handles) % hObject handle to HorizontalTransform (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); for i=1:row for j=1:col y(i,j)=x(i,col-j+1); end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function ImageTranspose_Callback(hObject, eventdata, handles) % hObject handle to ImageTranspose (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); for i=1:col for j=1:row y(i,j)=x(j,i); end end Time=toc; set(handles.edit1,'string',Time); if (row<=256)&(row<=256) W=256; else W=max(row,col); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=col)&(n<=row) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function ImageZoom_Callback(hObject, eventdata, handles) % hObject handle to ImageZoom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [row,col]=size(x); prompt={'zoom proportion for horizon(positive fraction or integer):' 'zoom proportion for vertical(positive fraction or integer):'}; name='Input for Geometric Transformation'; numlines=1; defaultanswer={'0.5' '0.5'}; anss=inputdlg(prompt,name,numlines,defaultanswer); Xratio=str2num(anss{1}); Yratio=str2num(anss{2}); T=[Xratio 0 0;0 Yratio 0;0 0 1]; tform=maketform('affine',T); g=imtransform(x,tform); Time=toc; set(handles.edit1,'string',Time); [row,col]=size(g); if (row<=256)&(col<=256) for m=1:256 for n=1:256 if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[]); else M=max(row,col); for m=1:M for n=1:M if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[]); msgbox('The output image has a width or height larger than 256!','HELP','help'); end handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function ImageRotate_Callback(hObject, eventdata, handles) % hObject handle to ImageRotate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; prompt={'Angle(-360~360):'}; name='Input for Geometric Transformation'; numlines=1; defaultanswer={'45'}; anss=inputdlg(prompt,name,numlines,defaultanswer); theta=str2num(anss{1}); T=[cos(theta) sin(theta) 0;-sin(theta) cos(theta) 0;0 0 1]; tform=maketform('affine',T); g=imtransform(x,tform); Time=toc; set(handles.edit1,'string',Time); [row,col]=size(g); if (row<=256)&(col<=256) for m=1:256 for n=1:256 if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[]); else M=max(row,col); for m=1:M for n=1:M if (m<=row)&(n<=col) extendx(m,n)=g(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[]); msgbox('The output image has a width or height larger than 256!','HELP','help'); end handles.imdata=g; guidata(hObject, handles); % -------------------------------------------------------------------- function VerticalTransform_Callback(hObject, eventdata, handles) % hObject handle to VerticalTransform (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [M,N]=size(x); for i=1:M for j=1:N y(i,j)=x(M-i+1,j); end end Time=toc; set(handles.edit1,'string',Time); if (M<=256)&(N<=256) W=256; else W=max(M,N); end extendx=double(zeros([W,W])); for m=1:W for n=1:W if (m<=M)&(n<=N) extendx(m,n)=y(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[min(min(y)),max(max(y))]); handles.imdata=y; guidata(hObject, handles); % -------------------------------------------------------------------- function CloseFile_Callback(hObject, eventdata, handles) % hObject handle to CloseFile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) x=zeros(256); axes(handles.axes1); imshow(x); axes(handles.axes2); imshow(x); set(handles.edit1,'string',0.0); handles.imdata=zeros(256); guidata(hObject, handles); % -------------------------------------------------------------------- function EXIT_Callback(hObject, eventdata, handles) % hObject handle to EXIT (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close; % -------------------------------------------------------------------- function file_Callback(hObject, eventdata, handles) % hObject handle to file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_52_Callback(hObject, eventdata, handles) % hObject handle to Untitled_52 (see GCBO) % evntdaa rserved-to e dene in fur veio f MTLAB %handle structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function ReloadRecentImage_Callback(hObject, eventdata, handles) % hObject handle to ReloadRecentImage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) x=handles.reload; [row,col,Cnums]=size(x); axes(handles.axes2); imshow(zeros([256,256])); if Cnums==1 if (row<=256)&(col<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes1); Imshow(extendx); else if (row<=256)&(col<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n,:)=x(m,n,:); else extendx(m,n,:)=realmax; end end end axes(handles.axes1); Imshow(extendx); msgbox('Please transform it to a monochrome image or it can not be processed correctly','fileopening','warning'); end title('recent image reloaded!'); set(handles.edit1,'string',0.0); handles.imdata=handles.reload; guidata(hObject, handles); % -------------------------------------------------------------------- function SaveResult_Callback(hObject, eventdata, handles) % hObject handle to SaveResult (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename, pathname] = uiputfile({'*.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 imwrite(handles.imdata,filename); guidata(hObject, handles); % -------------------------------------------------------------------- function Untitled_61_Callback(hObject, eventdata, handles) % hObject handle to Untitled_61 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function RLcoding_Callback(hObject, eventdata, handles) % hObject handle to RLcoding (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [M,N]=size(x); c=x(1,1); E(1,1)=c; E(2,1)=1; t1=1; for k=1:M for j=1:N if(not(and(k==1,j==1))) if(not(x(k,j)==c)) t1=t1+1; E(1,t1)=x(k,j);E(2,t1)=1; c=x(k,j); else E(2,t1)=E(2,t1)+1; end end end end Time=toc; set(handles.edit1,'string',Time); file = fopen('RLC.txt','w'); fprintf(file,'%d %d\n',E); fclose(file); msgbox('codes is saved in "RLC.txt"!'); guidata(hObject, handles); % -------------------------------------------------------------------- function LSSharpe_Callback(hObject, eventdata, handles) % hObject handle to LSSharpe (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); [row,col]=size(f); f2=zeros(row,col); for x=2:(row-1) for y=2:(col-1) g=f1(x-1,y)+f1(x+1,y)+f1(x,y-1)+f1(x,y+1)-4*f1(x,y); f2(x,y)=f1(x,y)-g; g=0; end end Time=toc; set(handles.edit1,'string',Time); extendx=double(zeros(256)); if (row<=256)&(row<=256) W=256; else W=max(row,col); end for m=1:W for n=1:W if (m<=row)&(n<=col) extendx(m,n)=f2(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes2); imshow(extendx,[0,255]); handles.imdata=f2; guidata(hObject, handles); % -------------------------------------------------------------------- function Huffman_Callback(hObject, eventdata, handles) % hObject handle to Huffman (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tic; x=handles.imdata; [M,N]=size(x); %%%%%%%%%static all different graylevel values in the image p1=1;s=M*N; for k=1:M for L=1:N f=0; for b=1:p1-1 if(c(b,1)==x(k,L)) f=1; break; end end if(f==0) c(p1,1)=x(k,L);p1=p1+1; end end end %%%%%%%%%%%%%Caculate the probabilities for every graylevel value for g=1:p1-1 p(g)=0;c(g,2)=01; for k=1:M for L=1:N if(c(g,1)==x(k,L)) p(g)=p(g)+1; end end end p(g)=p(g)/s; end %%%%%%%%Add the minmumal two probabilities pn=0;po=1; while(1) if(pn>=1.0) break; else [pm,p2]=min(p(1:p1-1));p(p2)=1.1; [pm2,p3]=min(p(1:p1-1));p(p3)=1.1; pn=pm+pm2;p(p1)=pn; tree(po,1)=p2;tree(po,2)=p3; po=po+1; p1=p1+1; end end %%%%%%%%%%coding for k=1:po-1 tt=k;m1=1; if(or(tree(k,1)<g,tree(k,2)<g)) if(tree(k,1)<g) c(tree(k,1),2)=c(tree(k,1),2)+m1; m2=1; while(tt<po-1) m1=m1*2; for L=tt:po-1 if(tree(L,1)==tt+g) c(tree(k,1),2)=c(tree(k,1),2)+m1; m2=m2+1;tt=L;break; elseif(tree(L,2)==tt+g) m2=m2+1;tt=L;break; end end end c(tree(k,1),3)=m2; end tt=k;m1=1; if(tree(k,2)<g) m2=1; while(tt<po-1) m1=m1*2; for L=tt:po-1 if(tree(L,1)==tt+g) c(tree(k,2),2)=c(tree(k,2),2)+m1; m2=m2+1;tt=L;break; elseif(tree(L,2)==tt+g) m2=m2+1;tt=L;break; end end end c(tree(k,2),3)=m2; end end end Time=toc; set(handles.edit1,'string',Time); file = fopen('HuffmanCodeTable.txt','w'); fprintf(file,'%d %d %d\n',c'); fclose(file); msgbox('CodesTable is saved in "HuffmanCodeTable.txt"!','help'); guidata(hObject, handles);