MATLAB课程设计--GUI图像处理 下载本文

% -------------------------------------------------------------------- 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) [filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'??è?í???'); if isequal(filename,0)|isequal(pathname,0) errordlg('??óD???D???t','3?′í'); return; else

file=[pathname,filename]; global S %éè??ò???è???a?á?S£?a£′?3?ê?í???????£?ò?a???oóμ??1?-2ù?? S=file;

x=imread(file);

set(handles.axes1,'HandleVisibility','ON'); axes(handles.axes1); imshow(x);

set(handles.axes1,'HandleVisibility','OFF'); axes(handles.axes2); imshow(x); handles.img=x;

guidata(hObject,handles); end

% -------------------------------------------------------------------- function about_Callback(hObject, eventdata, handles) % hObject handle to about (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('?aê?ò???GUIμ?í???′|àí3ìDò','1?óú');

% -------------------------------------------------------------------- function help_Callback(hObject, eventdata, handles) % hObject handle to help (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% -------------------------------------------------------------------- function save_Callback(hObject, eventdata, handles) % hObject handle to save (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

[sfilename ,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'a£′?í??????t','untitled.jpg');

37 / 52

if ~isequal([sfilename,sfilepath],[0,0]) sfilefullname=[sfilepath ,sfilename]; imwrite(handles.img,sfilefullname); else

msgbox('???′á?è????÷£?','a£′?ê§?ü'); end

% --- Executes on button press in radiobutton12.

function radiobutton12_Callback(hObject, eventdata, handles) % hObject handle to radiobutton12 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton12 global T

axes(handles.axes2); T=getimage; prompt={'μ???a?êy'}; defans={'1'};

p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1});

y=imadjust(handles.img,[ ], [ ],p1); %??ááí??? imshow(y); handles.img=y;

guidata(hObject,handles);

% -------------------------------------------------------------------- function uipanel4_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel4 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global T

str=get(hObject,'string'); axes(handles.axes2); switch str

case '??????é?' T=getimage; prompt={'ê?è???????é?2?êy1:'}; defans={'0.02'};

p=inputdlg(prompt,'input',1,defans);

38 / 52

p1=str2num(p{1});

f=imnoise(handles.img,'salt & pepper',p1); imshow(f); handles.img=f;

guidata(hObject,handles); case '???1??é?' T=getimage; prompt={'ê?è????1??é?2?êy1:','ê?è????1??é?2?êy2'}; defans={'0','0.02'};

p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1}); p2=str2num(p{2});

f=imnoise(handles.img,'gaussian',p1,p2); imshow(f); handles.img=f;

guidata(hObject,handles); case '3?D???é?' T=getimage; prompt={'ê?è?3?D???é?2?êy1:'}; defans={'0.02'};

p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1});

f=imnoise(handles.img,'speckle',p1); imshow(f); handles.img=f;

guidata(hObject,handles); end

% --- Executes on button press in radiobutton16.

function radiobutton16_Callback(hObject, eventdata, handles) % hObject handle to radiobutton16 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton16 global T

axes(handles.axes2); T=getimage;

x=rgb2gray(handles.img); %RGBí????a???a?ò?èí??? imshow(x); handles.img=x;

guidata(hObject,handles);

39 / 52

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles) % 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) global T

axes(handles.axes2); T=getimage;

x=imcrop(handles.img); %??í? imshow(x); handles.img=x;

guidata(hObject,handles);

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles) %í???Dy?a % 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) global T

axes(handles.axes2); T=getimage; prompt={'Dy?a???è:'}; defans={'0'};

p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1});

f=imrotate(handles.img,p1,'bilinear','crop'); imshow(f); handles.img=f;

guidata(hObject,handles);

% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

40 / 52