To write the images you need to convert the output into the right format (assuming outputs are in the 0,1 range):

# Convert outputs from 0-1 to 0, 255
img_in *= 255.0

# Convert floats to bytes
img_in = img_in.astype(np.uint8)

# Transpose the images from channel first (4, 96, 96) to channel last (96, 96, 4)
image1 = img_in[0, :, :, :].transpose(2, 1, 0)
image2 = img_in[1, :, :, :].transpose(2, 1, 0)

Then it's just a matter of saving the images:

cv2.imwrite('./example_path/image1.png', image1)
cv2.imwrite('./example_path/image2.png', image2)
Answer from 0xd34dc0de on Stack Overflow
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ opencv โ€บ python โ€บ opencv-python-save-image-example
OpenCV Python Save Image - cv2.imwrite() - Example
June 29, 2026 - If you give an absolute path, OpenCV writes the image at that exact location. If you give only a filename or a relative path, OpenCV saves the file relative to the current working directory of the Python process.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-opencv-cv2-imwrite-method
Python OpenCV | cv2.imwrite() method - GeeksforGeeks
December 23, 2025 - cv2.imwrite() is an OpenCV function used to save an image to storage in any supported format such as JPG, PNG, or BMP.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ opencv
Reading and saving image files with Python, OpenCV (imread, imwrite) | note.nkmk.me
October 15, 2022 - In Python and OpenCV, you can read (load) and write (save) image files with cv2.imread() and cv2.imwrite(). Images are read as NumPy array ndarray. This article describes the following contents. Read ...
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-opencv-cv2-imwrite-save-image
OpenCV cv2.imwrite() - Save Image - Python Examples
Python OpenCV cv2.imwrite() - To save image to local storage using Python, use cv2.imwrite() function on OpenCV library. imwrite() writes numpy array as image to the persistent storage.
๐ŸŒ
Medium
samuel-ozechi.medium.com โ€บ loading-display-and-saving-with-opencv-df737e183647
Fundamental OpenCV Functions: Loading, Displaying and Saving Images | by Samuel Ozechi | Medium
July 7, 2024 - We would use a sample image of the Eiffel Tower (saved as eiffel_tower.jpg in my working directory). Loading Images 1. If you donโ€™t have OpenCV installed already, you can do so by using !pip install opencv for Jupyter Notebook or pip install py-opencv for PyCharm terminal. 2. Import the OpenCV package by including import cv2 in your code.
Find elsewhere
๐ŸŒ
Indian AI Production
indianaiproduction.com โ€บ home โ€บ blog โ€บ explained cv2.imwrite() function in detail | save image
Explained Cv2.Imwrite() Function In Detail | Save Image
April 18, 2021 - import cv2 import numpy as np import os img_path = 'model.jpg' img = cv2.imread(img_path) cv2.imshow('image', img) cv2.imwrite("model_write.png", img) cv2.waitKey(0) cv2.destroyAllWindows()
๐ŸŒ
Idiot Developer
idiotdeveloper.com โ€บ home โ€บ cv2.imwrite() โ€“ saving images in opencv python
cv2.imwrite() - Saving Images in OpenCV Python - Idiot Developer
July 28, 2023 - This example will create a ... image = np.random.randint(255, size=(512, 512, 3)) ## Saving an image val = cv2.imwrite("random.jpg", image) if val == True: print("Image is successfully saved on the disk.") else: print("Image ...
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ opencv save image
OpenCV save image | Parameters and format of OpenCV save image
April 18, 2023 - # command used to import the OpenCV library to utilize OpenCV read image function import cv2 # command used for reading an image from the disk disk, cv2.imread function is used # reading the image as a grey scaled image img1 * = * cv2.imread * (* r * ' * C *:\ * Users * \ * PRIYANKA BANERJEE\ * educba.png', * * * * 1) # saving the image into * * * the * * * filing * * * system status1 * = * cv2.imwrite * (* r * ' * C *: * \ * Users * \ * PRIYANKA BANERJEE * \educba1.jpeg', * * 0, * img1) print("The image file needs to be written to the file-system : ", * status1) cv2.waitKey(0) cv2.destroyAllWindows()
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ read-display-save-image-opencv
How to Read, Display and Save Image in OpenCV - Step-by-step Guide - DataFlair
April 28, 2026 - In this section, weโ€™ll learn more ... file, show it on your screen, and even save a new version after making changes. To write code, you can use any editor of your choice. To read the contents of an image, we have a function cv2.imread()....
๐ŸŒ
Delft Stack
delftstack.com โ€บ "delft stack" โ€บ "howto" โ€บ "python how-to's" โ€บ "how to opencv save image"
How to OpenCV Save Image | Delft Stack
March 11, 2025 - Hereโ€™s a simple example of how to save an image: import cv2 image = cv2.imread('input_image.jpg') cv2.imwrite('output_image.jpg', image)
๐ŸŒ
techtutorialsx
techtutorialsx.wordpress.com โ€บ 2018 โ€บ 06 โ€บ 24 โ€บ python-opencv-saving-an-image-to-the-file-system
Python OpenCV: Saving an image to the file system โ€“ techtutorialsx
January 25, 2025 - image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) In order to save the converted image, we will use the imwrite function, which allows to save the image to a file.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ opencv cv2.imwrite() method
OpenCV cv2.imwrite() method- Scaler Topics
May 29, 2023 - It should be noted that the cv2.imwrite() technique does not alter the initial image data. Instead, it makes a new file and saves the picture info.
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ read-display-save-image-with-opencv
Read, Display and Save Image with OpenCV - TechVidvan
April 15, 2023 - This can be done using the โ€œcv2.imwriteโ€ function, which takes in two parameters: the file path and the image data to be saved. The image data should be in the form of a NumPy array, and the file path should include the desired file format ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ opencv_python โ€บ opencv_python_write_image.htm
OpenCV Python - Write an image
Following program loads OpenCV logo image and saves its greyscale version when s key is pressed โˆ’ ยท import numpy as np import cv2 # Load an color image in grayscale img = cv2.imread('OpenCV_Logo.png',0) cv2.imshow('image',img) key=cv2.waitKey(0) if key==ord('s'): cv2.imwrite("opencv_logo_GS.png", img) cv2.destroyAllWindows()
๐ŸŒ
LabEx
labex.io โ€บ questions โ€บ how-to-write-an-image-using-opencv-8438
How to Write an Image in OpenCV | LabEx
July 25, 2024 - To write an image in a specific format, you can simply provide the appropriate file extension in the cv2.imwrite() function.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-cv2imwrite-function
What is the "cv2.imwrite()" function?
image is a numpy array of the image data that you want to save. cv2.imwrite() returns True if the image is successfully saved.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ opencv-python-program-to-read-and-save-an-image
OpenCV Python - Reading an image
May 30, 2023 - import numpy as np import cv2 # Load a color image in grayscale img = cv2.imread('OpenCV_Logo.png',1) cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows()