How can I remove objects that fit within a certain circular radius?

6 ビュー (過去 30 日間)
Sanjana
Sanjana 2024 年 7 月 30 日
回答済み: Abhas 2024 年 7 月 30 日
I am currently trying to create a mask of an image to only capture certain vasculature in an image. I have created a mask that uses a specific sensitivity value to only get the darker areas (which would represent the blood vessels), but I am also picking up smaller circle-like areas that do not represent that vasculature. Is there a way for me to detect if certain white areas are within a circular radius and then delete them? Here is my code so far:
binarizedImage1 = imbinarize(repairedImage1, 'adaptive', 'Sensitivity', 0.8);
binarizedImage1 = ~binarizedImage1;
imshow(binarizedImage1)
BWao = bwareaopen(binarizedImage1, 500);
nhood = ones(3);
closeBWao = imclose(BWao,nhood);
mask = imfill(closeBWao,'holes');

回答 (2 件)

nick
nick 2024 年 7 月 30 日
Hi Sanjana,
I understand that you would like to remove the smaller circles in the given image.
The smaller circles in the image can be removed using morpholological opening with the "imopen" function. The morphological structuring element used can be a disk with a certain radius using "strel" function. This process performs morphological opening to remove small white areas within the specified radius.
You may refer to the following documentation to learn more about "imopen":
Hope this helps!

Abhas
Abhas 2024 年 7 月 30 日
Hi Sanjana,
To create a mask that captures only the vasculature in an image while excluding smaller circular areas that do not represent the blood vessels, you can follow a series of image processing steps. The process involves adaptive thresholding to binarize the image, morphological operations to refine the mask, and specific steps to remove small circular objects. The key steps include:
  1. Binarization: Convert the image to a binary format using adaptive thresholding to highlight the vasculature.
  2. Morphological Operations: Apply operations like morphological closing and hole filling to create a continuous representation of the vasculature.
  3. Object Removal: Use morphological opening with a disk-shaped structuring element to remove small circular objects that are not part of the vasculature.
  4. Final Mask Inversion: Invert the final mask to ensure the vasculature is highlighted in white and the background is black.
Here's the MATLAB code to perform the required steps:
I = imread('repairedImage1.jpg');
% Binarize the image using adaptive thresholding
binarizedImage1 = imbinarize(I, 'adaptive', 'Sensitivity', 0.8);
% Invert the binary image
binarizedImage1 = ~binarizedImage1;
% Ensure the image is 2D logical
binarizedImage1 = logical(binarizedImage1(:,:,1));
% Display the binarized image
imshow(binarizedImage1);
% Remove small objects from binary image
BWao = bwareaopen(binarizedImage1, 500);
% Create a structuring element
nhood = ones(3);
% Perform morphological closing
closeBWao = imclose(BWao, nhood);
% Fill holes in the binary image
mask = imfill(closeBWao, 'holes');
% Ensure the mask is 2D logical
mask = logical(mask(:,:,1));
% Set the radius for the circular objects you want to remove
radius = 10;
% Create a disk-shaped structuring element
se = strel('disk', radius);
% Perform morphological opening to remove small objects
openedMask = imopen(mask, se);
% Ensure the opened mask is 2D logical
openedMask = logical(openedMask(:,:,1));
% Invert the final mask to reverse the colors
finalMask = ~openedMask;
% Display the final result
imshow(finalMask);
OUTPUT:
You may refer to the following MathWorks documentation links to have a better understanding on binarization and morphological closing:
  1. Binarize 2-D grayscale image: https://www.mathworks.com/help/images/ref/imbinarize.html
  2. Remove small objects from binary image: https://www.mathworks.com/help/images/ref/bwareaopen.html
  3. Morphologically close image: https://www.mathworks.com/help/images/ref/imclose.html
  4. Morphological structuring element: https://www.mathworks.com/help/images/ref/strel.html

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by