How can I remove objects that fit within a certain circular radius?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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');
0 comentarios
Respuestas (2)
nick
el 30 de Jul. de 2024
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!
0 comentarios
Abhas
el 30 de Jul. de 2024
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:
- Binarization: Convert the image to a binary format using adaptive thresholding to highlight the vasculature.
- Morphological Operations: Apply operations like morphological closing and hole filling to create a continuous representation of the vasculature.
- Object Removal: Use morphological opening with a disk-shaped structuring element to remove small circular objects that are not part of the vasculature.
- 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:
- Binarize 2-D grayscale image: https://www.mathworks.com/help/images/ref/imbinarize.html
- Remove small objects from binary image: https://www.mathworks.com/help/images/ref/bwareaopen.html
- Morphologically close image: https://www.mathworks.com/help/images/ref/imclose.html
- Morphological structuring element: https://www.mathworks.com/help/images/ref/strel.html
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!