How to count the average rgb value of label region from original image?
1 次查看(过去 30 天)
显示 更早的评论
I have a label matrix image and label 1 is the border
labelimg = original image rgb=
1 2 3 4 5 6 1 2 3 4 5 6
1 3 3 3 3 3 3 1 (111,111,111) (111,111,111) (111,111,111) (111,111,111) (111,111,111) (112,112,112)
2 1 1 1 1 1 1 2 (000,000,000) (000,000,000) (000,000,000) (000,000,000) (000,000,000) (000,000,000)
3 1 2 2 1 4 1 3 (000,000,000) (222,222,222) (222,222,222) (000,000,000) (223,221,223) (000,000,000)
4 1 1 1 1 4 1 4 (000,000,000) (000,000,000) (000,000,000) (000,000,000) (223,221,223) (000,000,000)
5 5 5 5 1 1 1 5 (221,221,221) (223,223,223) (223,223,223) (000,000,000) (000,000,000) (000,000,000)
6 5 5 5 5 5 5 6 (221,221,221) (221,221,221) (221,221,221) (221,221,221) (221,221,221) (221,221,221)
I want count the average(median is more complicated,I want try on average first see whethere can solve my problem or not) rgb value of label region from original image~how to do this?
everytime I loop horizontal through the labelimage, if read 3 then count of 3= +1
I need get the count table so I can count
average=all pixel value of labelx/count of label x
average pixel value of label x=( r,g,b )
count =
label count
2 2
3 6
4 2
5 9
label region average rgb(use the round to integer)
2 (111,111,111)
3 (r,g,b)
4 (r,g,b)
5 (r,g,b)
label is the label image what i done and elephant is the original image
0 个评论
采纳的回答
Image Analyst
2015-12-4
First you need to split up your image into individual color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then you need to get a binary image of each label and then you can get the means for that particular label number.
for yourNumber = 1 : max(labeledImage(:))
thisLabel = labeledImage == yourNumber; % for example 2 or 3 or whatever region you want.
meanR(yourNumber) = mean(redChannel(thisLabel));
meanG(yourNumber) = mean(greenChannel(thisLabel));
meanB(yourNumber) = mean(blueChannel(thisLabel));
end
Again, like your other questions, this is not what you want to do, but it does what you asked.
2 个评论
Image Analyst
2015-12-4
It's really not what you want to do - you just don't realize it yet. It's a wild goose chase - a dead end. But sometimes by doing those things, that's how you learn.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!