%extracting objects提取目标
im=imread('17.bmp');
I=rgb2gray(im);
im1=medfilt2(I,[2 2]); %Median filtering the image to remove noise%
BW=edge(im1,'sobel'); %finding edges
[imx,imy]=size(BW);
msk=[
1 1 1 ;
1 1 1 ;
1 1 1 ;
];
B=conv2(double(BW),double(msk)); %Smoothing image to reduce the number of connected components
L = bwlabel(B,8);% Calculating connected components
mx=max(max(L))
% There will be mx connected components.Here U can give a value between 1 and mx for L or in a loop you can extract all connected components
% If you are using the attached car image, by giving 17,18,19,22,27,28 to L you can extract the number plate completely.
[r,c] = find(L==17);
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy);
for i=2:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
figure,imshow(im);
figure,imshow(im1);
figure,imshow(BW);
I2=BW;
originalmap=I2;
%calculate every pixel's IV(Interest value)
%divide image I by w*w
w=5;%divide to m*n
m=floor(size(I2,1)/w); %rows,round
n=floor(size(I2,2)/w); %columns
%get the coordinate of every centroid
c=ceil(w/2)+(0:n-1)*w; %x coordinate
r=ceil(w/2)+(0:m-1)*w; %y coordinate
%calculate every pixel's IV
step=floor(w/2);
提取码:nhxh
© 著作权归作者所有