image - Weird behaviour of bwareafilt in MATLAB and what algorithm does it use? -


i have following questions:

  1. what algorithm bwareafilt uses?

  2. weird behaviour: when input matrix totally black, following error

    error using bwpropfilt (line 73) internal error: p must positive. error in bwareafilt (line 33) bw2 = bwpropfilt(bw, 'area', p, direction, conn); error in colour_reception (line 95) iz=bwareafilt(b,1); 

    actually, using function take snapshots webcam, when block webcam totally, above following error.


so believe error due internal implementation mistake. case? how overcome this?

let's answer questions 1 @ time:

what algorithm bwareafilt use?

bwareafilt function image processing toolbox accepts binary image , determines unique objects in image. find unique objects, connected components analysis performed each object assigned unique id. can think of performing flood fill on each object individually. flood fill can performed using variety of algorithms - among them depth-first search can consider image graph edges connected each pixel. flood fill in case visits of pixels connected each other until don't have more pixels visit , localized within object. proceed next object , repeat same algorithm until run out of objects.

after, determines "area" each object counting how many pixels belong object. once determine area each object, can either output image retains top n objects or filter image objects within range of areas retained.

given code above, trying output image largest object in binary image. therefore, using former, not latter n=1.

weird behaviour bwareafilt

given above description of bwareafilt , intended application:

actually, using function take snapshots webcam, when block webcam totally, above following error.

... error self-explanatory. when cover webcam, entire frame black , there no objects found in image. because there no objects in image, returning object largest area makes no sense because there no objects return begin with. that's why getting error because trying make bwareafilt return image largest object there aren't objects in image begin with.

as such, if want use bwareafilt, suggest check see if entire image black first. if isn't black, go ahead , use bwareafilt. if is, skip it.

do this, assuming b image you're trying process:

if any(b(:))     iz = bwareafilt(b, 1); else     iz = b; end 

the above code uses any check see if there white pixels in image b non-zero. if there are, bwareafilt should appropriately called. if there aren't white pixels in image, set output b (which dark image anyway).


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -