paint-brush
This Is How Easy it Is to Read and Display Imagesby@shehzensidiq
334 reads
334 reads

This Is How Easy it Is to Read and Display Images

by M Shehzen SidiqDecember 1st, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Open CV library lets us do all the stuff with the images that we can imagine. In today’s post, we will explore 2 functions of Open Cv: `imread` and `imshow`; which do what their name suggests. Imread is used to read an image, and 'imshow' can be used to display the images using an open cv library. Imshow is used for the display of an arbitrary window name, and ‘window name’ is any arbitrary name for the displaying of images.

Company Mentioned

Mention Thumbnail
featured image - This Is How Easy it Is to Read and Display Images
M Shehzen Sidiq HackerNoon profile picture


So OPEN cv, HUH!


Yes! Why Not!!


Okay, then.


Since working with images is becoming more and more popularized, we are going to take a dive into this field, going from the basics and starting with the OPEN CV library. Which lets us do all the stuff with the images that we can imagine.


In today’s post, we will explore 2 functions of Open Cv: imread and imshow; which do what their name suggests.


imread is used to read an image, and imshow is used to display the images using an open cv.


Let us first import the library we need.


import opencv as cv2

Now, let us explore today’s jungle of open cv and find the meaning and working of two 👑s of this jungle.

imread()


So, this function is used to read an image, given the path of the image is correct 🤣.

im = cv2.imread("path to the image")


We must know that the image read -


  1. it is read in BGR color format and not the RGB format.


  2. Behind every image is a set of pixels, so if we print the im, we will get the NumPy array.


image is just a set of pixels

If we want to display the image and not the nd array, we must use imshow function and not the print function.


What it does is it reads the pixel values and displays those based on the color channel of the image.


cv2.imshow("window name", image)


image is the numpy nd array, and ‘window name’ is any arbitrary name for the window that pops up for the displaying of images.

Conclusion

So, this is how easy is it to read and then display images using an open cv. I hope you got an understanding of these concepts.


Thank you for reading and See you in the next post