How to isolate object from a background of variable brightness

10 ビュー (過去 30 日間)
Tapan Goel
Tapan Goel 2021 年 4 月 12 日
編集済み: DGM 2021 年 4 月 13 日
I am trying to isolate worms in these images below which have a variable background:
I binarize the image using
im = imbinarize(255-rgb2gray(image),'adaptive','Sensitivity',.62,'ForegroundPolarity','dark')
and get:
I then use
imfill(im,'holes')
to get
Now that I have a black 'halo' around my desired object, I want to isolate it from the background so that I can process it further - measure its area and the length of its skeleton.
But I am not sure how to do this.
The images always have only 1 of these worms - there are no other objects in the image. Just the background with striations and uneven lighting with 1 useful object in them.
Any help would be much appreciated :)
I've also attached the original image below.
Thanks in advance :)

採用された回答

DGM
DGM 2021 年 4 月 13 日
編集済み: DGM 2021 年 4 月 13 日
There are probably more robust methods, but here is my attempt:
image=imread('worm.bmp');
im0 = imbinarize(255-rgb2gray(image),'adaptive','Sensitivity',0.60,'ForegroundPolarity','dark');
se = strel('disk',5);
im = imerode(im0,se); % break up the bg
im = bwareafilt(im,1); % isolate primary object
im = imdilate(im,se); % restore
im = imfill(im,'holes');
Think of it as image opening, but with object isolation done in the middle, so that noise connectivity is at its lowest. It seems to work with both the test images.

その他の回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by