MATLAB: How can i remove object bigger than x pixel

image procesingImage Processing Toolbox

i know that bwareaopen remove small elements , but how can i remove object bigger than x pixels???
i want to just the letter to stay so how can i remove that 2 big objects???

Best Answer

Hi Lukasz,
Here's an example that removes all objects greater than 1000 pixels in area. You probably have your own BW image and your own threshold that you can use in a similar way.
I = imread('rice.png');
BW = I>80;
cc = bwconncomp(BW);
stats = regionprops(cc);
threshold = 1000;
removeMask = [stats.Area]>threshold;
BW(cat(1,cc.PixelIdxList{removeMask})) = false;
Did this help you out?
Thanks, Sven.