Remove parts from Image and Fill Parts
조회 수: 5 (최근 30일)
이전 댓글 표시
massimiliano de martino
2019년 12월 9일
댓글: massimiliano de martino
2019년 12월 10일
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
댓글 수: 0
채택된 답변
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!