Creating mask that take only area with specific number of pixel using convolution
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to make binary mask that take only areas with specific number of pixel,using convolution I know how to calculate number of pixels,but I cant figure out how to convolve the mask over the image and make it return only the areas within range of pixels and ignore the rest.. I tried many times, but nothing works.. I would greatly appreciate any help
0 个评论
回答(1 个)
Image Analyst
2014-12-3
Let's say you have a binary image called "binaryImage", and let's say you want to make another binary image called "mask" that is "true" only when the scanning window has 8 to 15 "true" pixels in binaryImage. So, first you'd count the number of pixels in the window, let's say the window is 5 by 5.
countImage = conv2(double(binaryImage), ones(5), 'same');
Now find pixels where the count is in the range 8 to 15, inclusive
mask = countImage >= 8 & countImage <= 15;
That's it. You're done. mask is the final resulting binary image.
2 个评论
Image Analyst
2014-12-3
Would have been nice to know that from the beginning. Advice on image processing is always better if you have an image to look at rather than guessing "blind".
You're going to have to separate them first. Either call watershed() or do repeated imerode() until they split apart.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!