Converting between RGB and HSV colorspaces -- lose Hue steps?

prismspecs's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Peter Castine's icon

It's not losing steps, it's scaling them. To scale back, either [scale 0. 255. 0. 359.] or simply [* 1.41176]. (You probably want float scaling, although there might be an argument for int scaling.)

FWIW, I've typically seen HSV as all values normalized to floats in the unit range.

Peter Castine's icon

Alternately, there's plenty of code online for HSV-to-RGB conversion. It's a pretty straightforward programming exercise to get whatever output convention you want.

prismspecs's icon

I think I'm correct when I say that one loses steps in this situation. For example, if you are scaling from 0-9 to 0-99, you lose the ability to have the number 7, or 77, for example. It's less precise. If there is no way to do this within jitter (which there should be, imo!) then you're right about turning to the math. Maybe I should write a LUA object for this and gift it to the community.

Thanks

Peter Castine's icon

You original message sounded as if you thought you were losing the values 256 to 359, which you're not.

Yes, you're losing granularity. OTOH, you're gaining the ability to store HSV values in a char matrix, which is not to be sneezed at.

Sorry if there was any misunderstanding.

I don't have time right now to check your patch, nor the Max docs, but I would double-check to see if you can't get jit.colorspace to work with float and/or double values. That will get you far more granularity than you can in any integer domain.

But, by all means, write this in Lua if you are so inclined. I wrote RGB-to-HSV-to-RGB in Javascript a few years back, but unfortunately I don't own the code to share. It was, however, a straightforward exercise.

prismspecs's icon

I see I see. Thanks. I'll check out the float avenue and hopefully remember to report here for future MAXers...

prismspecs's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This is a little idiosyncratic but it takes a hue and spits out RGB. The floating trick works.