Fun Python Exercise - Convert Numbers to Images with NumPy, OpenCV and Pillow

preview_player
Показать описание
In this exercise we will use our NumPy skills to convert numbers into images 💪💪💪 We will see examples of 2 very useful Python image libraries: OpenCV (cv2) and Pillow (PIL). And also discuss the differences between them.

The purpose of this tutorial is to guide you step by step from creating the most simple greyscale image - all the way until drawing a complex structure of RGB windows! or even a smooth turquoise gradient image! 🤩

⭐ Clone Complete Tutorial Code ⭐

--------------------------------------------------------------

🛑 If this is the first time you are working with NumPy,
I recommend watching the beginning of my Ultimate Guide to NumPy Arrays tutorial:

🛑 If this is the first time you are working with RGB/BGR/Greyscale,
I recommend watching my Image into Matrix Tutorial:

⌚ TIME STAMPS ⌚
---------------------------------------
00:00 - intro
00:34 - import NumPy and OpenCv
00:58 - create empty array
01:41 - save array as PNG image
02:30 - grayscale image - 50 Shades of Grey
03:26 - region of interest
04:27 - floor division
06:21 - smooth greyscale gradient image
---------------------------------------
06:43 - convert grayscale image to BGR
08:02 - red gradient BGR image
09:01 - turquoise/yellow gradient BGR images
---------------------------------------
09:35 - artistic RGB image with Pillow
11:29 - fill NumPy image background
11:40 - draw square with NumPy
13:15 - working with relative coordinates
15:17 - draw window pattern with NumPy
18:49 - apply random color
20:57 - thanks for watching!

👨‍👩‍👧 RELATED VIDEOS OF MINE 👨‍👩‍👧
---------------------------------------
⭐ Image into Matrix:
⭐ Draw with OpenCV:
⭐ Ultimate Guide to NumPy Arrays:
⭐ Ultimate Guide to NumPy Operations:

🐦 SOCIAL MEDIA 🐦
---------------------------------------
Share your NumPy Images with Me! 🤩🤩🤩
⭐ LinkedIn:
⭐ Twitter:

* CREDITS *
---------------------------------------
Рекомендации по теме
Комментарии
Автор

I like to think one of the contributors to OpenCV reversed RGB as a joke, then it escalated past the point of no return.
Cool video!
It gave me an idea to see what happens if I use data unrelated to colours to generate a picture...
if i know my data is in the range 0-5000, then I could calculate the value between 0-5000 as a percentage of 5000, then apply that percentage to 0-255, then see what monstrosity it generates as an image... kind of a heat-map but with no purpose except to make coloured squares... and probably learn more about OpenCV and Python in general...!
I think Mondrian would be horrified at the result... !

cerealport
Автор

I now understand why students learn better when there teacher is a beautiful and fun person. I have no idea learning python could be this awesome. I appreciate your good works and the effort. Cheers

hamzavictor
Автор

What a woman, what a voice!!! I'm excited by hearing the sound vibrations..., sometimes even forgetting that I came here to learn!)

kharutyunyan
Автор

these tutorials and explanations are amazing, I kinda learned all the basics of Python and didn't know what to do next, but your channel helps a lot

mansbjork
Автор

I was about to write you another message that where are you !!
Thank God you showed up 😀😀😊

smalirizvi
Автор

PyCharm (which the IDE that I use) wouldn't install the OpenCV and PIL the way Numpy installed. I had to look it up. PIL wouldn't install at all. So, with the alternate route, I had to install Pillow. In the end, I got everything working.

I may have to rewatch this particular video over and over again. I understand it as I'm following along with you. However, I'm not sure that, if I go back later to look at the code, I will understand it then.

Also, I have to say that it's refreshing to watch you, because you don't beg for money or give us a website where we have to give money to see more. Don't get me wrong, if I had money I'd probably tip, donate, pay you (however you want to look at it). What I'm getting at is that you don't throw distractions in the mix. You act as if you have a job ("mission" would probably be a better word) to do and you do it without letting anything else get in the way. So, thank you for putting out great videos.

andromydous
Автор

Blonde getting smarter is definitely a symbol of Endgame....
Luv ur content 💜

captainlevi
Автор

Fantastic. Thank you for simplifying a complex topic.

Khosrow
Автор

I did the same kind of thing in pygame now. There's a pygame function that gives you the address of the pixels of a surface, I used ctypes and a function written in C and imported it to pygame to alter the pixels manually very quickly ;)

undeadpresident
Автор

Hello ..

Thank you for your amazing tutorial. Please note my following observation.
1) if we set n_shades = 255, it gives a thick border on extreme right of the image.

Is there anyway to avoid that?

Thanks

johnminty
Автор

The Hi Mariya, thanks so much for your excellent tutorials. Your passion and enthusiasm for teaching Python are contagious..l have been binging on your python tutorials for the past 2 days, and I’m beginning to like Python. How can I donate to your channel?

jamalabu-dayyeh
Автор

I never thought I would be learning python and getting in love at the same time, isn’t she just beautiful? 😍☺️🙂

JoshCentauri
Автор

wow amazing rig..if I learn python and start to make $, will I be able to buy rig and monitor like yours?

paparazzo
Автор

Hi, can you create a video about setting up and using Tensor Flow? Maybe training some basic Neural Network using datasets provided by Google. Preferably made with Google Colaboratory. Thank you.

jurajchobot
Автор

I loved, you're the best! Mariya!!!

FA-Q
Автор

Hi, can you show us how to turn music into pictures? I would want to take a song, extract different frequencies from it and then turn them into a picture, where 1000x1000 image will show the song as a picture. It goes as follows: Algorithm for computing semitones: starting with base note, which you will set as variable C0 set to 16.35Hz and from there you will compute the whole spectrum as a list, where first member is C0 and member i is C0*2^(i/12) Don't forget i starts with 1, not 0). You will generate list members up to maximum frequency, which is about 22 000Hz. Then you will divide song length into 1000 discrete steps. For every song part you will compute its average frequency and make data pairs of song step n which will have semitone m assigned as a closest tone to average frequency. (Let's say average frequency of step one will be 120Hz and the closest frequency in semi tone list will be member 35 at 123.47 Hz. Frequency step 1 will then have semi tone 35 paired with it) Once every step has semitone assigned, you can draw the image. Let's say you have around 150 semi tones, semi tones with same modulo 12 result will have the same color. (Let's say semi tone 0, 12, 24 will have this color and 1, 13, 25 will have other color.) You will now need 12 colors, you will get them by dividing visible spectrum of light into 12 equal steps, where 1 will be true Red and 12 true Violet. Time to draw now. steps will be drawn in columns from left to right. Step 1 will be a 1x1000px column of color Red if it has order of semi tone in list at place 0 or 12 or 24 etc... Let's say step 2 has semi tone order of 5, 17, 29 etc.. which is (N mod 12 = 5) and so it is drawn as a 1x1000px column of fifth color in light spectrum. You will repeat until all 1000 steps are drawn. The result is an image, where time flows from left to right and every tone of scale is represented in different color (C0, C1, C2, C3 are Red, while B0, B1, B2.. are Violet and so on). I know it is a lot, but I would be glad, Thank you :D

jurajchobot
Автор

Hi i tried doing these syntaxes in jupiter notebook but it says it cant find a module named cv2 in the library?

haniabdulrehman
Автор

I enjoy watching you coding! Good job lady :)

Tabvn
Автор

Hi, nice video
Could you answer me something, where do you live, I'm saying state or city? I ask because I could understand easily what you say, but there some guys on YouTube I couldn't understand.
Thank you so much. =]

alejedi
Автор

I enjoy these and am learning so much, thanks.

PlasmaOscillations