Python OpenCV Reading Multiple Image

In this Python OpenCV lesson we are going to learn Python OpenCV Reading Multiple Image, some times you need to show two images, for example if you want to do image filtering, along side with original image you want to show the filtered image. for reading multiple images in OpenCV we are going to use Matplotlib, as we have already learned  that how you can use Matplotlib for showing the image in opencv.

 

 

This is the complete code for this lesson.

 

 

 

You can see that in here we have used subplot() for showing of our two images, you need to give some arguments, the first one is the number of rows, after that the number of columns and at the end you need to give the image position, we want to do the same process for the second but just we are going to change the image from 1 to 2.

 

 

 

If you run the code this will be the result.

Python OpenCV Reading Multiple Image
Python OpenCV Reading Multiple Image

 

 

 

We have our images, but you can see a color difference in our images, it is because opencv renders the image in order of GBR, the reverse of the usual RBG format. this is the reason the colors get messed up from OpenCV to matplotlib. The matplotlib module displays images according to the more conventional RGB method. Therefore, in order to correctly render images from OpenCV in matplotlib, what we need to do is to convert the GBR image into a RGB image.

 

We can use cv2.cvtColor() for converting our images.

 

 

Now this is the complete code for converting the color.

 

 

 

If you run the code this will be the result and you can see that we have the correct color images.

Python OpenCV Reading Multiple Image
Python OpenCV Reading Multiple Image

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.