您好,欢迎来到图艺博知识网。
搜索
您的当前位置:首页MATLAB(GUI)数字图像处理实验报告(可打印修改) (2)

MATLAB(GUI)数字图像处理实验报告(可打印修改) (2)

来源:图艺博知识网
2012—2013学年第二学期

课程名称:教学实践Ⅱ:软硬件提高训练任课教师: 题

目:MATLAB数字图像处理

学号:ROB12023姓名: 年级:2012级专业:自动化

提交日期: 年 月 日

评语:

成绩: 评卷人:

1.设计目的

利用MATLAB的GUI程序设计一个简单实用的图像处理程序。该程序应具备图像处理的常用功能,以满足要求。2.设计要求

设计程序有以下基本功能:1)图像的读取、保存和程序退出2)图像转化为灰度图像3)底片处理(反色)4)截图

5)亮度和对比度度调节6)图像的翻转与旋转7)添加噪声8)平滑和锐化9)直方图均衡化处理10)图像的腐蚀和膨胀11)边缘检测12)还原和撤销

3.总体设计

4.程序与运行结果

4.1图像的读取、保存和程序退出1.图像读取1)主要程序

A=imread(str) %读取图片imshow(A) %显示图片2)运行结果

2.图像保存1)主要程序

imwrite(handles.img,sfilefullname); %图像的保存

2)运行结果

3.退出1)主要程序close all; %关闭所有 2)运行结果(略)

4.2图像转化为灰度图像1)主要程序

C=rgb2gray(img); %将rgb彩色图像转换为灰度图2)运行结果

4.3底片处理(反色)1)主要程序

I=imcomplement(handles.img); %底片处理(反色)2)运行结果

4.4截图1)主要程序

a=imcrop(handles.img); %图像的截取2)运行结果

4.5亮度和对比度度调节1.亮度调节1)主要程序

y=imadjust(handles.img,[ ], [ ],p1); 2)运行结果

%亮度调节

2.对比度调节1)主要程序

f=immultiply(handles.img,p1); %对比度增强f=imdivide(handles.img,p1); %对比度减弱2)运行结果

4.6图像的翻转与旋转1.图像的翻转1)主要程序fliplr(b)

%图像的翻转

2)运行结果

2.图像的旋转1)主要程序

f=imrotate(handles.img,p1,'bilinear','crop'); 2)运行结果

%图像的旋转

4.7添加噪声1.椒盐噪声1)主要程序

f=imnoise(handles.img,'salt & pepper',p1); 2)运行结果

%添加椒盐噪声

2.高斯噪声1)主要程序

f=imnoise(handles.img,'gaussian',p1,p2); 2)运行结果

%添加高斯噪声

3.乘法噪声1)主要程序

f=imnoise(handles.img,'speckle',p1); 2)运行结果

%添加乘法噪声

4.8平滑和锐化1.平滑1)主要程序

Imfilter % 均值滤波medfilt2 % 中值滤波2)运行结果

2.锐化1)主要程序

fspecial( ) %创建预定义的滤波算子

imfilter( );imadd( ); %在实现卷积运算的基础上进行滤波2)运行结果

4.9直方图均衡化处理1.灰度图像1)主要程序

B=histeq(C); %直方图均衡化函数2)运行结果

2.RGB图像1)主要程序

B=histeq(C); %直方图均衡化函数2)运行结果

4.10 图像的腐蚀和膨胀1.图像的腐蚀1)主要程序

I1=imerode(handles.img,se); %图像的腐蚀2)运行结果

2.图像的膨胀1)主要程序

I1=imdilate(handles.img,se); %图像的膨胀

2)运行结果

4.11 边缘检测1)主要程序

rslt=ycbcr2rgb(uint8(img2)); %边缘检测2)运行结果

4.12 还原和撤销1.还原

1)主要程序

global S %设计一个全局变量S,保存初始图像路径,以便之后的还原操作 2)运行结果

2.撤销(只能撤销一次)1)主要程序

global T %设计一个全局变量S,保存每次操作原图像,以便撤销操作 2)运行结果

5.心得体会

通过用MATLAB(GUI)设计数字图像处理界面,我掌握了有关数字图像

处理的相关知识和GUI的操作知识,让理论知识与实际相结合,做出了数字图像处理的图形用户界面。

在实践前,通过一天的数字图像处理的相关知识与一天GUI的知识的学习,掌握了其基本入门知识;然后在实践中,结合要设计要求补充自学相关知识,在实践中

验证理论知识,充实理论知识,加强动手能力;在实践后,总结实践过程,撰写实验报告,再次加深所学知识。

6.附录代码(带注释)

function varargout = dazouyematlab(varargin)%DAZOUYEMATLAB M-file for dazouyematlab.fig% DAZOUYEMATLAB, by itself, creates a new DAZOUYEMATLAB or raises the existing% singleton*.%% H = DAZOUYEMATLAB returns the handle to a new DAZOUYEMATLAB or the handle to% the existing singleton*.%% DAZOUYEMATLAB('Property','Value',...) creates a new DAZOUYEMATLAB using the% given property value pairs. Unrecognized properties are passed via% varargin to dazouyematlab_OpeningFcn. This calling syntax produces a% warning when there is an existing singleton*.%% DAZOUYEMATLAB('CALLBACK') and DAZOUYEMATLAB('CALLBACK',hObject,...) call the% local function named CALLBACK in DAZOUYEMATLAB.M with the given input% arguments.%% *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 dazouyematlab% Last Modified by GUIDE v2.5 18-Jul-2014 11:52:53

% Begin initialization code - DO NOT EDITgui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @dazouyematlab_OpeningFcn, ... 'gui_OutputFcn', @dazouyematlab_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 dazouyematlab is made visible.

function dazouyematlab_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 unrecognized PropertyName/PropertyValue pairs from the% command line (see VARARGIN)% Choose default command line output for dazouyematlabhandles.output = hObject;% Update handles structureguidata(hObject, handles);

% UIWAIT makes dazouyematlab wait for user response (see UIRESUME)% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = dazouyematlab_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 pushbutton14.

function pushbutton14_Callback(hObject, eventdata, handles)%退出

% hObject handle to pushbutton14 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles clc;

close all;close(gcf);clear;

structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton15.

function pushbutton15_Callback(hObject, eventdata, handles)%图像载入

% 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)[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif'},'选择图片'); str=[pathname filename];global S

%设计一个全局变量S,保存初始图像路径,以便之后的还原操作S=str;

A=imread(str);

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

set(handles.axes1,'HandleVisibility','OFF');axes(handles.axes2); imshow(A);

cla(handles.axes2);handles.img=A;

guidata(hObject,handles);

% --- Executes on button press in pushbutton16.

function pushbutton16_Callback(hObject, eventdata, handles)%图像保存

% 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)

[sfilename,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像文件','untitled.jpg');if ~isequal([sfilename,sfilepath],[0,0]) sfilefullname=[sfilepath,sfilename]; imwrite(handles.img,sfilefullname);else

msgbox('取消保存','保存失败');

end

% --- Executes on button press in pushbutton22.

function pushbutton22_Callback(hObject, eventdata, handles)%腐蚀

% hObject handle to pushbutton22 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)temp={'腐蚀圆盘半径:'};defans={'0'};

p=inputdlg(temp,'请输入',1,defans);p1=str2num(p{1});se=strel('disk',p1,0);global T

axes(handles.axes2);T=handles.img;

I1=imerode(handles.img,se);imshow(I1); handles.img=I1;

guidata(hObject,handles);

% --- Executes on button press in pushbutton23.

function pushbutton23_Callback(hObject, eventdata, handles)%膨胀

% hObject handle to pushbutton23 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)temp={'膨胀结构长度:'};defans={'0'};

p=inputdlg(temp,'请输入',1,defans);p1=str2num(p{1});se=strel('line',p1,0);

I1=imdilate(handles.img,se);global T

axes(handles.axes2);T=handles.img;imshow(I1);handles.img=I1;

guidata(hObject,handles);

% --- Executes on button press in pushbutton21.

function pushbutton21_Callback(hObject, eventdata, handles)%RGB图象

% hObject handle to pushbutton21 (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=handles.img;RGB=handles.img;R=RGB(:,:,1);G=RGB(:,:,2);B=RGB(:,:,3);

G1(:,:,1)=histeq(R);G1(:,:,2)=histeq(G);G1(:,:,3)=histeq(B);imshow(G1);handles.img=G1;

guidata(hObject,handles);

% --- Executes on button press in pushbutton19.

function pushbutton19_Callback(hObject, eventdata, handles)%添加噪声

% 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)I=handles.img;global T

str=get(handles.popupmenu7,'value');axes(handles.axes2);switch str case 1 T=handles.img;

prompt={'输入椒盐噪声参数1:'};defans={'0.02'};

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

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

guidata(hObject,handles);case 2

T=handles.img;

end

prompt={'输入高斯噪声1:','输入高斯噪声2'};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

T=handles.img;

prompt={'输入乘性噪声1:'};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);

% --- Executes on selection change in popupmenu7.

function popupmenu7_Callback(hObject, eventdata, handles)% hObject handle to popupmenu7 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu7 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu7

% --- Executes during object creation, after setting all properties.function popupmenu7_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu7 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on button press in pushbutton17.

function pushbutton17_Callback(hObject, eventdata, handles)%平滑

% 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)global T

str=get(handles.popupmenu5,'value');axes(handles.axes2);switch str case 1 T=handles.img; prompt={'请输入模版维度:'}; defans={'3'}; p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1}); h1=fspecial('average',[p1 p1]); I=imfilter(handles.img,h1); imshow(I); handles.img=I; guidata(hObject,handles); case 2 T=handles.img;

prompt={'请输入模版维度:'};defans={'3'};

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

if numel(size(handles.img))>2

A=handles.img;R=A(:,:,1);G=A(:,:,2);B=A(:,:,3);

GP(:,:,1)=medfilt2(R,[p1 p1]);GP(:,:,2)=medfilt2(G,[p1 p1]);GP(:,:,3)=medfilt2(B,[p1 p1]);imshow(GP);handles.img=GP;else

A=handles.img;

I=medfilt2(A,[p1 p1]);imshow(I);handles.img=I;end

end

guidata(hObject,handles);

% --- Executes on button press in pushbutton20.

function pushbutton20_Callback(hObject, eventdata, handles)% hObject handle to pushbutton20 (see GCBO)

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

close all;close(gcf);clear;

% --- Executes on button press in pushbutton16.

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

str=get(handles.popupmenu5,'value');axes(handles.axes2);switch str case 1 T=handles.img; prompt={'请输入模版维度:'}; defans={'3'}; p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1}); h1=fspecial('average',[p1 p1]); I=imfilter(handles.img,h1); imshow(I); handles.img=I; guidata(hObject,handles); case 2 T=handles.img;

prompt={'请输入模版维度:'};defans={'3'};

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

if numel(size(handles.img))>2

A=handles.img;R=A(:,:,1);G=A(:,:,2);B=A(:,:,3);

GP(:,:,1)=medfilt2(R,[p1 p1]); GP(:,:,2)=medfilt2(G,[p1 p1]); GP(:,:,3)=medfilt2(B,[p1 p1]); imshow(GP); handles.img=GP; else A=handles.img; I=medfilt2(A,[p1 p1]); imshow(I); handles.img=I; end guidata(hObject,handles); end

% --- Executes on button press in pushbutton18.

function pushbutton18_Callback(hObject, eventdata, handles)%锐化

% 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)global T

str=get(handles.popupmenu6,'value');axes(handles.axes2);T=handles.img;g=handles.img;switch str case 1 h=fspecial('sobel'); case 2 h=fspecial('prewitt'); case 3 h=fspecial('laplacian');end

if numel(size(g))>2 R=g(:,:,1); G=g(:,:,2); B=g(:,:,3);

R1=imfilter(R,h);

GP(:,:,1)=imadd(R,R1); G1=imfilter(G,h);

GP(:,:,2)=imadd(G,G1); B1=imfilter(B,h);

GP(:,:,3)=imadd(B,B1);

imshow(GP); handles.img=GP;else

g1=g;

g2=imfilter(g1,h); g3=imadd(g2,g1); imshow(g3); handles.img=g3;end

guidata(hObject,handles);

% --- Executes on selection change in popupmenu5.

function popupmenu5_Callback(hObject, eventdata, handles)% hObject handle to popupmenu5 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu5 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu5

% --- Executes during object creation, after setting all properties.function popupmenu5_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on selection change in popupmenu6.

function popupmenu6_Callback(hObject, eventdata, handles)% hObject handle to popupmenu6 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu6 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu6

% --- Executes during object creation, after setting all properties.function popupmenu6_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on button press in pushbutton10.

function pushbutton10_Callback(hObject, eventdata, handles)%检测

% 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)global T

str=get(handles.popupmenu4,'value');axes(handles.axes2);

if numel(size(handles.img))>2 I=handles.img; switch str case 1 T=handles.img; img=I; [x y z]=size(img); if z==1 rslt=edge(img,'Roberts'); elseif z==3 img1=rgb2ycbcr(img); dx1=edge(img1(:,:,1),'Roberts'); dx1=(dx1*255); img2(:,:,1)=dx1; img2(:,:,2)=img1(:,:,2); img2(:,:,3)=img1(:,:,3); rslt=ycbcr2rgb(uint8(img2)); end imshow(rslt); handles.img=rslt; guidata(hObject,handles); case 2

T=handles.img; img=I; [x y z]=size(img); if z==1 rslt=edge(img,'sobel'); elseif z==3 img1=rgb2ycbcr(img); dx1=edge(img1(:,:,1),'sobel'); dx1=(dx1*255); img2(:,:,1)=dx1; img2(:,:,2)=img1(:,:,2); img2(:,:,3)=img1(:,:,3); rslt=ycbcr2rgb(uint8(img2)); end imshow(rslt); handles.img=rslt; guidata(hObject,handles); case 3 T=handles.img; img=I; [x y z]=size(img); if z==1 rslt=edge(img,'Prewitt'); elseif z==3 img1=rgb2ycbcr(img); dx1=edge(img1(:,:,1),'Prewitt'); dx1=(dx1*255); img2(:,:,1)=dx1; img2(:,:,2)=img1(:,:,2); img2(:,:,3)=img1(:,:,3); rslt=ycbcr2rgb(uint8(img2)); end imshow(rslt); handles.img=rslt; guidata(hObject,handles); case 4 T=handles.img; img=I; [x y z]=size(img); if z==1 rslt=edge(img,'log'); elseif z==3 img1=rgb2ycbcr(img); dx1=edge(img1(:,:,1),'log');

dx1=(dx1*255); img2(:,:,1)=dx1; img2(:,:,2)=img1(:,:,2); img2(:,:,3)=img1(:,:,3); rslt=ycbcr2rgb(uint8(img2)); end imshow(rslt); handles.img=rslt; guidata(hObject,handles); case 5 T=handles.img; img=I; [x y z]=size(img); if z==1 rslt=edge(img,'canny'); elseif z==3 img1=rgb2ycbcr(img); dx1=edge(img1(:,:,1),'canny'); dx1=(dx1*255); img2(:,:,1)=dx1; img2(:,:,2)=img1(:,:,2); img2(:,:,3)=img1(:,:,3); rslt=ycbcr2rgb(uint8(img2)); end imshow(rslt); handles.img=rslt; guidata(hObject,handles); endelse

g1=handles.img; switch str case 1 T=handles.img; g2=edge(g1,'Roberts'); imshow(g2); handles.img=g2; guidata(hObject,handles); case 2 T=handles.img; g2=edge(g1,'sobel'); imshow(g2); handles.img=g2; guidata(hObject,handles); case 3

T=handles.img; g2=edge(g1,'Prewitt'); imshow(g2); handles.img=g2; guidata(hObject,handles); case 4 T=handles.img; g2=edge(g1,'log'); imshow(g2); handles.img=g2; guidata(hObject,handles); case 5 T=handles.img; g2=edge(g1,'canny'); imshow(g2); handles.img=g2; guidata(hObject,handles); endend

% --- Executes on selection change in popupmenu4.

function popupmenu4_Callback(hObject, eventdata, handles)% hObject handle to popupmenu4 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu4

% --- Executes during object creation, after setting all properties.function popupmenu4_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu4 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on button press in pushbutton8.

function pushbutton8_Callback(hObject, eventdata, handles)%翻转

% 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)global T

str=get(handles.popupmenu2,'value');axes(handles.axes2);I=handles.img;if numel(size(I))>2 switch str case 1 T=handles.img; b=I(:,:,1); c=I(:,:,2); d=I(:,:,3); I1(:,:,1)=fliplr(b); I1(:,:,2)=fliplr(c); I1(:,:,3)=fliplr(d); case 2 T=handles.img; b=I(:,:,1); c=I(:,:,2); d=I(:,:,3); I1(:,:,1)=flipud(b); I1(:,:,2)=flipud(c); I1(:,:,3)=flipud(d);end

imshow(I1);handles.img=I1;

guidata(hObject,handles);else

switch str case 1 T=handles.img; f=fliplr(I); case 2 T=handles.img; f=flipud(I);end

imshow(f);handles.img=f;

guidata(hObject,handles);end

% --- Executes on button press in pushbutton9.

function pushbutton9_Callback(hObject, eventdata, handles)%旋转

% 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)global T

T=handles.img;

str=get(handles.popupmenu3,'value');axes(handles.axes2);

prompt={'请输入旋转角度:'};defans={'0'};

p=inputdlg(prompt,'input',1,defans);p1=str2num(p{1});switch str case 1 p1=-p1; case 2 p1=p1;end

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

guidata(hObject,handles);

% --- Executes on selection change in popupmenu1.

function popupmenu2_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.function popupmenu2_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called% 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

% --- Executes on selection change in popupmenu3.

function popupmenu3_Callback(hObject, eventdata, handles)% hObject handle to popupmenu3 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu3

% --- Executes during object creation, after setting all properties.function popupmenu3_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on button press in pushbutton6.

function pushbutton6_Callback(hObject, eventdata, handles)%亮度调节

% 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)global T

axes(handles.axes2);T=handles.img;

prompt={'调整倍数 ([0,1]:明 [1,~):暗)'};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);

% --- Executes on button press in pushbutton7.

function pushbutton7_Callback(hObject, eventdata, handles)%对比度调节按钮

% 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)global T

str=get(handles.popupmenu1,'value');axes(handles.axes2);T=handles.img;

prompt={'请输入参数:'};defans={'1'};

p=inputdlg(prompt,'input',1,defans);p1=str2num(p{1});switch str case 1 f=immultiply(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handles); case 2 f=imdivide(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handles);end

% --- Executes on selection change in popupmenu1.

function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% 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

% --- Executes on button press in pushbutton4.

function pushbutton4_Callback(hObject, eventdata, handles)%撤消

% 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)global T

handles.img=T;

axes(handles.axes2); imshow(T);

guidata(hObject,handles);

% --- Executes on button press in pushbutton5.

function pushbutton5_Callback(hObject, eventdata, handles)%还原

% 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)global S y=imread(S);

axes(handles.axes2); imshow(y);handles.img=y;

guidata(hObject,handles);

% --- 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

%设计一个全局变量T,保存初始图像路径,以便之后的撤销操作axes(handles.axes2);T=handles.img;img=handles.img;if numel(size(img))>2 C=rgb2gray(img);else

C=img;end

imshow(C);handles.img=C;

guidata(hObject,handles);

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)%底片处理(反色)

% 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)global T

axes(handles.axes2);T=handles.img;

I=imcomplement(handles.img); imshow(I);handles.img=I;

guidata(hObject,handles);

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles)%截图

% 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=handles.img;

a=imcrop(handles.img); imshow(a);

handles.img=a;

guidata(hObject,handles);

% --------------------------------------------------------------------function Untitled_1_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (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 pushbutton24.

function pushbutton24_Callback(hObject, eventdata, handles)%灰度图像

% hObject handle to pushbutton24 (see GCBO)

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

T=handles.img;img=handles.img;if numel(size(img))>2 C=rgb2gray(img);else

C=img;end

B=histeq(C);

axes(handles.axes2); imshow(B);handles.img=B;

guidata(hObject,handles);

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuoyibo.net 版权所有 湘ICP备2023021910号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务