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!