Syntax
rgb=rgbofall(x)
Input Parameter
x : | | input character 'b' or [255 0 0] etc. |
Output Parameter
rgb : | | rgb value between 0 and 1 |
Examples
rgbofall('y')
rgbofall(['y','g'])
rgbofall([255 0 64])
Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, rgbofall
, is designed to convert various input formats into RGB color values represented as doubles between 0 and 1. The function can handle character inputs, numeric arrays, and other formats, converting them into a standardized RGB format.
Input Parameters
- x: The input can be a character (e.g., 'b'), a string of characters (e.g., 'yg'), or a numeric array (e.g., [255 0 64]).
Output
- rgb: The output is an RGB value where each component is a double between 0 and 1.
Algorithm Steps
- Initialize a color table
ctab
with the characters 'kbgcrmyw', representing black, blue, green, cyan, red, magenta, yellow, and white.
- Check if the input
x
is a character array:
- Determine the number of characters
nc
in x
.
- Initialize an
nc
by 3 matrix rgb
with NaN values.
- For each character in
x
, convert it to an RGB value using the char2rgb
function and store it in the rgb
matrix.
- Normalize the
rgb
values by dividing by 255.
- If
x
is a numeric array with three columns and any value greater than 1:
- Normalize the array by dividing by 255 to convert it to a range between 0 and 1.
- If
x
is a numeric array with three columns and all values are less than or equal to 1:
- Return the array as is, assuming it is already in the correct range.
- If
x
is a single row or column vector:
- Determine the number of elements
nc
in x
.
- Initialize an
nc
by 3 matrix rgb
with NaN values.
- For each element in
x
, map it to a character in ctab
and convert it to an RGB value using char2rgb
.
- Normalize the
rgb
values by dividing by 255.
- If none of the above conditions are met, assume
x
is already in the correct RGB format and return it as is.
Algorithm explaination created using ChatGPT on 2025-08-19 00:19. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21