Creating mask that take only area with specific number of pixel using convolution

3 ビュー (過去 30 日間)
Reema
Reema 2014 年 12 月 2 日
コメント済み: Image Analyst 2014 年 12 月 3 日
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

回答 (1 件)

Image Analyst
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 件のコメント
Reema
Reema 2014 年 12 月 3 日
Thanks for your answer, I really appreciate it, but it didn't give me the result I expected, the image I'm working on include connected objects, I want to create mask to extract the smallest objects on each end,as in the attached image
Image Analyst
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!

Translated by