Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:23:40+00:00 2026-06-12T13:23:40+00:00

I have some strange issue when trying to apply a conversion from HSI to

  • 0

I have some strange issue when trying to apply a conversion from HSI to RGB which I am trying to do as part of a homework assignment. To start off, here is my original image:

original image (sorry about the links, I don’t have the rep to post images)

I am converting from an image with H,S,I values (0-255). Here is a display of that image in RGB colorspace (Hue=red, sat=green, inten=blue):

HSI src image

To me it looks about right… the white flowers (high intensity) are blue, the hues (red) seem to change with the different colored flowers.

So now I do some equalization on the intensity channel (blue in display) in some boxes, resulting in this:

HSI equalized image:
http://i.imgur.com/hgk9K.png
((you must copypasta these ’cause I don’t have rep for >2 hyperlinks))

No big deal there. It doesn’t look exactly right, but it’s hard to say and everything outside the region-of-interest boxes is the same.

Now here comes the problem. After converting this back to RGB I get this result:

converted image:
http://i.imgur.com/6wEyw.png

No idea what the problem is here, the green looks okay, but some red/blue pixels seem to be maxed. The three boxes are there as expected, and they’re contents seem pretty messed, but that’s not the bigger issue here since that could be from my equalization function. Everything outside of those boxes should now be nearly identical to the original image, but somehow it has been jumbled.

I’ve gone over my code many times and added extra parentheses and data type casts just to be sure, but still can’t find the issue. I am confident my formulas are correct, but I must be missing some problem in the way the pixel values are being calculated.

Here is the code I am using to convert from HSI to RGB. It is possible the error is outside of this method, but all the functions used here have been tested elsewhere and seem to work fine.

void colorSpace::HSItoRGB(image &src, image &tgt){
    cout<<"HSI->RGB\n";
    tgt.resize(src.getNumberOfRows(),src.getNumberOfColumns());
    float pi = 3.14159265358979f;
    for (int i=0; i<src.getNumberOfRows(); i++){    //for each pixel
        for (int j=0; j<src.getNumberOfColumns(); j++){
            //re-normalize h,s,i
            float h = ((float)src.getPixel(i,j,H))*pi*2.0f/255.0f;//255/2 instead of 180
            float s = ((float)src.getPixel(i,j,S))/255.0f;//255 instead of 100
            float in= ((float)src.getPixel(i,j,I))/255.0f;
            //compute x y z
            float x = in*(1.0f-s);
            float y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
            float z = 3.0f*in-(x+y);
            float r,g,b;    //set rgb
            if(h<(2.0f*pi/3.0f)){
                b = x;
                r = y;
                g = z;
            }else if(h<(4.0f*pi/3.0f)){//&&2pi/3<=h
                r = x; 
                g = y;
                b = z;
            }else{  //less than 2pi && 4pi/3<=h
                g = x;
                b = y;
                r = z;
            }
            //convert normalized rgb to 0-255 range
            int rr = (int)round(r*255.0f);
            int gg = (int)round(g*255.0f);
            int bb = (int)round(b*255.0f);
            tgt.setPixel(i,j,RED,rr);
            tgt.setPixel(i,j,GREEN,gg);
            tgt.setPixel(i,j,BLUE,bb);
        }
    }
}

Does anybody see any trouble in the code or have any insights from looking at the images?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:23:41+00:00Added an answer on June 12, 2026 at 1:23 pm

    The h values need to be adjusted for the three cases prior to calculating the cos values dependent on them. i.e.:

            if(h<(2.0f*pi/3.0f)){
                y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
                b = x;
                r = y;
                g = z;
            }else if(h<(4.0f*pi/3.0f)){//&&2pi/3<=h
                h -= 2*pi/3;
                y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
                r = x; 
                g = y;
                b = z;
            }else{  //less than 2pi && 4pi/3<=h
                h -= 4*pi/3;
                y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
                g = x;
                b = y;
                r = z;
            }
    

    You will also need to make sure that none of the rr,gg,bb values end up outside the 0..255 interval:

    if (rr < 0) rr = 0;
    if (rr > 255) rr = 255;
    

    … etc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have this rather strange issue, i am trying to line up some
I have some strange behavior redirecting stdout and stderr from s3cmd. For example: $
I have a strange issue. I'm trying to get Apple Push Notifications working with
Im facing a strange issue trying to move from sql server to oracle. in
I have some strange issues with loading of RadGrid. What I'm trying to accomplish
I have some strange behavior occurring in an ASP.NET application that I am trying
I am trying to debug a strange issue with users that have LogMeIn installed.
I have a very strange issue that only affects webkit browsers for some reason,
We have some strange issue with some internet explorer versions, so we have a
I have been trying to get rid of some strange text appearing under my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.