フィルターのクリア

How to remove unwanted small blob?

11 ビュー (過去 30 日間)
Tan Wen Kun
Tan Wen Kun 2015 年 11 月 11 日
コメント済み: Image Analyst 2015 年 11 月 13 日
I want to remove the small blob and only keep the largest connected blob.
How can I do it?
  1 件のコメント
Tan Wen Kun
Tan Wen Kun 2015 年 11 月 11 日
編集済み: Tan Wen Kun 2015 年 11 月 12 日
I want the keep the region which in black box only.
Other small blob I want turn to background color

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

採用された回答

Image Analyst
Image Analyst 2015 年 11 月 11 日
First of all, don't use watershed or whatever to break up the blobs into sub-blobs. Then use imclearborder() to get rid of blobs touching the borders, then use bwareafilt(binaryImage, 1) to get just the largest blob.
  9 件のコメント
Tan Wen Kun
Tan Wen Kun 2015 年 11 月 13 日
binary is c and d, b is edge image
Image Analyst
Image Analyst 2015 年 11 月 13 日
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
fullFileName = fullfile(pwd, 'd.jpg');
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Binarize the gray scale image.
binaryImage = grayImage > 128;
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get rid of blobs touching the border
binaryImage = imclearborder(binaryImage);
subplot(2, 2, 3);
imshow(binaryImage, []);
title('With border cleared', 'FontSize', fontSize, 'Interpreter', 'None');
% Get the largest remaining blob:
binaryImage = bwareafilt(binaryImage, 1);
subplot(2, 2, 4);
imshow(binaryImage, []);
title('Largest Remaining Blob', 'FontSize', fontSize, 'Interpreter', 'None');

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by