MATLAB: Getting rid of noise

bwlabelfilterimageImage Processing Toolboxnoiseregionprops

So I have the image that I have attached. I am trying to count the objects in the image (The black rectangle) but matlab is picking up the other object (noise). I have tried few filters but I haven't been able to get rid of it. I was wondering if someone had a better idea.
Capture.PNG

Best Answer

Actually I figured it out. I just inverted it using imcompliment. Then used bwareaopen to pull all the noise away then inverted it back. It may sound stupid but it works.