フィルターのクリア

How to choose only the region with the specified height and width?

1 回表示 (過去 30 日間)
ezhil K
ezhil K 2019 年 1 月 19 日
編集済み: ezhil K 2019 年 1 月 21 日
I have applied connected component analysis on a car image.Now, I need to reduce the number of components by specifying the height and width of the license plate characters in a vehicle,so that only those region will be displayed and rest of them are discarded.Can anyone help me in doing the same?

回答 (1 件)

Image Analyst
Image Analyst 2019 年 1 月 19 日
See attached utility to get the bounding box of all the bounding boxes. Then, after you've used that to get the overall bounding box, use imcrop()
croppedImage = imcrop(originalImage, overallBoundingBox);
  2 件のコメント
ezhil K
ezhil K 2019 年 1 月 20 日
actually I have used connected component algorithm to get all the connected components in a car image.now I'm in need of extracting only the region with the specified height and width as same as height of the number plate character.So how should I use the code you provided.I could'nt understand it's implementation.Can you please help me in understanding and implementing it in my image?I have attached my CCA code here.I have also attached my input image to this function.Please help me in doing so.Screenshot (9).png
function img=cca(im)
% k indicates number of components in binary image
k = 0;
global B;
img=imbinarize(im,0.5);
B = zeros(size(img,1),size(img,2));
% to make sure boundary conditions, skip first row, column and last row,
% column. These will be taken care by recursive function calls later
for i = 2 : size(img,1) - 1
for j = 2 : size(img,2) - 1
if img(i,j) == 1 && B(i,j) == 0
k = k + 1;
rcca(i,j,img,k);
end
end
end
for i = 1 : size(img,1)
if img(i,1) == 1 && B(i,1) == 0
k = k + 1;
B(i,1) = k;
else
if img(i,size(img,2)) == 1 && B(i,size(img,2)) == 0
k = k + 1;
B(i,size(img,2)) = k;
end
end
end
for j = 1 : size(img,2)
if img(1,j) == 1 && B(1,j) == 0
k = k + 1;
B(1,j) = k;
else
if img(size(img,1),j) == 1 && B(size(img,1),j) == 0
k = k + 1;
B(size(img,1),j) = k;
end
end
end
%figure,imshow(img);
fprintf('\ntotal number of components in image = %.0f\n',k);
function rcca(x,y,A,k)
global B;
A=imresize(A, 0.5);
B(x,y) = k;
% dx and dy is used to check for 8 - neighbourhood connectivity
dx = [-1,0,1,1,1,0,-1,-1];
dy = [1,1,1,0,-1,-1,-1,0];
if x > 1 && y > 1 && x < size(A,1) && y < size(A,2)
for i = 1 : 8
nx = x + dx(i);
ny = y + dy(i);
if A(nx,ny) == 1 && B(nx,ny) == 0
rcca(nx,ny,A,k);
end
end
end
ezhil K
ezhil K 2019 年 1 月 21 日
編集済み: ezhil K 2019 年 1 月 21 日
I have used the code you provided above.But, I don't get any output.I have attached the code and the input image to it.Can you please help me in rectifying my mistakes?
img=imread('test.png');
BW=im2bw(img);
st = regionprops(BW, 'BoundingBox');
figure, imshow(img);
hold on;
[xMin,xMax,yMin,yMax]=BoundingBoxFromRegionProps(st,1);
croppedImage = imcrop(img,[xMin,xMax,yMin,yMax]);
figure,imshow(croppedImage);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by