Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all; clear all;
- Indeks = imread('ksztalty.bmp');
- subplot(2,1,1)
- imshow(Indeks);
- Nei8 = bwlabel(Indeks,8);
- subplot(2,1,2)
- imshow(Nei8,[]);
- klasy = {'kolo';'krzyz';'kwadrat';'kwadrat';'krzyz';'kolo';'kwadrat'; 'krzyz'};
- r = regionprops(Nei8,'Centroid');
- for i=1:length(r)
- text(r(i).Centroid(1),r(i).Centroid(2),['\color{magenta}',klasy(i)]);
- end
- wsp = obliczWspolczynniki(Nei8);
- wsp(:,3)=wsp(:,3)/10;
- klasyfikator = fitcknn(wsp,klasy);
- [XX YY] = size(Nei8);
- ;
- %WYKRYWANIE KWADRATOW RMIN/RMAX
- Nei8kw = Nei8;
- for i=1:XX
- for j=1:YY
- piksel = Nei8kw(i,j);
- if piksel ~= 0 && ~(wsp(piksel,2) > 0.80 && wsp(piksel,2) < 0.84)
- Nei8kw(i,j) = 0;
- end
- end
- end
- figure
- imshow(Nei8kw,[]);
- %WYKRYWANIE KRZYZYKOW RMIN/RMAX
- Nei8krz = Nei8;
- for i=1:XX
- for j=1:YY
- piksel = Nei8krz(i,j);
- if piksel ~= 0 && ~(wsp(piksel,2) > 0.52 && wsp(piksel,2) < 0.523)
- Nei8krz(i,j) = 0;
- end
- end
- end
- figure
- imshow(Nei8krz,[]);
- %________________________________________________________%
- KsztaltyReal = imread('ksztaltyReal.bmp');
- figure
- imshow(KsztaltyReal);
- KsztaltyRealGray = rgb2gray(KsztaltyReal);
- h=fspecial('gaussian',[9 9]);
- filtr=conv2(KsztaltyRealGray,h,'same');
- filtr=uint8(filtr);
- figure;
- imhist(filtr);
- title('Histogram');
- filtr=~im2bw(filtr,76/256);
- figure;
- imshow(filtr);
- title('Po binaryzacji');
- figure;
- filtr=bwlabel(filtr,8);
- imshow(filtr,[]);klasyfikator = fitcknn(wsp,klasy);
- title('PO indeksacji');
- r = regionprops(filtr,'Centroid');
- for i=1:length(r)
- text(r(i).Centroid(1),r(i).Centroid(2),['\color{magenta}',num2str(i)]);
- end
- wsp1=obliczWspolczynniki(filtr);
- wsp1(:,3)=wsp1(:,3)/10;
- [X Y]=size(filtr);
- %WYKRYWANIE KÓŁ COMPACTNESS
- for i=1:X
- for j=1:Y
- piksel=filtr(i,j);
- if piksel ~= 0 && ~(wsp1(piksel,1) > 0.73 && wsp1(piksel,1) < 0.86)
- filtr(i,j) = 0;
- end
- end
- end
- figure
- imshow(filtr,[]);
- lista = predict(klasyfikator,wsp1)
- celldisp(lista)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement