?? mydip.asv
字號:
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,[b,a]);
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);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -