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

1 回表示 (過去 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 Center および File ExchangeGet 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