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
| function [RgbPlat]=LocatPlat(RGBimage,NumColor)
global ax1 ax2
%%
RgbPlat=[];
plat=RGBimage;
%imshow(plat,'Parent',ax1)
%%
[X_no_dither,map]= rgb2ind(plat,NumColor,'nodither');
%imshow(X_no_dither,map,'Parent',ax1)
%% rgb yellow filter
r=map(:,1)>0.5;
g=map(:,2)>0.3;
b=map(:,3)<0.31;
y=r.*g.*b;
locy=find(y);
by=roicolor(X_no_dither, locy-1);
%imshow(by,'Parent',ax1)
%% noise filter
noise1=bwareaopen(by,200);
%imshow(noise1,'Parent',ax1)
cc = bwconncomp(noise1, 26);
if cc.NumObjects==0
return
end
%%
SE = strel('square',7);
yellow=imdilate(by ,SE);
RGBfill=imfill(yellow,'holes');
%imshow(RGBfill,'Parent',ax1)
%% noise filter
rgb=bwareaopen(RGBfill,2000);
%imshow(rgb,'Parent',ax1)
%% shape filter
%%
SE = strel('square',1);
yellow=imdilate(rgb ,SE);
yellowclear=yellow;
% yellowclear=imclearborder(yellow);
%imshow(yellowclear,'Parent',ax1)
%%
W=regionprops(yellowclear);
cc = bwconncomp(yellowclear, 26);
%%
NumberObj=size(W);
box=cell(1,NumberObj(1));
for n=1:NumberObj(1)
box{n}.width=W(n).BoundingBox(3);
box{n}.high=W(n).BoundingBox(4);
box{n}.z=box{n}.width/box{n}.high;
end
%% Test - the higth/Width proportion test
word = false(size(yellow));
for n=1:cc.NumObjects
allowed=box{n}.z>1.67&&box{n}.z<6.7;
word(cc.PixelIdxList{n}) = allowed;
hold on;
imshow(word,'Parent',ax1)
end
%% delete the image thet are smaller to see the number
noise2=bwareaopen(word,4300);
imshow(noise2,'Parent',ax1)
%%
imgplat=getimage(ax1);
cc = bwconncomp(imgplat, 26);
W=regionprops(imgplat);
%% test the fill Area Test
%% the biggest size Test
if cc. NumObjects>1
word = false(size(yellow));
areas=[W.Area];
Sper=zeros(1,cc.NumObjects);
for n=1:cc.NumObjects
Sper(n)= W(n).Area/(W(n).BoundingBox(3)*W(n).BoundingBox(4));
end
if abs(min(Sper)-max(Sper))>0.07
for n=1:cc.NumObjects
allowed=Sper(n)==max(Sper);
word(cc.PixelIdxList{n}) = allowed;
hold on;
imshow(word,'Parent',ax1)
end
else
for n=1:cc.NumObjects
allowed=W(n).Area==max(areas);
word(cc.PixelIdxList{n}) = allowed;
hold on;
imshow(word,'Parent',ax1)
end
end
elseif cc. NumObjects==0
return
end
%%
img=getimage(ax1);
W=regionprops(img);
rect=W.BoundingBox;
rect=rect+[0 -15 -5 15];
RgbPlat=imcrop(plat,rect);
imshow(RgbPlat,'Parent',ax2) %put % here for beter prefrmence
pause(1) %put % here for beter prefrmence
end |
Partager