how to remove object that contain more than X% black pixels

조회 수: 1 (최근 30일)
Lukasz Jarod
Lukasz Jarod 2014년 12월 26일
댓글: Image Analyst 2014년 12월 27일
i have some roi and i want to remove roi that has more then 90% black pixels how can i do that???

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 26일
편집: Image Analyst 2014년 12월 26일
Is your ROI in the form of a binary image? Are there multiple regions in that binary image? Just call regionprops and find blobs where the (FilledArea - Area) / FilledArea > 0.1.
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'FilledArea', 'Area');
allAreas = [measurements.Area];
allFilledAreas = [measurements.FilledArea];
darkRatios = (allFilledAreas - allAreas) / allFilledAreas;
darkIndexes = find(darkRatios > 0.1);
newLabeledImage = ismember(labeledImage, darkIndexes);
% Relabel
labeledImage = bwlabel(newLabeledImage > 0);
% Measure again with new blobs.
measurements = regionprops(labeledImage, 'FilledArea', 'Area');
  댓글 수: 3
Lukasz Jarod
Lukasz Jarod 2014년 12월 27일
편집: Lukasz Jarod 2014년 12월 27일
well i dont understand what you doing in this code;/
http://i58.tinypic.com/amze38.jpg for example i have this image then for each labeled componetnt i do template matching but first i remove some of the object. and now i want to remove somehow boject on the left(as you can see object is almost 90% filld with black pixels and there is no letters that are 90% filled with black) maybe you could tell me step by step what hapens in your code , or it will not work for me now? or maybe there is another way to do it?
Image Analyst
Image Analyst 2014년 12월 27일
It's only 9 lines of code, that do what you asked for.
If you really wanted OCR instead, then you should have said so initially and posted your image.

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

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by