Skip to content

sRGBtoRGB and RGBtosRGB do not rescale, resulting in inaccurate conversions #29

@FallingPineapples

Description

@FallingPineapples

Unlike other colorspace conversions, sRGBtoRGB and RGBtosRGB do not rescale the input or output between imager's default 0-1 range and CImg's 0-255 range; since sRGB is not linear, this results in quite inaccurate conversions. Both input and output rescalings would be required for accurate conversion.

//' @describeIn imager.colourspaces RGB to sRGB conversion
//' @export
// [[Rcpp::export]]
NumericVector RGBtosRGB(NumericVector im) {
CId img = as<CId >(im);
img.RGBtosRGB();
return wrap(img);
}
//' @describeIn imager.colourspaces sRGB to RGB conversion
//' @export
// [[Rcpp::export]]
NumericVector sRGBtoRGB(NumericVector im) {
CId img = as<CId >(im);
img.sRGBtoRGB();
return wrap(img);
}

For example, converting white in RGB to sRGB results in values well out of range:

c(1,1,1) %>% as.cimg %>% RGBtosRGB %>% str
# 'cimg' num [1, 1, 1, 1:3] 12.7 12.7 12.7

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions