Exemple #1
0
HSI operator*(const HSI& c, double scale_factor)
{   float new_I = (float)(scale_factor * c.I);
    if ( new_I < 0 || new_I > 1.0 )
    {   std::cerr<<"HSI::operator*(HSI, double): result out of range." << std::endl;
        return ( HSI( 0, 0, 1 ) );
    }
    else
    {
        return ( HSI(c.H, c.S, new_I) );
    }
}
Exemple #2
0
RLI::operator HSI() const
{
#if HSI_CYLINDER
    double nr = ( R - 127 ) / 127.0;
    double nl = ( L - 127 ) / 127.0;

    double h;
    if ( nr == 0 )  // On l-axis
    {
        h = (nl >= 0) ? M_PI / 2 : 3 * M_PI / 2;
    }
    else
    {
        h = (nr >= 0) ?  ((nl >= 0) ? atan( nl / nr ) : atan( nl / nr ) + 2 * M_PI)
            : atan( nl / nr ) + M_PI;
    }

    HSIType s = (HSIType)sqrt( nr*nr + nl*nl );
    HSIType i = (HSIType)(I / 255.0);

    return ( HSI( (HSIType)h, s, i ) );
#else
    std::cerr<<"The RLI -> HSI transform is not implemented for conical space.";
#endif
}
Exemple #3
0
// BETTER IMPLEMENTATION:??
_RGB::operator HSI() const
{
    float total = (float)R + (float)G + (float)B;
    float i = athird * total / 255;

    if ( is_gray(*this) )
    {
        return( HSI_GRAY(i) );
    }
    else
    {
        float r = (float)R / total;
        float g = (float)G / total;
        float b = (float)B / total;

        float s = 1 - 3 * ((r<g) ? ((r<b) ? r : b ) : ((g<b) ? g : b ));

        double angle = 0.5 * ( (r-g) + (r-b) ) / (sqrt((r-g)*(r-g)+(r-b)*(g-b)) );

        double h;
        if(b<=g)
        {
            h = acos(angle);
        }
        else
        {
            h = 2*M_PI - acos(angle);
        }

        return ( HSI ( (HSIType)h, s, i ) );
    }
}
int* HueSaturationFilter::setHueSaturationIntesity(double hue, double saturation, double intensity) {
	for (int i = 0; i < width * height; i++) {
		HSI hsi = pixelsHSI[i];
		double h = hsi.h;
		h = hue;
		if (h > 360) {
			h = h - 360;
		} else if (h < 0) {
			h = h + 360;
		}

		double s = hsi.s;
		s = saturation;
		s = min(1.0, max(0.0, s));

		double newI = hsi.i;
		newI = intensity;
		newI = min(1.0, max(0.0, newI));

		pixelsHSI[i] = HSI(h, s, newI);
		RGB rgb = ColorTranslator::HSI2RGB(h, s, hsi.i);
		if (ColorTranslator::checkRGB(rgb)) {
			pixels[i] = RGB2Color(rgb.r, rgb.g, rgb.b);
		}
	}
	return pixels;
}
HSI ColorTranslator::RGB2HSI(double R, double G, double B) { // 0 ~ 255
	double r = R / COLOR_UPPER_BOUND;
	double g = G / COLOR_UPPER_BOUND;
	double b = B / COLOR_UPPER_BOUND;

	double theta = acos(
			((r - g) + (r - b)) * 0.5
					/ pow((pow((r - g), 2) + (r - b) * (g - b)), 0.5));
	theta = theta * 180 / PI;
	double h;
	if (b <= g) {
		h = theta;
	} else {
		h = 360 - theta;
	}

	double i = (r + g + b) / 3.0;

	double minColor = 0;
	minColor = r < g ? r : g;
	minColor = minColor < b ? minColor : b;
	double s = 1 - i / (r + g + b);

	return HSI(h, s, i);
}
int* HueSaturationFilter::setSaturation(double saturation) {
	for (int i = 0; i < width * height; i++) {
		HSI hsi = pixelsHSI[i];
		double s = hsi.s;
		s = saturation;
		s = min(1.0, max(0.0, s));
		pixelsHSI[i] = HSI(hsi.h, s, hsi.i);
		RGB rgb = ColorTranslator::HSI2RGB(hsi.h, s, hsi.i);
		if (ColorTranslator::checkRGB(rgb)) {
			pixels[i] = RGB2Color(rgb.r, rgb.g, rgb.b);
		}
	}
	return pixels;
}
int* HueSaturationFilter::setHue(double hue) {
	for (int i = 0; i < width * height; i++) {
		HSI hsi = pixelsHSI[i];
		double h = hsi.h;
		h = hue;
		//h = min(360.0, max(0.0, h));
		if (h > 360) {
			h = h - 360;
		} else if (h < 0) {
			h = h + 360;
		}
		pixelsHSI[i] = HSI(h, hsi.s, hsi.i);
		RGB rgb = ColorTranslator::HSI2RGB(h, hsi.s, hsi.i);
		if (ColorTranslator::checkRGB(rgb)) {
			pixels[i] = RGB2Color(rgb.r, rgb.g, rgb.b);
		}
	}
	return pixels;
}
Exemple #8
0
HSI HSIColorScale::operator[](double f) const {
  return HSI(hue_range * f + foot.hue,
             sat_range * f + foot.saturation,
             int_range * f + foot.intensity);
}