Hello,
I am trying to lear how I can remove the small objects to find the main area of the image (the black section between the long lines (edges)? I want ot get rid of external and internal objects.
Thanks for the helps
Capture.PNG

 Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 6 Dez. 2019

0 Stimmen

#Approximate Here
se = strel('line',3,3);
BW1=imdilate(binaryImage,se);
BW2=bwareafilt(~BW1,1);
se = strel('line',3,3);
BW3=imerode(BW2,se);
se=strel('disk',7);
result=imclose(BW3,se);
imshow(result);
ui.png

8 Kommentare

Thanks KALYAN. I have binarized the image using imbinarize(I) and continued with your pirce of code. However I am getting an error message. If I dont binarize it I am getting pretty similar error which is related to the second strel command. Am I missing something?error.PNG
KALYAN ACHARJYA
KALYAN ACHARJYA am 6 Dez. 2019
Which Matlab version you are using?
Very Determined
Very Determined am 6 Dez. 2019
I am using R2019a.
KALYAN ACHARJYA
KALYAN ACHARJYA am 6 Dez. 2019
I didnot get any error, when I tried with the attach image. Also shown the result.
KALYAN ACHARJYA
KALYAN ACHARJYA am 6 Dez. 2019
Bearbeitet: KALYAN ACHARJYA am 6 Dez. 2019
Have you confirmed that the passing binaryImage data is binary image?
Very Determined
Very Determined am 6 Dez. 2019
Bearbeitet: Very Determined am 6 Dez. 2019
This is the whole code returns error the second time strel is used.
My understanding is that the imbinarize gives me a binary image, by the way. Right? Looking to numbers I see all have bianary values.
BW = imread('Capture.png');
imshow(BW)
BW = imbinarize(BW);
se = strel('line',3,3);
BW1=imdilate(BW,se);
BW2=bwareafilt(~BW1,1);
se = strel('line',3,3);
BW3=imerode(BW2,se);
se=strel('disk',7);
result=imclose(BW3,se);
imshow(result);
KALYAN ACHARJYA
KALYAN ACHARJYA am 6 Dez. 2019
Bearbeitet: KALYAN ACHARJYA am 6 Dez. 2019
#Try
BW = rgb2gray(imread('Capture.png'));
figure,imshow(BW)
BW = imbinarize(BW);
se = strel('line',3,3);
BW1=imdilate(BW,se);
BW2=bwareafilt(~BW1,1);
se = strel('line',3,3);
BW3=imerode(BW2,se);
se=strel('disk',7);
result=imclose(BW3,se);
figure,imshow(result);
Very Determined
Very Determined am 6 Dez. 2019
Great. It works. So I have to convert it from RGB first.
Thak you again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 6 Dez. 2019

1 Stimme

Looks like you're doing an edge detection for some reason. Can I see the original image? Because usually edge detection is NOT what you want to do, for exactly the reasons you are seeing. It would probably be better to use a different segmentation method, like thresholding.

4 Kommentare

Image Analyst
Image Analyst am 6 Dez. 2019
Bearbeitet: Image Analyst am 10 Dez. 2019
Exactly as I thought. You don't want to do edge detection. You should do color segmentation. If all your subjects are on green grass, you should use the Color Thresholder app on the Apps tab of the tool ribbon to find all green stuff. Anything that is not green is your subject. Let me know if you can't figure it out.
Or you might try training a deep learning model to identify the subjects from overhead images.
Very Determined
Very Determined am 6 Dez. 2019
Bearbeitet: Image Analyst am 10 Dez. 2019
Hello, I will try this then. Thank you for the reponse.
[EDIT] Flag moved here to a comment.
Could you remove the images and the key word (cattle) from your response. I am not allowed to post the images/topic in public as a part of my research agreement.
Image Analyst
Image Analyst am 10 Dez. 2019
I changed the keyword to subject. It looks like the images are no longer there for some reason, perhaps because you took them down from your site.
Very Determined
Very Determined am 10 Dez. 2019
Bearbeitet: Very Determined am 10 Dez. 2019
Thank you.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by