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
| function buttonN2s_Callback(gcf,event_data,handles) % Segmentation
handles = guidata(gcbf);
if get(handles.buttonN2s,'Value')== 1
set(handles.buttonChamp1,'Visible','on');
set(handles.buttonOk1,'Visible','on');
else
set(handles.buttonChamp1,'Visible','off');
set(handles.buttonOk1,'Visible','off');
end
N = str2num(get(handles.buttonChamp1,'String'));
TethaDegSeg=360/N;
TethaDeg=0;
for n=1:N
Tetha=(TethaDeg*pi)/180;
A=tan(Tetha);
if TethaDeg==0||TethaDeg==360
for X=(Xo+1):L
Y=A*X;
handles.input_image(Yo,X)=255;handles.input_image(Yo,(X+L))=255;handles.input_image(Yo,(X+2*L))=255;
end
elseif TethaDeg<90
if A<=1
for X=1:L
Y=A*X; Y=round(Y);
Xx=Xo+X+L;
Yx=Yo-Y;
if Yx<1||Xx>2*L
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
else
for X=1:L
Y=A*X; Y=round(Y);
Xx=Xo+X+L;
Yx=Yo-Y;
if Yx<1
for Yx=1:(Yo-round(A*(X-1))-1)
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
break;
end
if Xx>2*L
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
sup=Yx+1;
for Yx=sup:(Yo-round(A*(X-1))-1)
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
end
end
elseif TethaDeg==90
for Y=1:(Yo-1)
Y=round(Y);
handles.input_image(Yo,X)=255;handles.input_image(Yo,(X+L))=255;handles.input_image(Yo,(X+2*L))=255;
end
elseif TethaDeg<180
if A>=-1
for X=1:(Xo-1)
Y=-(A*X); Y=round(Y);
Xx=Xo-X+L;
Yx=Yo-Y;
if Yx<1||Xx<1
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
else
for X=1:(Xo-1)
Y=-(A*X); Y=round(Y);
Xx=Xo-X+L;
Yx=Yo-Y;
if Yx<1
for Yx=1:(Yo-round(-A*(X-1)-1))
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
break;
end
if Xx<1
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
sup=Yx+1;
for Yx=sup:(Yo-round(-A*(X-1)-1))
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
end
end
elseif TethaDeg==180
for X=1:(Xo-1)
handles.input_image(Yo,X)=255;handles.input_image(Yo,(X+L))=255;handles.input_image(Yo,(X+2*L))=255;
end
elseif TethaDeg<270
if A<=1
for X=1:(Xo-1)
Y=(A*X); Y=round(Y);
Xx=Xo-X+L;
Yx=Yo+Y;
if Yx>H||Xx<1
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
else
for X=1:(Xo-1)
Y=A*X; Y=round(Y);
Xx=Xo-X+L;
Yx=Yo+Y;
if Yx>H
for Yx=(Yo+round(A*(X-1)+1)):sup
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
break,
end
if Xx<1
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
sup=Yx-1;
for Yx=(Yo+round(A*(X-1)+1)):sup
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
end
end
elseif TethaDeg==270
for Y=(Yo+1):H
Y=round(Y);
handles.input_image(Yo,X)=255;handles.input_image(Yo,(X+L))=255;handles.input_image(Yo,(X+2*L))=255;
end
elseif TethaDeg<360
if A>=-1
for X=1:L
Y=-(A*X); Y=round(Y);
Xx=Xo+X+L;
Yx=Yo+Y;
if Yx>H||Xx>2*L
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
else
for X=1:L
Y=-(A*X); Y=round(Y);
Xx=Xo+X+L;
Yx=Yo+Y;
if Yx>H
for Yx=(Yo-round(A*(X-1)-1));
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
break;
end
if Xx>2*L
break;
end
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
sup=Yx-1;
for Yx=(Yo-round(A*(X-1)-1)):sup
handles.input_image(Yx,(Xx-L))=255;handles.input_image(Yx,Xx)=255;handles.input_image(Yx,(Xx+L))=255;
end
end
end
end
TethaDeg=TethaDegSeg+TethaDeg;
end
imshow(handles.input_image);
guidata(gcbf, handles);
function buttonOpen_Callback(hObject, event_data, handles)
handles = guidata(gcbf);
[FileName, PathName] = uigetfile('*.bmp','Selection file');
handles.input_image = imread(fullfile(PathName, FileName));
guidata(gcbf, handles);
function buttonC2g_Callback(gcf,eventdata,handles) % Centre de gravité
handles = guidata(gcbf);
compt = 0;
vecX = 0;
vecY = 0;
[H,L] = size(handles.input_image);
L=L/3;
for Y=1:H
for X=1:L
if handles.input_image(Y,X)==255&&handles.input_image(Y,(X+L))==0&&handles.input_image(Y,(X+2*L))==0
compt = compt+1;
vecY(compt) = Y;
vecX(compt) = X;
end
end
end
Yo = round(mean(vecY));
Xo = round(mean(vecX));
handles.input_image(Yo,(Xo+L))=255;
guidata(gcbf, handles);
imshow(handles.input_image); |
Partager