How to detect a dark color in RGB triplet?

4 ビュー (過去 30 日間)
David Franco
David Franco 2020 年 4 月 26 日
コメント済み: David Franco 2020 年 4 月 26 日
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:

採用された回答

Image Analyst
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);
  2 件のコメント
David Franco
David Franco 2020 年 4 月 26 日
For Gama 0-1 should I use 0.5 instead of 128?
David Franco
David Franco 2020 年 4 月 26 日
I am already using
if mean(color) < 0.45 % tried with median(color) < 0.45 too
mapshow(Snew(results(ii,2)),'FaceColor',color,'EdgeColor',[1,1,1]); % white border
else
mapshow(Snew(results(ii,2)),'FaceColor',color,'EdgeColor',[0,0,0]); % white border
end
But the results aren't good enough... Sometimes light regions get white borders:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by