Search code examples
matlabimage-processingcolorshsv

How to determine color in MATLAB


I would like to map HSV values to color names in MATLAB. I have converted RGB to HSV and thresholded the values using a series of if statements in order to determine the color . However I would instead like to map the values to defined color names. Is this possible in MATLAB?


Solution

  • If you're working with an mxnx3 (i.e. 2D with 3 channels) RGB image im, then typically the red channel is im(:,:,1), green is im(:,:,2), and blue is im(:,:,3). So if you want the RGB values at some point (x, y), then you can get the vector by im(x,y,:).

    If you just want to convert HSV values to RGB, then you can use the function hsv2rgb.