-
-
Save bkw/0055c4f638328f6a4dc8 to your computer and use it in GitHub Desktop.
naïve attempt at lab transform prior to normalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apply normalization | |
if (baton->normalize) { | |
// normalize the luminance band in LAB space: | |
VipsImage *lab; | |
if (vips_colourspace(image, &lab, VIPS_INTERPRETATION_LAB, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, lab); | |
VipsImage *luminance; | |
if (vips_extract_band(lab, &luminance, 0, "n", 1, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, luminance); | |
VipsImage *chroma; | |
if (vips_extract_band(lab, &chroma, 1, "n", 2, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, chroma); | |
VipsImage *stats; | |
if (vips_stats(luminance, &stats, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, stats); | |
double min = *VIPS_MATRIX(stats, 0, 0); | |
double max = *VIPS_MATRIX(stats, 1, 0); | |
double f = 100.0 / (max - min); | |
double a = -(min * f) + 0.5; | |
VipsImage *luminance100; | |
if (vips_linear1(luminance, &luminance100, f, a, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, luminance100); | |
VipsImage *normalized; | |
if (vips_bandjoin2(luminance100, chroma, &normalized, NULL)) { | |
return Error(); | |
} | |
vips_object_local(hook, normalized); | |
image = normalized; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment