필터 지우기
필터 지우기

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 CenterFile Exchange에서 Geometric 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