function varargout = Processing(varargin)
% PROCESSING MATLAB code for Processing.fig
% PROCESSING, by itself, creates a new PROCESSING or raises the existing
% singleton*.
%
% H = PROCESSING returns the handle to a new PROCESSING or the handle to
% the existing singleton*.
%
% PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROCESSING.M with the given input arguments.
%
% PROCESSING('Property','Value',...) creates a new PROCESSING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Processing_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Processing_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 Processing
% Last Modified by GUIDE v2.5 22-May-2021 22:54:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Processing_OpeningFcn, ...
'gui_OutputFcn', @Processing_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 Processing is made visible.
function Processing_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 Processing (see VARARGIN)
% Choose default command line output for Processing
handles.output = hObject;
setappdata(handles.Processing,'X',0);
setappdata(handles.Processing,'bw',0);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Processing wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Processing_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;
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (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 pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (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 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)
% --- 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 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)
% --- 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)
% --- Executes on button press in InputImage.
function InputImage_Callback(hObject, eventdata, handles)
% hObject handle to InputImage (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';'*.*'},'载入图像');
file=[pathname,filename];
% global S %设置一个全局变量S,保存初始图像路径,以便之后的还原操作
% S=file;
X=imread(file);
set(handles.imageshow1,'HandleVisibility','ON');
axes(handles.imageshow1);
imshow(X);
handles.img=X;
guidata(hObject,handles);
setappdata(handles.Processing,'X',X);
% --- 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)
% --- Executes during object creation, after setting all properties.
function imageshow1_CreateFcn(hObject, eventdata, handles)
% hObject handle to imageshow1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% global fname fpath see
% [fname,fpath]=uigetfile('*.*','打开');
% see=[fpath fname];
% I=imread(see);
% axes(handles.axes1);
% imshow(I,'notruesize');
% title('原始图片');
function B=boundaries(BW,conn,dir)
% 函数输入
% BW:二值图像矩阵%
% conn:4或8
% 返回二值图像中连通区域的边缘像素的坐标
if nargin<3 %nargin定义在用户自定义函数体内,nargin返回
%用来调用函数的变量的个数。
dir='cw';
end
if nargin<2
conn=8;
end
L=bwlabel(BW,conn); %返回值是矩阵L,大小同BW,包含了BW中的连通部分的标记
% 初始化结果矩阵B
numObjects=max(L(:));%寻找L中所作标记中的最大值,这个最大值实际上就对应着L中
% 包含的最多的连通部分的数目。
if numObjects>0
B={zeros(0,2)};%元包数组中仅包含一个元素。
B=repmat(B,numObjects,1);%将B进行numObjects*1个复制构成新的B。
else
B={};
end
%在图像边界补充0值像素
Lp=padarray(L,[1 1],0,'both');
%在方向和引索坐标间建立关系
M=size(Lp,1);%SIZE(X,1) returns the number of rows.
if conn==8
%Order is N NE E SE S SW W NW.
offsets=[-1,M-1,M,M+1,1,-M+1,-M,-M-1];
else
%Order is N E S W.
offsets=[-1,M,1,-M];
end
% 搜索方向的起始方向
if conn==8
next_search_direction_lut=[8 8 2 2 4 4 6 6];
else
next_search_direction_lut=[4 1 2 3];
end
%下一个访问节点
if conn==8
next_direction_lut=[2 3 4 5 6 7 8 1];
else
next_direction_lut=[2 3 4 1];
end
START=-1;
BOUNDARY=-2;
scratch=zeros(100,1);
%Find candidate starting locations for boundaries.
[rr,cc]=find((Lp(2:end-1,:)>0)&(Lp(1:end-2,:)==0));
rr=rr+1;
for k=1:length(rr)
r=rr(k);
c=cc(k);
if (Lp(r,c)>0)&(Lp(r-1,c)==0)&isempty(B{Lp(r,c)})
%We've found the start of the next boundary.Compute its linear
%offset,record which boundary it is,mark it,and initialize the
%counter for the number of boundary pixels.
idx=(c-1)*size(Lp,1)+r;
which=Lp(idx);
scratch(1)=idx;
Lp(idx)=START;
numpixels=1;
currentpixel=idx;
initial_departure_direction=[];
done=0;
next_search_direction=2;
while ~done
%Find the next boundary pixel.
direction=next_search_direction;
found_next_pixel=0;
for k=1:length(offsets)
neighbor=currentpixel+offsets(direction);
if Lp(neighbor)~=0
%Found the next boundary pixel.
if (Lp(currentpixel)==START)&...
isempty(initial_departure_direction)
%We are making the initial departure from the starting
%pixel.
initial_departure_direction=direction;
elseif (Lp(currentpixel)==START)&...
(initial_departure_direction==direction)
% We are about to retrace our path.
%That means we're done.
done=1;
found_next_pixel=1;
break;
end
%Take the next step along the boundary.
next_search_direction=...
next_search_direction_lut(direction);
found_next_pixel=1;
numpixels=numpixels+1;
if numpixels>size(scratch,1)
%Double the scratch space.
scratch(2*size(scratch,1))=0;
end
scratch(numpixels)=neighbor;
if Lp(neighbor)~=START
Lp(neighbor)=BOUNDARY;
end
currentpixel=neighbor;
break;
end
direction=next_direction_lut(direction);
end
if ~found_next_pixel
%If there is no next neighbor,the object must just have a
%single pixel.
numpixels=2;
scratch(2)=scratch(1);
done=1;
end
end
%Convert linear indices to row_column coordinates and save in the
%output cell array.
[row,col]=ind2sub(size(Lp),scratch(1:numpixels));
B{which}=[row-1,col-1];
end
end
if strcmp(dir,'ccw')
for k=1:length(B)
B{k}=B{k}(end:-1:1,:);
end
end
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.
- 245.
- 246.
- 247.
- 248.
- 249.
- 250.
- 251.
- 252.
- 253.
- 254.
- 255.
- 256.
- 257.
- 258.
- 259.
- 260.
- 261.
- 262.
- 263.
- 264.
- 265.
- 266.
- 267.
- 268.
- 269.
- 270.
- 271.
- 272.
- 273.
- 274.
- 275.
- 276.
- 277.
- 278.
- 279.
- 280.
- 281.
- 282.
- 283.
- 284.
- 285.
- 286.
- 287.
- 288.
- 289.
- 290.
- 291.
- 292.
- 293.
- 294.
- 295.
- 296.