필터 지우기
필터 지우기

remove pixel and height that doesnt meet certain criteria

조회 수: 1 (최근 30일)
Tulips
Tulips 2012년 11월 6일
hi sir, in my color detection, I used ismember to set object between pixel 100 and 500. Its worked. however, can I know from the bounding box of object detection, how to remove bounding of blobs that doesnt meet height and width criteria ,say width and height of 100x100 pixels?

채택된 답변

Image Analyst
Image Analyst 2012년 11월 6일
편집: Image Analyst 2012년 11월 6일
Sure, you just get all the bounding boxes
allBB = [blobMeasurements.BoundingBox];
Then extract every 4th one for the widths and heights.
allWidths = allBB(3:4:end);
allHeights = allBB(4:4:end);
Then use ismember just like you did to filter based on area. You'd do something like this:
% Get a list of the blobs that meet our criteria and we need to keep.
allowableWidthIndexes = (allWidths > 150) & (allWidths < 220);
allowableHeightIndexes = allHeights < 2000; % Take the small objects.
keeperIndexes = find(allowableWidthIndexes & allowableHeightIndexes );
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
You can then relabel keeperBlobsImage and call regionprops on keeperBlobsImage if you want to measure only the keeper blobs.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 11월 6일
minwidth = 100; maxwidth = 100; %as far as I can tell from your question
minheight = 100; maxheight = 100; %as far as I can tell from your question
rinfo = regionprops(YourLabeledImage, 'BoundingBox');
bb = [rinfo.BoundingBox];
bbmatches = bb(4) >= minheight & bb(4) <= maxheight & bb(3) >= minwidth & bb(3) >= maxwidth;
Now bbmatches would be a logical array and you can do things like
rinfo(bbmatches)
to select just the relevant boxes.
  댓글 수: 7
Tulips
Tulips 2012년 11월 6일
I mean, using the ismember values to plot using rectangle.is that possible?
Image Analyst
Image Analyst 2012년 11월 6일
No. ismember() returns a labeled image, not bounding box coordinates. You'd need to either pick out selectively the bounding boxes that meet your criteria from your measurements (what regionprops returned the first time), or, probably easier, just relabel and call regionprops again. It's regionprops() that returns bounding box coordinates, not ismember().

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

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by