Effacer les filtres
Effacer les filtres

How to extract the blob in the middle of a binary image

7 vues (au cours des 30 derniers jours)
Manuella Juwita
Manuella Juwita le 18 Juil 2020
Commenté : Image Analyst le 20 Juil 2020
I want to ask how to extract the blob in the middl to measure the area. Because my image has a lot of noise and nonuniform lighting, it is really hard to do so. This is my greyscale image
Here is the code that I used to get the binary image
I = imread("C:\Users\Lenovo\Downloads\Suryajaya_Data2_front\Suryajaya_Data2_front\Suryajaya_Data2_front_ROI465.jpg");
I = adapthisteq(I);
%gmag = imgradient(I);
gmag = imfilter(I, fspecial('average',[5 5]),'replicate');
L = watershed(gmag);
Lrgb = label2rgb(L);
se = strel('disk',50);
Io = imopen(I,se);
Ie = imerode(I,se);
Iobr = imreconstruct(Ie,I);
Ioc = imclose(Io,se);
Iobrd = imdilate(Iobr,se);
Iobrcbr = imreconstruct(imcomplement(Iobrd),imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
fgm = not(fgm);
I2 = labeloverlay(I,fgm);
se2 = strel(ones(5,5));
fgm2 = imclose(fgm,se2);
fgm3 = imerode(fgm2,se2);
fgm4 = bwareaopen(fgm3,4500);
I3 = labeloverlay(I,fgm4);
bw = imbinarize(Iobrcbr);
Here is the final binary image(bw)
My guess is that the corners of the image are too dark that it is included in the foreground of the binary image. How do I extract only the blob in the middle?

Réponse acceptée

Image Analyst
Image Analyst le 18 Juil 2020
Use imclearborder(bw). Here is the full demo:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing
fontSize = 15;
I = imread("Suryajaya_Data2_front_ROI465.jpg");
subplot(2, 2, 1);
imshow(I);
I = adapthisteq(I);
subplot(2, 2, 2);
imshow(I, []);
%gmag = imgradient(I);
gmag = imfilter(I, fspecial('average',[5 5]),'replicate');
L = watershed(gmag);
Lrgb = label2rgb(L);
se = strel('disk',50);
Io = imopen(I,se);
Ie = imerode(I,se);
Iobr = imreconstruct(Ie,I);
Ioc = imclose(Io,se);
Iobrd = imdilate(Iobr,se);
Iobrcbr = imreconstruct(imcomplement(Iobrd),imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
fgm = not(fgm);
I2 = labeloverlay(I,fgm);
se2 = strel(ones(5,5));
fgm2 = imclose(fgm,se2);
fgm3 = imerode(fgm2,se2);
fgm4 = bwareaopen(fgm3,4500);
I3 = labeloverlay(I,fgm4);
subplot(2, 2, 3);
imshow(I3);
bw = ~imbinarize(Iobrcbr);
% Remove blobs touching the edge of the image.
bw = imclearborder(bw);
% Fill any holes that might be there.
bw = imfill(bw, 'holes');
% Extract only the biggest blob.
bw = bwareafilt(bw, 1);
subplot(2, 2, 4);
imshow(bw);
fprintf('Done running %s.m ...\n', mfilename);
  2 commentaires
Manuella Juwita
Manuella Juwita le 20 Juil 2020
Thank you very much Image Analyst! This is so very helpful because I rarely see people talking about this issue. You don't know how much time you've saved me. Once again thank you!
Image Analyst
Image Analyst le 20 Juil 2020
You're welcome. Thanks for Accepting this answer. Actually getting a correct segmentation is one of the most common questions in the forum, other than questions about certain errors. https://matlab.fandom.com/wiki/FAQ#Error_Messages

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 3-D Volumetric Image Processing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by