56926

conversion between RGB and HSV space

Question:

I am currently trying to convert two objects from RGB space to HSV space using the rgb2hsv function, one being an image, the other being a matrix of RGB values, but my results for the value part of the matrix are not consistent.

The results for value in matrix I are between 1 and 255, but in the second matrix D, they are between 0 and 1. Does anybody know why this is the case?

I = imread('00000001.jpg'); I = rgb2hsv(I); D = [221 12 26; 30 68 76; 40 47 27; 165 87 25; 37 59 26; 148 125 91]; D = rgb2hsv(D);

Answer1:

When you call <a href="http://www.mathworks.com/help/matlab/ref/rgb2hsv.html" rel="nofollow">rgb2hsv</a> with a N-by-3 matrix, it is interpreted <em>as a colormap</em>, not an image or even image intensities. A colormap has values on [0,1], while a uint8 image has values on [0,255]. This is what rgb2hsv expects.

The colormap syntax explained by the help page for rgb2hsv:

<blockquote>

H = rgb2hsv(M) converts an RGB color map to an HSV color map. Each map is a matrix with any number of rows, exactly three columns, and elements in the interval 0 to 1.

</blockquote>

When you run D = rgb2hsv(D); it is running it with the above syntax, rather than treating the input as an image.

That said, you can just divide the third column of the output D by 255 since the resulting bizarro colormap seems to simply have scaled value elements.

Answer2:

I simply multiplied by 255 on the resulting matrix from running rgb2hsv on an image. I verified that the hue, saturation, and value were then the correct value and it was. This solved my problem. Be sure to verify. Another weird thing was that those values are a percentage, so 1 means 100% and 0.5 means 50%. This also threw me off.

Recommend

  • Get the ROI of two binary images and find difference of the mean image intesities between 2 ROI in p
  • python imshow, set certain value to defined color
  • Otsu's Thresholding Implementation not working properly
  • How to detect anomalies in opencv (c++) if threshold is not good enought?
  • Matplotlib 3D Plot Colors Appear Darker Than Normal
  • Matlab Image and Plot with Unexpected Flip
  • What is equivalent of VB6.0's MaskColor property in C#
  • Skewing an array in Python
  • How to use OpenCV in python 3.4 on windows 7 x64? [duplicate]
  • Problems using HOGDescriptor
  • Matplotlib: Custom colormap with three colors [duplicate]
  • Why are `colMeans()` and `rowMeans()` functions faster than using the mean function with `lapply()`?
  • K-means in OpenCV's Python interface
  • Is it possible to disable esc/F11 key during full screen mode of webpage, programmatically?
  • 'include' of functions in groovy scripts
  • Can XOR be expressed using SKI combinators?
  • Streaming screenshots over WebRTC as a video stream from iOS
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • Cut the background to expose the layer below
  • Row to Column conversion in Talend
  • Java color detection
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • Chart.js Multiple dataset
  • How do I open a C file with a relative path?
  • Google Custom Search with transparent background
  • Android fill_parent issue
  • Highlight and Bold text in JTextPane
  • Syntax for setting draggablecursor property in google maps api
  • Algorithm for a smudge tool?
  • How reduce the height of an mschart by breaking up the y-axis
  • Resize panoramic image to fixed size
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Web-crawler for facebook in python
  • A cron job substitute?
  • Change div Background jquery
  • Android Google Maps API OnLocationChanged only called once
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?