%本程序可以完成布匹疵点检测和识别,并保存检测和识别结果,且本程序是批处理程序。
%可以完成布匹图像批量检测和识别
function varargout = FabricGui(varargin)
% FABRICGUI M-file for FabricGui.fig
% FABRICGUI, by itself, creates a new FABRICGUI or raises the existing
% singleton*.
%
% H = FABRICGUI returns the handle to a new FABRICGUI or the handle to
% the existing singleton*.
%
% FABRICGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FABRICGUI.M with the given input arguments.
%
% FABRICGUI('Property','Value',...) creates a new FABRICGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FabricGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FabricGui_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 FabricGui
% Last Modified by GUIDE v2.5 24-Nov-2010 16:44:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FabricGui_OpeningFcn, ...
'gui_OutputFcn', @FabricGui_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 FabricGui is made visible.
function FabricGui_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 FabricGui (see VARARGIN)
movegui(handles.MainFig,'center');
global global_pause global_stop
global_pause=0;
global_stop=0;
% Choose default command line output for FabricGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FabricGui wait for user response (see UIRESUME)
% uiwait(handles.MainFig);
% --- Outputs from this function are returned to the command line.
function varargout = FabricGui_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 hedit_fenlei_Callback(hObject, eventdata, handles)
% hObject handle to hedit_fenlei (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 hedit_fenlei as text
% str2double(get(hObject,'String')) returns contents of hedit_fenlei as a double
% --- Executes during object creation, after setting all properties.
function hedit_fenlei_CreateFcn(hObject, eventdata, handles)
% hObject handle to hedit_fenlei (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 ptnRun.
function ptnRun_Callback(hObject, eventdata, handles)
% hObject handle to ptnRun (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%批处理
srcDir=uigetdir('Choose source directory.'); %获得选择的文件夹
cd(srcDir);
allnames=struct2cell(dir('*.bmp')); %只处理8位的bmp文件
[k,len]=size(allnames); %获得bmp文件的个数
global number;
number=len;
data0=get(handles.htable_xianshi,'data');
handles.data0=data0;
numwu=0;numjing=0;numwei=0;numqu=0;numan=0;numliang=0;
global global_pause global_stop
set(handles.ptnRun,'enable','off');
for ii=1:len
%完成系统运行暂停和终止功能
if global_stop
set(handles.ptnRun,'enable','on');
set(handles.hedit_fenlei,'string','终止');
break
end
if global_pause
set(handles.hedit_fenlei,'string','暂停');
while 1
pause(0.1);
if ~global_pause
break
end
end
end
%得到设置的参数
P=get(handles.hedit_zhouqi,'UserData'); %获得织物纹理周期
T1=get(handles.hedit_yuzhifenge,'UserData'); %分割阈值
T2=get(handles.hedit_yuzhihou,'UserData'); %后处理阈值
E1=get(handles.hedit_erode1,'UserData'); %区域类腐蚀宽度
E2=get(handles.hedit_erode2,'UserData'); %非区域类腐蚀宽度
B=get(handles.hedit_bi,'UserData'); %长短轴之比
An=get(handles.hedit_jiaodu,'UserData'); %主轴倾斜度
H=get(handles.hedit_junzhi,'UserData'); %灰度平均值
%逐次取出文件
name=allnames{1,ii};
I=imread(name); %读取文件
axes(handles.hyuanshiaxes); %显示图像
imshow(I);
set(gcf,'NextPlot','add');
set(handles.hyuanshiaxes,'UserData',I);
set(gcf,'Pointer','arrow');
I0=I;
%预处理
I=double(I0); %数据类型的转换
[M,N]=size(I);%得到待检测图像的大小
J=junzhicaiyang(I,M,N,P); %调用均值下采样函数
J=uint8(J);
%双线性插值,恢复原来的图像大小
I1=imresize(J,P,'bilinear'); %双线性插值,恢复原来图像的大小。
%进行方差下采样,用于增强图像疵点信息
I1=double(I1);
J1=fangchacaiyang(I1,M,N,P); %调用方差下采样函数
J1=uint8(J1);
%双线性插值,恢复原来图像的大小。
I=imresize(J1,P,'bilinear');
% 显示预处理后图像
axes(handles.hyuchuliaxes);
set(handles.htext_name,'string','预处理后图像');
imshow(I);
set(gcf,'NextPlot','add');
%进行二值化及其后处理
T=Otsu(I);
%解决了利用大津法不能分辨是否含有疵点的缺陷的缺点,统计发现无疵点图像otsu得到阈值均小于8
if T<=T1
T=T1+1;
end
I=im2bw(I,T/255); %调用自己编写的Otsu大津法进行二值化操作
Ibw=imfill(I,'holes'); %填充空洞,特别是对于油污破洞等区域类缺陷来说是必要的
%去掉小面积的值
Ibw=bwareaopen(Ibw,T2); %这也是一个可调节的参数
%第一次进行特征提取用于分类的运算。
I=Ibw;
L1=bwlabel(I,8);
stats1=regionprops(L1);
BP=zeros(4,1);%定义的用于神经网络进行识别的输入向量
Num1=length(stats1);
if (Num1<=0)
BP(1)=0;BP(2)=0;BP(3)=0;BP(4)=0;
axes(handles.hyuchuliaxes);
set(handles.htext_name,'string','分割后处理图像');
imshow(I);
set(gcf,'NextPlot','add');
axes(handles.hyuchuliaxes);
set(handles.htext_name,'string','疵点标记图像');
imshow(I);
set(gcf,'NextPlot','add');
Ifinal=I;
stats(1).Area=0;stats(1).MajorAxisLength=0;stats(1).MinorAxisLength=0;
Q=0;P=0;temp(1)=0;temp(2)=0;
numwu=numwu+1;
else
BP(1)=1;
for i=1:Num1
A(i)=stats1(i).Area;
%调用不同连通区域相连接的程序,将多个连通区域变为一个连通区域
%用于经向类和纬向类的疵点,解决了分割不完全的问题
if (((i+1)<=Num1) & (Num1>1)) %连通个数大于一,且不超过总的连通个数
ax=stats1(i).Centroid(1);
ay=stats1(i).Centroid(2);
bx=stats1(i+1).Centroid(1);
by=stats1(i+1).Centroid(2);
I=liantonglianjie1(I,ax,bx,ay,by);
end
Fabric-defect-detection-.rar_Gabor fabric_defect_matlab疵点检测_织物检测
版权申诉
5星 · 超过95%的资源 63 浏览量
2022-07-14
21:51:43
上传
评论
收藏 824KB RAR 举报
四散
- 粉丝: 51
- 资源: 1万+
最新资源
- 计算最佳快递运费.xlsx
- 20221230IqFQX3Yc.zip
- Microsoft.AspNetCore.Authentication.JwtBearer 3.1.32
- picCombobox图片下拉菜单案例.xls
- Java语言实现使用Prim(普利姆)算法求最小生成树(源代码)
- grex 既是一个库也是一个命令行工具,它可以自动从用户提供的测试用例生成单个正则表达式
- 奕尧笔记 yiyao-notebook-evv Setup 3.1.6.exe
- 继保实验模版 实验一 三段式电流保护及自动重合闸 实验二 变压器差动保护 实验三 微机型距离保护实验
- web前端页面通过BrowserPrint API连接斑马打印机进行RFID条形码贴纸打印
- 导体、导线、各种电缆载流量表
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈