Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSI out of bounds values and hue shifting #38

Open
jtlapp opened this issue Nov 9, 2017 · 6 comments
Open

HSI out of bounds values and hue shifting #38

jtlapp opened this issue Nov 9, 2017 · 6 comments

Comments

@jtlapp
Copy link

jtlapp commented Nov 9, 2017

The HSI conversion will take valid intensity values and convert them to RGB bytes > 255.

Also, shifting the intensity by a small amount can produce a rather large change in hue.

const cs = require('color-space');

console.log('HSI:');
let rgb1 = [ 0xb7, 0xc7, 0xff ];
let hsi = cs.rgb.hsi(rgb1);
let rgb2 = cs.hsi.rgb(hsi);
console.log(`     from RGB ${round(rgb1)} to HSI ${round(hsi)}`);
console.log(`  back to RGB ${round(rgb2)}`);
hsi[2] += 6;
let rgb3 = cs.hsi.rgb(hsi);
console.log(`  i+=6 to RGB ${round(rgb3)}`);

function round(vals) {
    return [Math.round(vals[0]), Math.round(vals[1]), Math.round(vals[2])];
}

Yields:

HSI:
     from RGB 183,199,255 to HSI 228,14,212
  back to RGB 183,199,255
  i+=6 to RGB 188,205,262
@jtlapp jtlapp changed the title HSI out of bounds I and hue shifting HSI out of bounds values and hue shifting Nov 9, 2017
@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

FYI @dfcreative

@dy
Copy link
Member

dy commented Nov 9, 2017

Thanks for the catch! Can you help with fixing that?

@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

There are so many ways to express this conversion, I'm not finding the algorithm you modeled. I'm coding it from scratch to see if I get better behavior. Will share when I'm done.

@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

I implemented this algoirthm and got these results:

     from RGB 183,199,255 to HSI 227,14,212
  back to RGB 183,200,254
  i+=6 to RGB 188,206,261

Despite using two different algorithms, our results are in rough agreement. There must be something about HSI that I'm not understanding.

@dy
Copy link
Member

dy commented Nov 9, 2017

I used this source http://web.archive.org/web/20130124054245/http://web2.clarkson.edu/class/image_process/RGB_to_HSI.pdf

@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

I experimented with bounding the RGB outputs to 0..255 and the colors I get seem quite reasonable for my image transformations. I think that's all you need to do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants