Color segmentation


(system) #1

السلام عليكم اود ان اسالكم عن كود موجود بالهيلب اود معرفة بعض الشرح

هذا هو الكود

[LEFT]fabric = imread(‘fabric.png’);
figure(1), imshow(fabric), title(‘fabric’);
load regioncoordinates;

nColors = 6;
sample_regions = false([size(fabric,1) size(fabric,2) nColors]);

for count = 1:nColors
sample_regions(:,:,count) = roipoly(fabric,region_coordinates(:,1,count),…
region_coordinates(:,2,count));
end

imshow(sample_regions(:,:,2)),title(‘sample region for red’);
cform = makecform(‘srgb2lab’);
lab_fabric = applycform(fabric,cform);
a = lab_fabric(:,:,2);
b = lab_fabric(:,:,3);
color_markers = repmat(0, [nColors, 2]);

for count = 1:nColors
color_markers(count,1) = mean2(a(sample_regions(:,:,count)));
color_markers(count,2) = mean2(b(sample_regions(:,:,count)));
end
color_labels = 0:nColors-1;
Initialize matrices to be used in the nearest neighbor classification.a = double(a);
b = double(b);
distance = repmat(0,[size(a), nColors]);
Perform classificationfor count = 1:nColors
distance(:,:,count) = ( (a - color_markers(count,1)).^2 + …
(b - color_markers(count,2)).^2 ).^0.5;
end

[value, label] = min(distance,[],3);
label = color_labels(label);
clear value distance;
rgb_label = repmat(label,[1 1 3]);
segmented_images = repmat(uint8(0),[size(fabric), nColors]);

for count = 1:nColors
color = fabric;
color(rgb_label ~= color_labels(count)) = 0;
segmented_images(:,:,:,count) = color;
end

imshow(segmented_images(:,:,:,2)), title(‘red objects’);

[RIGHT]سؤالي هو ارجو من ذوي الخبرة شرح كيف يتم التعرف على اللون وماهو الجزء في الكو د اللي يوضح ذلك

وما المقصود بذا الجزء

distance = repmat(0,[size(a), nColors]);
[/right]
[/left]