1 简介
图像直方图、滤波、小波变换、分割处理系统?
2 部分代码
function varargout = exp_gs(varargin)
% EXP_GS M-file for exp_gs.fig
% ? ? EXP_GS, by itself, creates a new EXP_GS or raises the existing
% ? ? singleton*.
%
% ? ? H = EXP_GS returns the handle to a new EXP_GS or the handle to
% ? ? the existing singleton*.
%
% ? ? EXP_GS('CALLBACK',hObject,eventData,handles,...) calls the local
% ? ? function named CALLBACK in EXP_GS.M with the given input arguments.
%
% ? ? EXP_GS('Property','Value',...) creates a new EXP_GS or raises the
% ? ? existing singleton*. Starting from the left, property value pairs are
% ? ? applied to the GUI before exp_gs_OpeningFcn gets called. An
% ? ? unrecognized property name or invalid value makes property application
% ? ? stop. All inputs are passed to exp_gs_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
% Edit the above text to modify the response to help exp_gs
% Last Modified by GUIDE v2.5 30-Jun-2010 13:33:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', ? ? ? mfilename, ...
? ? ? ? ? ? ? ? ? 'gui_Singleton', gui_Singleton, ...
? ? ? ? ? ? ? ? ? 'gui_OpeningFcn', @exp_gs_OpeningFcn, ...
? ? ? ? ? ? ? ? ? 'gui_OutputFcn', @exp_gs_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 exp_gs is made visible.
function exp_gs_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 exp_gs (see VARARGIN)
% Choose default command line output for exp_gs
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes exp_gs wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = exp_gs_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 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
% ? ? ? str2double(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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- 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)
ImgPath=get(handles.edit1,'String');
global img_1;
img_1=imread(ImgPath);
axes(handles.axes1);
imshow(img_1);
global histogram1;
histogram1=zeros(1,256);
[sizex,sizey]=size(img_1);
for ii=1:sizex % 计算直方图
? for jj=1:sizey
? ? ? histogram1(img_1(ii,jj)+1)=histogram1(img_1(ii,jj)+1)+1;
? end
end
maxhisto1=sum(histogram1);% 归一化
histogram1=histogram1/maxhisto1;
axes(handles.axes2);
bar(0:255,histogram1);
axis([0 255 0 max(histogram1)]);
% --- 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 img_1;
[sizex,sizey]=size(img_1);
for ii=1:sizex % 减小动态范围
? for jj=1:sizey
? ? ? img_1tmp(ii,jj)=floor(img_1(ii,jj)/2)+64;
? end
end
global img_11;
img_11=img_1tmp;
axes(handles.axes3);
imshow(img_11);
histogram2=zeros(1,256);
for ii=1:sizex
? for jj=1:sizey
? ? ? histogram2(img_11(ii,jj)+1)=histogram2(img_11(ii,jj)+1)+1;
? end
end
maxhisto2=sum(histogram2);
histogram2=histogram2/maxhisto2;
axes(handles.axes4);
bar(0:255,histogram2);
axis([0 255 0 max(histogram2)]);
% --- 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 img_1;
[sizex,sizey]=size(img_1);
for ii=1:sizex % 直方图左移
? for jj=1:sizey
? ? ? img_1tmp(ii,jj)=img_1(ii,jj)-30;
? end
end
global img_11;
img_11=img_1tmp;
axes(handles.axes3);
imshow(img_11);
histogram3=zeros(1,256);
for ii=1:sizex
? for jj=1:sizey
? ? ? histogram3(img_11(ii,jj)+1)=histogram3(img_11(ii,jj)+1)+1;
? end
end
maxhisto3=sum(histogram3);
histogram3=histogram3/maxhisto3;
axes(handles.axes4);
bar(0:255,histogram3);
axis([0 255 0 max(histogram3)]);
% --- 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 img_1;
[sizex,sizey]=size(img_1);
for ii=1:sizex % 直方图右移
? for jj=1:sizey
? ? ? img_1tmp(ii,jj)=img_1(ii,jj)+30;
? end
end
global img_11;
img_11=img_1tmp;
axes(handles.axes3);
imshow(img_11);
histogram4=zeros(1,256);
for ii=1:sizex
? for jj=1:sizey
? ? ? histogram4(img_11(ii,jj)+1)=histogram4(img_11(ii,jj)+1)+1;
? end
end
maxhisto4=sum(histogram4);
histogram4=histogram4/maxhisto4;
axes(handles.axes4);
bar(0:255,histogram4);
axis([0 255 0 max(histogram4)]);
% --- 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 histogram1;
% 直方图均衡化
histosum1=zeros(1,256);
histosum1(1)=histogram1(1);
for ii=2:256 % 累积直方图各项tk
? histosum1(ii)=histosum1(ii-1)+histogram1(ii);
end
tk=floor(255.*histosum1+0.5); % tk取整扩展
global img_1;
[sizex,sizey]=size(img_1);
global img_11;
for ii=1:sizex % 确定映射关系
? for jj=1:sizey
? ? ? img_11(ii,jj)=tk(img_1(ii,jj)+1);
? end
end
axes(handles.axes3);
imshow(img_11);
histogram5=zeros(1,256);
for ii=1:sizex
? for jj=1:sizey
? ? ? histogram5(img_11(ii,jj)+1)=histogram5(img_11(ii,jj)+1)+1;
? end
end
maxhisto5=sum(histogram5);
histogram5=histogram5/maxhisto5;
axes(handles.axes4);
bar(0:255,histogram5);
axis([0 255 0 max(histogram5)]);
% --- 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)
% 直方图规定化
gdhistogram=zeros(1,256);
for ii=1:256 % 规定化函数的直方图,同P95图4.4.6(b)所示
? gdhistogram(ii)=ii;
end
gdhistosum=sum(gdhistogram);
for ii=1:256 % 归一化
? gdhistogram(ii)=gdhistogram(ii)/gdhistosum;
end
global histogram1;
histosum1=zeros(1,256);
histosum1(1)=histogram1(1);
for ii=2:256 % 原图的累积直方图
? histosum1(ii)=histosum1(ii-1)+histogram1(ii);
end
histosum2=zeros(1,256);
histosum2(1)=gdhistogram(1);
for ii=2:256 % 规定化函数的累积直方图
? histosum2(ii)=histosum2(ii-1)+gdhistogram(ii);
end
GML=zeros(1,256);
if histosum2(1)~=0 % GML映射
? tmp1=abs(histosum2(1)-histosum1(1));
? for ii=2:256
? ? ? tmp2=abs(histosum2(1)-histosum1(ii));
? ? ? if tmp2<=tmp1
? ? ? ? ? tmp1=tmp2;
? ? ? else
? ? ? ? ? GML(ii-1)=1;
? ? ? ? ? break;
? ? ? end
? end
end
for ii=2:256
? if histosum2(ii)~=histosum2(ii-1)
? ? ? tmp1=abs(histosum2(ii)-histosum1(1));
? ? ? for kk=2:256
? ? ? ? ? tmp2=abs(histosum2(ii)-histosum1(kk));
? ? ? ? ? if tmp2<=tmp1
? ? ? ? ? ? ? tmp1=tmp2;
? ? ? ? ? else
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)
global img_3c;
global img_3s;
global img_31;
img_31=uint8(waverec2(img_3c,img_3s,'haar'));
axes(handles.axes8);
imshow(img_31);
function edit10_Callback(hObject, eventdata, handles)
% hObject ? handle to edit10 (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 edit10 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit10 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- 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 img_31;
ImgPath=get(handles.edit10,'String');
imwrite(img_31,ImgPath,'bmp');
function edit11_Callback(hObject, eventdata, handles)
% hObject ? handle to edit11 (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 edit11 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit11 as a double
% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit11 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton25.
function pushbutton25_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton25 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_4;
ImgPath=get(handles.edit11,'String');
img_4=imread(ImgPath);
axes(handles.axes9);
imshow(img_4);
function edit12_Callback(hObject, eventdata, handles)
% hObject ? handle to edit12 (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 edit12 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit12 as a double
% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit12 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton26.
function pushbutton26_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton26 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
ImgPath=get(handles.edit12,'String');
global img_41;
global img_4;
global img_42;
img_41=imread(ImgPath);
[m,n]=size(img_4);
? D(m,:)=0; D(:,n)=0;
else
? mm=m-double(parameter)+1;
? nn=n-double(parameter)+1;
? D(mm:m,:)=0; D(:,nn:n)=0;
end
axes(handles.axes9);
imshow(D);
img_42=uint8(idct2(D));
axes(handles.axes10);
imshow(img_42);
function edit15_Callback(hObject, eventdata, handles)
% hObject ? handle to edit15 (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 edit15 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit15 as a double
% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit15 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton31.
function pushbutton31_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton31 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_42;
ImgPath=get(handles.edit15,'String');
imwrite(img_42,ImgPath,'bmp');
function edit16_Callback(hObject, eventdata, handles)
% hObject ? handle to edit16 (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 edit16 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit16 as a double
% --- Executes during object creation, after setting all properties.
function edit16_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit16 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton32.
function pushbutton32_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton32 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
ImgPath=get(handles.edit16,'String');
global img_5;
img_5=imread(ImgPath);
axes(handles.axes11);
imshow(img_5);
function edit17_Callback(hObject, eventdata, handles)
% hObject ? handle to edit17 (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 edit17 as text
% ? ? ? str2double(get(hObject,'String')) returns contents of edit17 as a double
% --- Executes during object creation, after setting all properties.
function edit17_CreateFcn(hObject, eventdata, handles)
% hObject ? handle to edit17 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton33.
function pushbutton33_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton33 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_51;
ImgPath=get(handles.edit17,'String');
imwrite(img_51,ImgPath,'bmp');
% --- Executes on button press in pushbutton34.
function pushbutton34_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton34 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_5;
global img_51;
global img_52;
sz=size(size(img_5));
if sz(2)==3
? img_51=rgb2gray(img_5); % 如果是彩色图像,变换成灰度图像
? ?
% ? ? img_51=img_5(:,:,3);
% ? ? rgb=im2double(img_5);
% ? ? r=rgb(:,:,1);
% ? ? g=rgb(:,:,2);
% ? ? b=rgb(:,:,3);
% ? ? num=0.5*((r-g)+(r-b));
% ? ? den=sqrt((r-g).^2+(r-b).*(g-b));
% ? ? theta=acos(num./(den+eps));
% ? ? H=theta;
% ? ? H(b>g)=2*pi-H(b>g);
% ? ? H=H/(2*pi);
% ? ? num=min(min(r,g),b);
% ? ? den=r+g+b;
% ? ? den(den==0)=eps;
% ? ? S=1-3.*num./den;
% ? ? H(S==0)=0;
% ? ? img_51=uint8((H*255-176)*10);
elseif sz(2)==2
? img_51=img_5;
else
? error('Unexpected input image!');
end
% img_51=im2bw(img_51,graythresh(img_51));
% img_51=img_51>=11;
img_5tmp=double(img_51>=11);
img_51=uint8(double(img_51).*img_5tmp); % 灰度阈值小于11的都将灰度设置成0
img_52=uint8(img_51*6); % 增加动态范围
axes(handles.axes12);
imshow(img_51);
% --- Executes on button press in pushbutton39.
function pushbutton39_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton39 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_51;
gc=~img_51; % 图像求补并做距离变换
D=uint8(bwdist(gc));
img_51=255-D*6;
img_51(img_51==255)=0;
axes(handles.axes12);
imshow(img_51);
% --- Executes on button press in pushbutton40.
function pushbutton40_Callback(hObject, eventdata, handles)
% hObject ? handle to pushbutton40 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles ? structure with handles and user data (see GUIDATA)
global img_51;
img_51=imclose(imopen(img_51,ones(7,7)),ones(7,7)); % 梯度用7阶模板平滑
axes(handles.axes12);
imshow(img_51);
3 仿真结果
4 参考文献
[1]杨群. (2006). 基于直方图和小波变换的图像分割方法的研究. (Doctoral dissertation, 南昌大学).
|