필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Manuella Juwita
Manuella Juwita 2020년 7월 18일
댓글: Image Analyst 2020년 7월 20일
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?

채택된 답변

Image Analyst
Image Analyst 2020년 7월 18일
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
Manuella Juwita
Manuella Juwita 2020년 7월 20일
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 2020년 7월 20일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by