How to isolate object from a background of variable brightness

조회 수: 12 (최근 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