Remove parts from Image and Fill Parts

6 ビュー (過去 30 日間)
massimiliano de martino
massimiliano de martino 2019 年 12 月 9 日
Goodmorning,
I would like to have help about that question:
I have the image_1 which I've attached.After having thresholding and binarized that image as result i've Image_2 (attached).Starting from Binary Image (Image_2) ,I would like to remove filled parts and noise, and I would like to fill remaining empty shapes (Filled Parts,Noise and Empty Shape are clearly reported in the Image_3).
Thanks in advance for your support
Attached also the develpoed code
clear
clc
close all
%%
rgbImage = imread('Foto_1.JPG');
Image_Gray = rgb2gray(rgbImage); % Translete in Gray Scale
%%
figure;grid on;hold on;
subplot(121);
imshow(Image_Gray);
subplot(122)
[counts,binLocations] = imhist(Image_Gray);
bar(binLocations,counts)
%%
thresholdValue = 100; % 100 is the correct Value
binaryImage = Image_Gray > thresholdValue; % Bright objects will be chosen if you use >.
figure;
imshow(binaryImage);
hold off

採用された回答

Image Analyst
Image Analyst 2019 年 12 月 10 日
Pretty easy. Threshold, fill holes, take the 3 largest.
Solution below. Adapt as needed.
% Initialization steps.
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 = 14;
filename = fullfile(pwd, 'image_1.jpg');
grayImage = imread(filename);
if ndims(grayImage) == 3
% It's really an RGB image, not a gray scale image.
% Convert to gray scale
grayImage = rgb2gray(grayImage);
end
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize);
% Threshold
subplot(2, 3, 2);
imhist(grayImage);
grid on;
title('Histogram', 'FontSize', fontSize);
mask = grayImage < 128; % or whatever value works
subplot(2, 3, 3);
imshow(mask, []);
title('Initial Binary Image', 'FontSize', fontSize);
% Fill Holes
mask = imfill(mask, 'holes');
subplot(2, 3, 4);
imshow(mask, []);
title('After holes filled', 'FontSize', fontSize);
% Take 3 largest blobs then invert intensity.
mask = ~bwareafilt(mask, 3);
subplot(2, 3, 5);
imshow(mask, []);
title('Final Image Showing 3 Largest', 'FontSize', fontSize);
0000 Screenshot.png
  1 件のコメント
massimiliano de martino
massimiliano de martino 2019 年 12 月 10 日
Thanks for your support

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by