Methods of Detecting and Removing Protrusions in Image

조회 수: 5 (최근 30일)
HanaHana
HanaHana 2024년 8월 13일
댓글: HanaHana 2024년 8월 16일
Is there any way to remove only the red shaded area of an image like the one below?
The data is a binary image and is binarized.
The image we are recognizing is basically a figure like the one on the left, so we can use bwareafilt to extract the maximum structure.
However, sometimes we get images like the one on the right. It does not mean that every time they are attached.
It would be best if we could set a threshold (if they are too close together, we recognize them as one), since the degree of attachment of the two objects varies.
We would appreciate it if you could let us know.
  댓글 수: 5
HanaHana
HanaHana 2024년 8월 15일
Thank you for the further detailed introduction.
I am using the following image. 
I would like to extract the following yellow parts and to erase the red and blue areas.
What I want to recognize is "approximately" an oval shape, so I want to remove the part that extends outside of the oval shape.
If it's difficult to define the blue areas, I'd like to just erase the red areas that are obviously popping up.
Catalytic
Catalytic 2024년 8월 15일
What I want to recognize is "approximately" an oval shape, so I want to remove the part that extends outside of the oval shape.
There is no unique oval shape that fits your images. You need a more well-defined criterion.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2024년 8월 15일
How about this:
% Read in image.
grayImage = imread('blobs5.jpeg');
% Convert to binary.
binaryImage = grayImage(:,:,2) > 128;
% Get rid of white stripes along the edges.
binaryImage = binaryImage(2 : end-2, 2:end-1);
subplot(2, 2, 1)
imshow(binaryImage);
title('Initial Image')
axis('on', 'image');
radius = 3;
se = strel('disk', radius, 0); % Create structuring element. Change the 3 as necessary.
binaryImage2 = imerode(binaryImage, se); % Erode the image to separate the blobs.
subplot(2, 2, 2)
imshow(binaryImage2);
binaryImage2 = bwareafilt(binaryImage2, 1, 4); % Take largest blob only.
subplot(2, 2, 3)
imshow(binaryImage2);
radius = 5;
se = strel('disk', radius, 0); % Create structuring element. Change the 5 as necessary.
binaryImage2 = imdilate(binaryImage2, se); % Regrow.
% Make sure dilated version doesn't stick out past the original.
binaryImage2 = binaryImage2 & binaryImage;
binaryImage2 = bwareafilt(binaryImage2, 1, 4); % Take largest blob only.
subplot(2, 2, 4)
imshow(binaryImage2);
axis('on', 'image');
title('Final Image')
  댓글 수: 1
HanaHana
HanaHana 2024년 8월 16일
This is exactly what I have been looking for!! Thank you from the bottom of my hearts.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt J
Matt J 2024년 8월 13일
편집: Matt J 2024년 8월 13일
Use bwlalphaclose from this FEX package,
load Image
BW2=bwareafilt( ~bwlalphaclose(~BW,15) ,1);
montage({BW,BW2},[],'Bord',[5,5],'Back','w')
  댓글 수: 2
HanaHana
HanaHana 2024년 8월 15일
Thanks for introducing me to this precious package.I will use it.
Thank you.
Matt J
Matt J 2024년 8월 15일
You're welcome, but please Accept-click the answer to indicate that it solved the problem for you.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2024년 8월 14일
Yes, you just call imerode to eat away enough layers such that the blob separates into two blobs. Then you "thicken" the image with bwmorph which will restore the two blobs to their original size but not let them merge. Then call bwareafilt to select the largest blob. Something like this (untested)
se = strel('disk', 5, 0); % Create structuring element. Change the 5 as necessary.
mask = imerode(mask, se); % Erode the image to separate the blobs.
mask = bwmorph(mask, 'thicken', inf); % Regrow without merging.
mask = bwareafilt(mask, 1); % Take largest blob only.
  댓글 수: 1
HanaHana
HanaHana 2024년 8월 15일
Thank you for your detailed and thorough explanation. I found out how to use bwmorph.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by