How does julia downscale from 16 bit to 8 bit?

I am attempting to revamp an old script that I found that converts a TIF format 16 bit image into a 8 bit JPG format image. I was wondering how Julia handles the downscaling of 16 bit images. It seems like this code is responsible for the downscaling:“($path_to_jpg)$(flir_dt_str).jpg”, Argb)
How does this actually work? What math does it do to downscale the bits?

I don’t know and don’t know and don’t have time to try to dig into this right now, but I will suggest you try applying the @edit macro to your call (e.g., @edit“($path_to_jpg)$(flir_dt_str).jpg”, Argb)) to open the source code and take a look. You can sniff around the source code to try to see what it’s doing. If it isn’t calling an external library, you should eventually be able to find the implementation. But, if I were to guess, this is using an external library and your search will end at a ccall somewhere. Then you’ll have to look into that library or its documentation to get an answer.

If you have a hard time following the functions that get called as part of that function, check out the Cthulhu package and its @descend macro. It may be a little easier if the functions are spread across many files.

Were I to guess, the conversion is done by first converting the TIF image to raw pixels (possibly at even “higher” bit depth, although the extra bits would be effectively unused), then it converts the pixel-space image to JPG. JPG compression is pretty math-y (heavy use of discrete cosine transforms and non-uniform quantization, if I recall correctly) so the answer may not be totally clear even if you find the code. You might get an easier answer by looking into written discussions of the JPG compression process.

It’s the same as if you do Float32(Float64(π)), it’s just rounding. It comes “for free” because of FixedPointNumbers. Unlike most image-processing suites, in JuliaImages the meaning of the numeric value of a pixel is independent of its bitwidth: the latter is regarded as an internal detail. “White” is always 1.0 whether you’re using Float64, Float32, N0f8 (8-bits for the range 0…1), or N0f16 (16-bits for the range 0…1).