How to make a set of RGB color combinations
조회 수: 4 (최근 30일)
이전 댓글 표시
I want to build a finite set of RGB colors, say 100, which maximices the overall differences (Euclidean distance) between each of them. Any suggestions?
댓글 수: 0
채택된 답변
Thorsten
2013년 2월 5일
This is what you get if you tile the RGB cube uniformly
N = 100;
n = ceil(N^(1/3)); % 3D color volume
x = linspace(1, 255, n)';
Nr = n^3;
x3 = repmat(x, [Nr/n 1]);
x2 = repmat(x', [5 1]);
x2 = repmat(x2(:), [Nr/numel(x2) 1]);
x1 = repmat(x', [5^2 1]);
x1 = repmat(x1(:), [Nr/numel(x1) 1]);
rgb = [x1 x2 x3];
rgb = rgb(1:N, :); % select first N
% rearrange colors as image to show
n2 = sqrt(N);
if round(n2) == n2
I = reshape(cat(3, cat(3, rgb(:, 1), rgb(:, 2), rgb(:, 3))), [n2 n2 3]);
end
imshow(I/255)
댓글 수: 2
Jan
2013년 2월 6일
Cubes are not the structure with the maximum distance. Actually you need a close packing of spheres. But the fix number of elements makes the problem really hard. I've voted for this question, because it is one of the hardest problems in the forum at all.
추가 답변 (2개)
Image Analyst
2013년 2월 5일
I think that is not such an easy thing to do. Think of a 3D space, in the shape of a Munsell solid if you want to Google that. Would the set of points that has the max average distance between all the points be all on the outer surface? Or uniformly distributed throughout the volume? Or some other distribution? I have no idea, though I bet Roger Stafford does if we're lucky enough to get him to respond here.
I think it might be better to ask what you need this for and find something that works for you. For example, is the "lines" colormap good to use for your situation?
댓글 수: 0
Mario Trevino
2013년 2월 5일
댓글 수: 2
Jan
2013년 2월 6일
The more different does not mean that the distance in the 3D space of RGB values is maximal. "Different" involves the perception by a human and our eyes do not work in RGB space. See FEX: maximal perceptual distinct colors for a solution.
Image Analyst
2013년 2월 7일
Mario, that doesn't make any sense. If you make multiple masks, then you have multiple masks - they are binary (true/false) and the color is of no consequence at all. It doesn't matter if the masks are all on one image or one blob per image and multiple images. Anyway, if you wanted to have multiple colors on a binary image with multiple blobs in the image, you'd just label the image with bwlabel() and then call label2rgb() to turn separate blobs into different colors. You wouldn't do what you asked to do. So I say that your question was wrong, and it you use Thorsten's answer you'll be on a wild goose chase, even though his question may have answered your question. If you want to explain further, go ahead, and we can get this figured out. I've dealt with image processing every day for over 30 years so I have a pretty good understanding of this stuff.
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!