How to Segment a object's based on color pixel value ? and how to labelling it ?

조회 수: 3 (최근 30일)
Selva Karna
Selva Karna 2021년 2월 17일
댓글: Image Analyst 2021년 6월 26일
How to Segment a object's based on color ?and how to labelling it ? Image dynamic ?

답변 (1개)

Image Analyst
Image Analyst 2021년 2월 17일
You can use the Color Thresholder on the Apps tab of the tool ribbon. Tell it to export the code. Then you can pass the mask into bwlabel() or bwconncomp().
For the image you've shown, it looks like it was already labeled and passed in to label2rgb() function to produce a pseudocolored image. If not, then tell me how you obtained that image and why you don't have the labeled image for it.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 2월 17일
See my File Exchange where I have several demos where I use color segmentation without the color thresholder.
And will you respond to my last paragraph?
Image Analyst
Image Analyst 2021년 6월 26일
You can create a histogram (256x256x256) of colors, then use unique() to get the unique colors. Then use a for loop to find all pixels of each color in an RGB image and assign a labeled image the color index. Something like (untested)
[rows, columns, numColorChannels] = size(rgbImage);
hist3d = zeros(256,256,256);
for col = 1 : columns
for row = 1 : row
r = rgbImage(row, column, 1);
g = rgbImage(row, column, 2);
b = rgbImage(row, column, 3);
hist3d(r, g, b) = hist3d(r, g, b) + 1;
end
end
row = 1;
uniqueColors = zeros(nnz(hist3d), 3);
for r = 0 : 255
for g = 0 : 255
for b = 0 : 255
uniqueColors(row, :) = [r, g, b];
end
end
end
% Create labeled image.
labeledImage = zeros(rows, columns);
for row = 1 : size(uniqueColors, 1)
maskr = rgbImage(:, :, 1) == uniqueColors(row, 1);
maskg = rgbImage(:, :, 2) == uniqueColors(row, 2);
maskb = rgbImage(:, :, 3) == uniqueColors(row, 3);
mask = maskr & maskg & maskb; % Mask of where this RGB color occurs in the image.
labeledImage(mask) = row;
end
imshow(labeledImage, []);
title('Labeled Image')

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

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by