In Python:
I read in an image and I want to process each channel (RGB) separately, then put the modified channels back together into an image and save it to disk. I have tried everything I can think of, but I get mangled images back no matter what.
BTW, I can't use Pillow for most of this because I want 16 bits to process.
I've tried innumerable variations of this:
import imageio
import numpy as np
from PIL import Image
def load_pic():
global picky, reds, greens, blues, shape
filename = "FinalStacked.fit"
print(f"loading {filename}")
picky = imageio.v3.imread(filename, plugin = "FITS")
shape = picky.shape
print(f"Image loaded, size = {shape}")
reds = picky[0]
greens = picky[1]
blues = picky[2]
print("picture loaded")
def finish():
out = np.dstack((reds, greens, blues))
im = Image.fromarray(out, 'RGB')
print(im.mode)
imageio.v3.imwrite("done.png", im)
load_pic()
finish()
But nothing seems to work. I would expect the above to return a reasonable facsimile of the input image, but it doesn't.
As mentioned in the comments you are not actually getting the RGB channels with your code. Something like the below code will work for you:
The error in your code is that you're taking the wrong channels
Print: