Andrew Simpson
Andrew Simpson

Reputation: 7334

Converting HSV data from base 255 to base 359

I am using emgucv.

I wish to do hsl filtering.

the colour range is 0 to 359.

I am filtering yellows so I am looking for hues from 30 to 60.

I load an existing bitmap and load it as a hsv image:

var img = new Image<Hsv, int>(@"D:\yellow.jpg");

When I run this I get:

System.NotSupportedException: 'There is an error converting Emgu.CV.Structure.Bgr to Emgu.CV.Structure.Hsv: Requested value 'Bgr2Bgr' was not found.'

I could do this:

var img = new Image<Hsv, byte>(@"D:\yellow.jpg");

and that loads fine, but the byte values only go up to 255.

What else can I try? Do I have to multiply each 'pixel' data by value * 255/359?

Upvotes: 0

Views: 206

Answers (1)

AeroClassics
AeroClassics

Reputation: 1124

The simplest way is to read the file. That should give you a RGBA image. Convert RGBA to BGR and then convert from BGR to HLS.

I use Mats so:

Mat src = new Mat(@"D:\yellow.jpg");
Mat Bgr = new Mat();
Mat Hls = new Mat();
CvInvoke.CvtColor(src, Bgr, ColorConversion.Rgba2Bgr);
CvInvoke.CvtColor(Bgr, Hls, ColorConversion.Bgr2Hls);

I think it does. You want to do HSL filtering, which tells me you need the image in HSL format. In all cases in OpenCV, HSV, HSL, etc only go to 255 so they fit nicely in a byte for 8-bit images. If you are using a 32-bit depth the values are unchanged. 16-bit images are NOT supported. For HSV the value for Hue are 0 - 180 (I use BGR with 8-bit unsigned values), I simply multiply or divide by 2, but this is ONLY necessary if I need to show this value to the user or get a Hue value from the user. Ultimately, it has no effect on how I work with the Hue value internally.

HSL is treated the exact same way, Hue values for 8-bit are 0 - 180, 16-bit is unsupported and 32-bit is left unchanged.

Doug

Upvotes: 1

Related Questions