How to extract the blob in the middle of a binary image
7 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で 3-D Volumetric Image Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!