【瑕疵检测】基于Otsu实现织物疵点检测matlab源码含 GUI
2022/1/16 22:03:38
本文主要是介绍【瑕疵检测】基于Otsu实现织物疵点检测matlab源码含 GUI,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、简介
模型参考这里。
二、源代码
%本程序可以完成布匹疵点检测且本程序是批处理程序。 function varargout = FabricGui(varargin) 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 % --- Executes just before FabricGui is made visible. function FabricGui_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; % Update handles structure guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = FabricGui_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function hedit_detect_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_detect_CreateFcn(hObject, eventdata, handles) 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) %批处理 srcDir=uigetdir('Choose source directory.'); %获得选择的文件夹 cd(srcDir); allnames=struct2cell(dir('*.bmp')); %只处理8位的bmp文件 [k,len]=size(allnames); %获得bmp文件的个数 %得到设置的参数 P=str2num(get(handles.hedit_zhouqi,'string')); %获得织物纹理周期 T1=str2num(get(handles.hedit_yuzhifenge,'string')); %分割阈值 T2=str2num(get(handles.hedit_yuzhihou,'string')); %后处理阈值 numwu=0;numyou=0; for ii=1:len %逐次取出文件 cd(srcDir); name=allnames{1,ii}; I=imread(name); %读取文件 axes(handles.hyuanshiaxes); %显示图像 imshow(I); cd('..'); 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'); %进行二值化及其后处理 T=Otsu(I); % --- Executes on button press in ptnExit. function ptnExit_Callback(hObject, eventdata, handles) % hObject handle to ptnExit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) delete(handles.MainFig); function hedit_zhouqi_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_zhouqi_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function hedit_yuzhifenge_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_yuzhifenge_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function hedit_yuzhihou_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_yuzhihou_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function hedit_you_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_you_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function hedit_wu_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. function hedit_wu_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function J=junzhicaiyang(I,M,N,a) k=1;h=1;temp=0; %均值下采样,用于削弱图像周期纹理 for i=1:a:M-a+1 for j=1:a:N-a+1 %每一个小块的均值作为新的图像像素值 temp=0; for m=i:1:i+a-1 for n=j:1:j+a-1 temp=temp+I(m,n); end end J(h,k)=temp/(a*a); %计算均值,作为新的图像像素值 k=k+1; end
三、运行结果
四、参考文献
[1]步红刚, 黄秀宝, 汪军. 基于多分形特征参数的织物瑕疵检测[J]. 计算机工程与应用, 2007, 43(036):233-237.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
这篇关于【瑕疵检测】基于Otsu实现织物疵点检测matlab源码含 GUI的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南