How can I improve segmentation of these images?

9 ビュー (過去 30 日間)
BC
BC 2021 年 2 月 25 日
コメント済み: BC 2021 年 2 月 27 日
I'm trying to segment ants in several thousand images (I've attached two images here). I'm then applying a colour detection function, with the ultimate aim of detecting paint marks on the abdomen of ants.
I've had some success with the below segmentation, but it also sometimes picks up the brood (the pale oval-shaped things in the image), as well as some of the border. I can't just use something like imclearborder, because often there are ants connected to these border pixels, right on the edge of the image.
I have also tried
  • K means clustering - but often the colour blobs are treated seperately to the ant body
  • imfindcircles (to try and isolate just the abdomen of ants) - not much success so far
I'm just wondering if anyone has any input or other methods to improve the segmentation.
ant = imread("ant.jpg") % read original image, call it "ant"
burnedAnt = createAntSegmentation(ant) % apply local function to ant image
%% display images side by side, check segmentation not too strict
fig = figure();
ax(1) = axes('Units','normalized','Position', [ .1 .1 .4 .8]);
ax(2) = axes('Units','normalized','Position', [ .5 .1 .4 .8]);
imshow(ant,'Parent', ax(1)) % display original image
imshow(burnedAnt, 'Parent', ax(2)) % display new burned image
linkaxes(ax)
%% create function to segment ants, and burn the mask onto the original
% image
function burnedAnt = createAntSegmentation(ant)
greyant = rgb2gray(ant); % convert image to grayscale
% threshold image. Higher = more lenient filering
adaptedAnt = adaptthresh(greyant, 0.38,"ForegroundPolarity","dark");
BW = imbinarize(greyant,adaptedAnt); % binarize ant image, using the above thresholding
BWopen = bwareaopen(~BW,800); % exclude pixels smaller than X
se = strel("disk",32); % create shape used for dilating image
% dilate image, expand the white pixels to ensure not cutting off relevant areas
BWdilate = imdilate(BWopen,se);
BWfilled = imfill(BWdilate,"holes"); % fill in any holes
%produce final image, mask burned onto original image, with black (k) fill.
burnedAnt = imoverlay(ant,~BWfilled,"k");
end

採用された回答

Image Analyst
Image Analyst 2021 年 2 月 27 日
編集済み: Image Analyst 2021 年 2 月 27 日
Did you try the Color Thresholder on the Apps tab of the tool ribbon? Set it up for hsv color space and tell it to find green blobs and then export the code. Do you need the whole ant, or just need to know how many green blobs there are? It could get tricky if some of the ants touch each other, connecting the blobs.
  5 件のコメント
Image Analyst
Image Analyst 2021 年 2 月 27 日
Yeah, it doesn't have to be a video. A video is essentially just a series of still photos anyway, just like you got. I'm sure it can get tricky quickly, like if ants crawl over each other or touch, and some ants don't seem to have a very vivid green dot, if an ant is covering an arena mark in the first image, etc. So I'm just describing the simplest case. I'm sure you'll run into lots of cases where it gets tricky. Good luck though.
BC
BC 2021 年 2 月 27 日
Yeah there's lots of little issues that'll crop up for sure! It'll never be 100% accurate but I'm trying to get it as good as I can. Thanks again for the help :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by