Image Segmentation using Color Tresholder App ?

9 visualizaciones (últimos 30 días)
PaunBGD
PaunBGD el 15 de Sept. de 2021
Respondida: yanqi liu el 28 de Sept. de 2021
Does anyone have idea how to create mask for this frame? I have a initital frame from video, and I want to create a mask so that later I can extract the region with the traffic policeman's gloves and track them in order to recognize a traffic gestures. I have tried with Color Tresholder App, but I fail to get the proper thresholds.
  1 comentario
PaunBGD
PaunBGD el 15 de Sept. de 2021
Code:
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder App. The colorspace and
% minimum/maximum values for each channel of the colorspace were set in the
% App and result in a binary mask BW and a composite image maskedRGBImage,
% which shows the original RGB image values under the mask BW.
% Auto-generated by colorThresholder app on 02-Jul-2021
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2ycbcr(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 73.000;
channel1Max = 144.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 100.000;
channel2Max = 133.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 137.000;
channel3Max = 153.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end

Iniciar sesión para comentar.

Respuestas (1)

yanqi liu
yanqi liu el 28 de Sept. de 2021
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/740009/untitled.jpg');
J = rgb2hsv(img);
s = mat2gray(J(:,:,2));
bw = im2bw(s, graythresh(s));
bw = imclose(bw, strel('line', 19, 90));
bw = bwareafilt(bw, 1);
bw = imdilate(bw, strel('disk',5));
J1 = img(:,:,1); J2 = img(:,:,2); J3 = img(:,:,3);
J1(bw) = 255; J2(bw) = 0; J3(bw) = 0;
Jt = cat(3,J1,J2,J3);
montage({img, bw, Jt}, 'Size', [1 3], 'BackgroundColor', 'w', 'BorderSize', [3 3])

Community Treasure Hunt

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

Start Hunting!

Translated by