How to make a set of RGB color combinations

9 visualizaciones (últimos 30 días)
Mario Trevino
Mario Trevino el 5 de Feb. de 2013
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?

Respuesta aceptada

Thorsten
Thorsten el 5 de Feb. de 2013
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 comentarios
Mario Trevino
Mario Trevino el 5 de Feb. de 2013
thanks Thorsten!
Jan
Jan el 6 de Feb. de 2013
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.

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 5 de Feb. de 2013
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?

Mario Trevino
Mario Trevino el 5 de Feb. de 2013
Hey there, thanks for your help Im solving an image processing problem, and Im planning to create multiple masks with different colors to detect regions. the more different the colors are, the less likely it will be that mask detection would pull out different masks with similar colors.... you see?
  2 comentarios
Jan
Jan el 6 de Feb. de 2013
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
Image Analyst el 7 de Feb. de 2013
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by