How can I segment depth images

I have read depth imges and converted them into grayscale. Now how to segment the hand region properly.

답변 (1개)

yanqi liu
yanqi liu 2021년 10월 12일

0 개 추천

sir,please check the follow code to get some information
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/764791/img27.png');
bw = imbinarize(img,'adaptive','ForegroundPolarity','dark','Sensitivity',0.8);
bw = imclose(bw, strel('line', 5, 0));
bw = imclearborder(bw);
bw = bwareafilt(bw, 1);
bw = imclose(bw, strel('line', 25, 0));
bw = imfill(bw, 'holes');
bw = imopen(bw, strel('line', 15, 0));
bw = bwareafilt(bw, 1);
[r,c] = find(bw);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
figure; imshow(img);
hold on; rectangle('position', rect, 'EdgeColor', 'g', 'LineWidth', 2)

댓글 수: 8

Zara Khan
Zara Khan 2021년 10월 12일
편집: Zara Khan 2021년 10월 12일
How to crop the hand portion separately ?? One more thing. I have 1320 images, is this algorithm will work in general ??
sir,may be use some DeepLearning framework to make it work in general ,such as yolo,frcnn
can crop by the follows.
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/764791/img27.png');
bw = imbinarize(img,'adaptive','ForegroundPolarity','dark','Sensitivity',0.8);
bw = imclose(bw, strel('line', 5, 0));
bw = imclearborder(bw);
bw = bwareafilt(bw, 1);
bw = imclose(bw, strel('line', 25, 0));
bw = imfill(bw, 'holes');
bw = imopen(bw, strel('line', 15, 0));
bw = bwareafilt(bw, 1);
[r,c] = find(bw);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
figure; imshow(img);
hold on; rectangle('position', rect, 'EdgeColor', 'g', 'LineWidth', 2)
% crop
img2 = imcrop(img,rect);
figure; imshow(img2);
Zara Khan
Zara Khan 2021년 10월 12일
Instead of cropping can we make the background totally black. I mean the final image will be binary one. Hand region will be white and background will be black
Try using the inverse of the hand mask to erase that part of the original image
maskedImage = img; % Initialize to the original image.
% Now erase pixels not in the hand mask.
maskedImage(~bw) = 0;
Zara Khan
Zara Khan 2021년 10월 13일
Image Analyst: Not able to clear the background properly.
Zara Khan
Zara Khan 2021년 10월 13일
yanqi Liu: How you are calculating the rectangle ?
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/764791/img27.png');
bw = imbinarize(img,'adaptive','ForegroundPolarity','dark','Sensitivity',0.8);
bw = imclose(bw, strel('line', 5, 0));
bw = imclearborder(bw);
bw = bwareafilt(bw, 1);
bw = imclose(bw, strel('line', 25, 0));
bw = imfill(bw, 'holes');
bw = imopen(bw, strel('line', 15, 0));
bw = bwareafilt(bw, 1);
[r,c] = find(bw);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
figure; imshow(img);
hold on; rectangle('position', rect, 'EdgeColor', 'g', 'LineWidth', 2)
% make mask
figure; imshow(bw)
img1 = img; img2 = img; img3 = img;
img1(~bw) = 0; img2(~bw) = 0; img3(~bw) = 0;
imgr = cat(3, img1, img2, img3);
figure; imshow(imgr);
Zara Khan
Zara Khan 2021년 10월 14일
Mask is not working well. Still have some background portion. Any other idea?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2021년 10월 12일

댓글:

2021년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by