การตรวจับสีผิวโดยใช้สี YCbCr
การตรวจับสีผิวโดยใช้สี YCbCr
clc,
close all,
clear all,
%%
img_orig=imread(‘car6.jpg’);
figure, imshow(img_orig)
img=img_orig; %copy of original image
%%
img_g = rgb2gray(img);
img_g1 = img_g;
%%
ycbcr = rgb2ycbcr(img);
y=ycbcr(:,:,1);
cb=ycbcr(:,:,2);
cr=ycbcr(:,:,3);
figure, imshow(cb), impixelinfo
figure, imshow(cr), impixelinfo
figure, imshow(y), impixelinfo
%%
[r c] = size(y);
%%
for i = 1:r
for j = 1:c
if cb(i,j) >= 110 && cb(i,j) <= 120 && cr(i,j) >= 137 && cr(i,j) <= 142
%img_g(i,j) = img_g(i,j);
img_g(i,j) = 255;
else
img_g(i,j) = 0;
end
end
end
figure, imshow(img_g), impixelinfo
%%
imf = imfill(img_g, ‘holes’);
figure, imshow(imf), impixelinfo
%%
imbw = bwareaopen(imf, 5000);
figure, imshow(imbw), impixelinfo
%%
m = img_g1 .* uint8(imbw);
figure, imshow(m), impixelinfo
%%
[rimbw cimbw] = size(imbw);
for iimbw = 1:rimbw
for jimbw = 1:cimbw
if imbw(iimbw,jimbw) == 1
%img_g(i,j) = img_g(i,j);
img_orig(iimbw,jimbw,:) = img_orig(iimbw,jimbw,:);
else
img_orig(iimbw,jimbw,:) = 0;
end
end
end
figure, imshow(img_orig), impixelinfo
ภาพ Input
ภาพ Output
Comments
Post a Comment