필터 지우기
필터 지우기

detect square in image

조회 수: 47 (최근 30일)
Abdul
Abdul 2011년 12월 29일
댓글: Dmitry Surov 2020년 9월 16일
i want to detect square shape only in image. how can i do this using matlab?

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 29일
Hello,
Is your goal only to detect square in this picture?
If so, you don't need to do shape recognition, etc.
You just need to perform some morphologichal operations only.
I = imread('3617ca70.png');
Ibw = ~im2bw(I,graythresh(I));
Ifill = imfill(Ibw,'holes');
Iarea = bwareaopen(Ifill,100);
Ifinal = bwlabel(Iarea);
stat = regionprops(Ifinal,'boundingbox');
imshow(I); hold on;
for cnt = 1 : numel(stat)
bb = stat(cnt).BoundingBox;
rectangle('position',bb,'edgecolor','r','linewidth',2);
end
And the result :
Is this what you need?
  댓글 수: 3
An Hoang
An Hoang 2018년 4월 9일
편집: An Hoang 2018년 4월 9일
thank you so much! How to determine whether a check box option is selected
Dmitry Surov
Dmitry Surov 2020년 9월 16일
Can you please explain what do we get in stat variable ? It's something related to border line of each square, but i misunderstand what that means
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 12월 29일
Those squares are very well defined.
  • Set a less than threshold to make the dark colors true and everything else false. ( BW = I<thresh )
  • Perform a connected components analysis ( doc bwconncomp)
  • Then regionprops with EulerNumber specified.
  • Apply a threshold to the regions matching the EulerNumber ( idx = [stats(:).EulerNumber] == x ) of a sample square.
  • Build a new matrix of false. ( BWnew = false(CC.ImageSize))
  • Set the indices in the connected components analysis corresponding to the matching EulerNumber to true. ( BWnew(vertcat(CC.PixelIdxList{idx})) = true)
In theory you'll have a mask of the boxes.

Naz
Naz 2011년 12월 29일
편집: John Kelly 2013년 11월 14일
I just thought of an alternative idea. Instead of detecting a square, you should register the image (filled form) of interest with the raw image. Then, since you know the coordinates of each square, you can just check the pixels at those coordinates for the white/black values.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by