News for hackers. Stuff that matters.
Re:A 100x speedup with unsafe Python by gugagore on Monday May 06, 2024 @11:11PM (#40281979)
Technically, image resizing does in general care about the color channel ordering, because color spaces are in general not linear. https://www.alanzucconi.com/2016/01/06/colour-interpolation/
Re:A 100x speedup with unsafe Python by quietbritishjim on Monday May 06, 2024 @11:20PM (#40282019)
That article fails to touch on the fundamental issue with its title "The Secrets of Colour Interpolation"; RGB values are a nonlinear function of the light emitted (because we are better at distinguishing dark colours, so it's better to allow representing more of those), so to interpolate properly you need to invert that function, interpolate, then reapply. The difference that makes to colour gradients is really striking.
Re:A 100x speedup with unsafe Python by topherclay on Monday May 06, 2024 @11:33PM (#40282099)
Do you mean converting the RGB value to LAB values in the CIELAB color space and doing the interpellation there?

Is there a better way to do it?

Re:A 100x speedup with unsafe Python by CarVac on Tuesday May 07, 2024 @12:16AM (#40282277)
No, you just need to linearize the brightness.
Re:A 100x speedup with unsafe Python by drjasonharrison on Tuesday May 07, 2024 @03:51PM (#40290720)
Typically this is done by using a look-up table to convert the 8-bit gamma encoded intensities to 10-bit (or more) linear intensities. You can use the same look-up table for R, G, and B. Alpha should be linear.
Re:A 100x speedup with unsafe Python by yosefk on Tuesday May 07, 2024 @01:54AM (#40282773)
While this is a valid point, cv2.resize doesn't actually implement color conversion in a way addressing this issue; at least in my testing I get identical results whether I interpret the data as RGB or BGR. So if you want to use cv2.resize, AFAIK you can count on it not caring which channel is which. And if you need fast resizing, you're quite likely to settle for the straightforward interpolation implemented by cv2.resize.
Re:A 100x speedup with unsafe Python by planede on Tuesday May 07, 2024 @07:48AM (#40284423)
Even if the RGB components correspond to sRGB, to linearize you apply the same non-linear function to each component value, independently. So even if you do the interpolation in a linear colorspace, the order of the sRGB components does not matter.