How to count the average rgb value of label region from original image?

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 4 Dec 2015
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 Comments
Tan Wen Kun
Tan Wen Kun on 4 Dec 2015
Edited: Tan Wen Kun on 4 Dec 2015
It is the thing I want to do,after got mean then I want try merge the label together like label 1 and label 2 comparing rgb whether is +-5 or not.
If yes then I reassign label 2 to label 1.
After reassign all the label then I do the clearborder so I can get the lousy segmentation for my image. That my work done. I also regret get a image segmentation topic, it made my life worst because never touch matlab and image segmentation before, I only got 4week to learn it so this the reason I always the weird question you think.
I want turn label to final result is get almost like that but the label is already reassign so the object maybe only got few label color only
Image Analyst
Image Analyst on 4 Dec 2015
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!