How to detect a dark color in RGB triplet?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am plotting a map with many subdivision and colors.
I would like to automatically draw the borders with contrasting color with respect to the facecolor of the subdivision.
I am using the sum of the RGB triplet but I am not having perfect matchs.
Is there another way to do that?
My results until now:
댓글 수: 0
채택된 답변
Image Analyst
2020년 4월 26일
I don't know what you do on the border between light and dark regions. But anyway, when you're drawing the boundary around a region get the mean RGB of that region -- summing the values is fine, or equvalently, taking the mean. Then you can say
meanRGB = mean([regionsRedValue, regionsGreenValue, regionsBlueValue]);
if meanRGB < 128
% It's dark, so draw with white line.
lineColor = 'w';
else
% It's bright, so draw black line.
lineColor = 'k';
end
plot(x, y, '-', 'Color', lineColor, 'LineWidth', 2);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Map Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!