function varargout = guide4(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @guide4_OpeningFcn, ...
'gui_OutputFcn', @guide4_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
% --- Executes just before guide4 is made visible.
function guide4_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = guide4_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%示波器g4彩色图象更新函数
function updateg4(handles)
r=handles.img(:,:,1);%分别取出三个通道的图像
g=handles.img(:,:,2);
b=handles.img(:,:,3);
x=size(r);
x=(1:x(1,2));%x(:)是为了将信号转换为一段连续的向量
r=r(1,:);
g=g(1,:);
b=b(1,:);%b(:,1)表示矩阵b的第一列所有元素
axes(handles.g4);
cla;
plot(x,r,'r');%坐标点为圆圈标志,且线型为红色短划线的绘图样式
hold on
plot(x,g,'g'); %坐标点为圆圈标志,且线型为绿色短划线的绘图样式
plot(x,b,'b');%坐标点为圆圈标志,且线型为蓝色短划线的绘图样式
hold off;
ImageData1 = reshape(handles.img(:,:,1), [size(handles.img, 1) * size(handles.img, 2) 1]);%重构数组,单个通道与图像大小
ImageData2 = reshape(handles.img(:,:,2), [size(handles.img, 1) * size(handles.img, 2) 1]);
ImageData3 = reshape(handles.img(:,:,3), [size(handles.img, 1) * size(handles.img, 2) 1]);
[H1, X1] = hist(ImageData1, 1:5:256);%直方图
[H2, X2] = hist(ImageData2, 1:5:256);
[H3, X3] = hist(ImageData3, 1:5:256);
axes(handles.g5);
cla;
hold on;
plot(X1, H1, 'r');%三条曲线合并
plot(X2, H2, 'g');
plot(X3, H3, 'b');
axis([0 256 0 max([H1 H2 H3])]);%设置范围,横轴0-256,纵轴0-max([H1 H2 H3](最大直方图)
%示波器灰色图象更新函数
function updateg4_1(handles)
k=handles.img(:,:,1);
x=size(k);
x=(1:x(1,2));
k=k(1,:);
axes(handles.g4);
cla;
plot(x,k,'k');
ImageData = reshape(handles.img, [size(handles.img, 1) * size(handles.img, 2) 1]);
[H, X] = hist(ImageData, 1:5:256);
axes(handles.g5);
cla;
hold on;
plot(X, H, 'k');
axis([0 256 0 max(H)]);
%打开
% --- Executes on button press in open.
function open_Callback(hObject, eventdata, handles)
[file, path]=uigetfile('*.*','请选择图片','multiselect','on','.\');
image=[path file];
handles.file=image;
if (file==0)
warndlg('请选择一张图片...') ;
end
[fpath, fname, fext]=fileparts(file);
validex=({'.bmp','.jpg','.jpeg','.png'});
found=0;
for (x=1:length(validex))
if (strcmpi(fext,validex{x}))
found=1;
handles.img=imread(image);
handles.i=imread(image);
h = waitbar(0,'等待...');
steps = 100;
for step = 1:steps
waitbar(step / steps)
end
close(h)
axes(handles.g1);
cla;
imshow(handles.img);
axes(handles.g2);
cla;
imshow(handles.img);
guidata(hObject,handles);
break;
end
end
if (found==0)
end
set(handles.g3,'Visible','on');
set(handles.g4,'Visible','on');
% 示波器g3更新
mysize=size(handles.img);
if numel(mysize)>2
r=handles.i(:,:,1);
g=handles.i(:,:,2);
b=handles.i(:,:,3);
x=size(r);
x=(1:x(1,2));
r=r(1,:);
g=g(1,:);
b=b(1,:);
axes(handles.g3);
cla;
plot(x,r,'r');
hold on
plot(x,g,'g');
plot(x,b,'b');
set(gca,'xtick',-inf:inf:inf);
hold off;
else
k=handles.img(:,:,1);
x=size(k);
x=(1:x(1,2));
k=k(1,:);
axes(handles.g3);
cla;
plot(x,k,'k');
end
%示波器g5更新
mysize=size(handles.img);
if numel(mysize)>2
ImageData1 = reshape(handles.img(:,:,1), [size(handles.img, 1) * size(handles.img, 2) 1]);
ImageData2 = reshape(handles.img(:,:,2), [size(handles.img, 1) * size(handles.img, 2) 1]);
ImageData3 = reshape(handles.img(:,:,3), [size(handles.img, 1) * size(handles.img, 2) 1]);
[H1, X1] = hist(ImageData1, 1:5:256);
[H2, X2] = hist(ImageData2, 1:5:256);
[H3, X3] = hist(ImageData3, 1:5:256);
axes(handles.g5);
cla;
hold on;
plot(X1, H1, 'r');
plot(X2, H2, 'g');
plot(X3, H3, 'b');
axis([0 256 0 max([H1 H2 H3])]);
else
ImageData = reshape(handles.img, [size(handles.img, 1) * size(handles.img, 2) 1]);
[H, X] = hist(ImageData, 1:5:256);
axes(handles.g5);
cla;
hold on;
plot(X, H, 'k');
axis([0 256 0 max(H)]);
end
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function exit_Callback(hObject, eventdata, handles)
close all;
function save_Callback(hObject, eventdata, handles)
[file path]= uiputfile('*.jpg','Save Image as');
save=[path file]; imwrite(handles.img,save,'jpg');
function clean_Callback(hObject, eventdata, handles)
handles.img=handles.i;
axes(handles.g2);
cla;
imshow(handles.img);
updateg4(handles);
guidata(hObject,handles);
function gaosizaobo_Callback(hObject, eventdata, handles)
handles.img = imnoise(handles.img,'gaussian');
axes(handles.g2);
cla;
imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function bosongzaobo_Callback(hObject, eventdata, handles)
h = waitbar(0,'等待...');
steps = 200;
for step = 1:steps
waitbar(step / steps)
end
close(h)
handles.img = imnoise(handles.img,'poisson');
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function jiaoyanzaobo_Callback(hObject, eventdata, handles)
handles.img = imnoise(handles.img,'salt & pepper',0.02);
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function bandianzaobo_Callback(hObject, eventdata, handles)
handles.img = imnoise(handles.img,'speckle',0.04);
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function gaosilvbo_Callback(hObject, eventdata, handles)
hsize=[8 8]; sigma=1.7;
h=fspecial('gaussian',hsize,sigma);
handles.img=imfilter(handles.img,h,'replicate');
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function junzhilvbo_Callback(hObject, eventdata, handles)
h=fspecial('average');
handles.img=imfilter(handles.img,h,'replicate');
axes(handles.g2); cla; imshow(handles.img)
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function zhongzhilvbo_Callback(hObject, eventdata, handles)
r=medfilt2(handles.img(:,:,1));
g=medfilt2(handles.img(:,:,2));
b=medfilt2(handles.img(:,:,3));
handles.img=cat(3,r,g,b);
axes(handles.g2); cla; imshow(handles.img);
guidata(hObject,handles);
mysize=size(handles.img);
if numel(mysize)>2
updateg4(handles)
else
updateg4_1(handles)
end
function slider1_Callback(hObject, eventdata, handles)
x=get(hObject,'Value');
r=handles.img(:,:,1);
g=handles.img(:,:,2);
b=handles.img(:,:,3);
r1=r+x;
rcon=cat(3,r1,g,b);
axes(handles.g2);
cla;
imshow(rcon)
handles.img=rcon;
r=handles.img(:,:,1);
g=handles.img(:,:,2);
b=handles.img(:,:,3);
x=size(r);
x=(1:x(1,2));
r=r(1,:);
g=g(1,:);
b=b(1,:);
axes(handles.g4);
plot(x,r,'r');
hold on
plot(x,g,'g');
plot(x,b,'b');
hold off;
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(g