How to simplify [ 1 0 0] to red?
조회 수: 2 (최근 30일)
이전 댓글 표시
This is my code that checks which color I have and converts it to matlab syntax
%{
Red = [0 0 0; 255 20 20]; should be complete
Orange = [240 50 0; 255 146 100]; should be complete
Blue = [0 0 0; 20 20 255]; should be complete
Green = [0 200 60; 46 255 150]; should be complete
White = [190 200 200; 255 255 255]; should be complete
Yellow = [215 230 0; 255 255 34]; should be complete
%}
function ColorIdent = ColorID(h)
for w = 1: size(h,1)
if [(h(w,1) <= 255),(h(w,2) <= 20),(h(w,3) <= 20)] %Red limits
ColorIdent(w,:) = [1 0 0]; %Red
elseif [(h(w,1) >= 240),((h(w,2) >= 50) && (h(w,2) <= 146)),(h(w,3) <= 100)] %Orange limits
ColorIdent(w,:) = [1 0 1]; %Orange but had to use magenta
elseif [(h(w,1) <= 20),(h(w,2) <= 20),(h(w,3) <= 255)&&(h(w,3) >= 0)] %Blue limits
ColorIdent(w,:) = [0 0 1]; %Blue
elseif [(h(w,1) <= 46),(h(w,2) >= 200),(h(w,3) <= 150)&&(h(w,3) >= 60)] %Green limits
ColorIdent(w,:) = [0 1 0]; %Green
elseif [(h(w,1) >= 190),(h(w,2) >= 200),(h(w,3) >= 200)] %White limits
ColorIdent(w,:) = [1 1 1]; %White
elseif [(h(w,1) >= 215),(h(w,2) >= 230),(h(w,3) <= 140)] %Yellow limits
ColorIdent(w,:) = [1 1 0]; %Yellow
end
end
end
What I want to do is change the rgb triplet to its respective color
so if [1 0 0] then r
if [1 0 1] then m
if [0 0 1] then b
so on so forth
댓글 수: 4
Walter Roberson
2021년 2월 10일
ColorCodes = 'kbgyrmcw';
k = [0 0 0]; b = [0 0 1]; g = [0 1 0]; y = [0 1 1]; r = [1 0 0]; m = [1 0 1]; c = [1 1 0]; w = [1 1 1];
idx = rgb2ind(reshape(h, [], 1, 3), [k;b;g;y;r;m;c;w]);
ColorIdent = ColorCodes(idx);
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!