Depending on whether opencv was installed via conda or pip, it reads the same image differently. The following is the script and image I used to test this.
Code
import cv2
import rasterio as rio
from skimage import io
import numpy as np
def check(path):
# All images should be in RGB mode
im1 = rio.open(path)
im1 = im1.read()
im1 = im1.transpose(1, 2, 0) # CHW to HWC
im2 = cv2.imread(path)
im2 = im2[:,:,::-1] # BGR to RGB
im3 = io.imread(path)
print(f"Rasterio and OpenCV = {np.all(im1[:,:,0] == im2[:,:,0])}")
print(f"Rasterio and Skimage = {np.all(im1[:,:,0] == im3[:,:,0])}")
if __name__ == "__main__":
check("rgb.jpg")
How to reproduce
Create two environments as follows:
conda create -n s1 -c conda-forge rasterio scikit-image python=3.7
conda activate s1
pip install opencv-python
conda create -n s2 -c conda-forge rasterio scikit-image opencv python=3.7
Link to image here
Output
# For s1 (opencv from pip)
Rasterio and OpenCV = False
Rasterio and Skimage = True
# For s2 (opencv from conda)
Rasterio and OpenCV = True
Rasterio and Skimage = True
s1 returns False for the rasterio vs opencv test, whereas s2 returns True for the same.
Why does this happen?