Remove parts from Image and Fill Parts

6 visualizaciones (últimos 30 días)
massimiliano de martino
massimiliano de martino el 9 de Dic. de 2019
Comentada: massimiliano de martino el 10 de Dic. de 2019
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

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Dic. de 2019
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

Más respuestas (0)

Categorías

Más información sobre Vehicle Scenarios en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by