Image segmentation using bwareafilt

4 vues (au cours des 30 derniers jours)
Ajith Kumar Rajendra
Ajith Kumar Rajendra le 9 Avr 2021
I have set of depth images in which I want to segement an object from it. I was able to get binary image of the object but I also have some unwanted data/noise along with it. Can someone suggest how to remove them?
Thanks in advance.
clc;
clear all;
close all;
workspace;
s = load(strcat('test_data/data3/d2/images_depth.mat')); %source of data
for i=1:7
img = (s.images_depth{1,i});
[filledDepth, zeroPixels] = Kinect_DepthNormalization(img);
a = mat2gray(filledDepth);
b = imbinarize(a);
b = bwareafilt(b, 1);
c = ~(b);
figure, imshow(c)
% figure,imshow(filledDepth, [])
figure,imshow(img, [])
% figure, imagesc(filledDepth)
end

Réponses (1)

colordepth
colordepth le 15 Avr 2025
To clean up noise in your depth images, consider using a median filter, which is a straightforward method for noise removal. Check out this guide here: https://www.mathworks.com/discovery/denoising.html. Applying this before binarization will help reduce unwanted noise.
For binarizing your depth images, you can manually set a threshold in "imbinarize" by passing a second numerical argument. Experiment with thresholds to find one that best segments your object. More details on "imbinarize" can be found here: https://www.mathworks.com/help/images/ref/imbinarize.html. Rest assured that this will work consistently if your camera and table setup remain unchanged.
If you want an automated approach to automatically adjust to your setup, I suggest programming the following framework:
  1. Noise Removal: For every captured depth image, perform noise removal.
  2. Calibration Step (One-Time): Capture a depth image of your table without any objects on it. Calculate the mean of the smallest 40,000 pixels, which represents about 20% of the 424x512 resolution. This mean value will serve as your "baseEstimate," providing a good approximation of the table's surface. You can tinker with this percentage if it does not work too well for your task.
  3. Object Segmentation Step: With an object on the table, capture a depth image. Calculate an estimate with a similar approach above for the top of the object, referred to as "topEstimate." Use these estimates to determine a threshold for the "imbinarize" function. A threshold like "baseEstimate + 0.1*(topEstimate-baseEstimate)" should effectively separate the object from the table in the binarized image.
I enjoyed tinkering with depth cameras during my undergraduate, I'd be happy to help in answering any questions you have about the above approach :)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by