 We will have now an overview on Torch's image package. Image is the Torch 7 package for processing images. It allows us to save and load JPEGs, PNG, PPN, and PGMs. Allow us to do some easy transformations, like translation, scaling, rotation, horizontal, vertical, flip. We can also do parametrized transformations, like convolutions and warping. We can also draw some text and rectangles on images. And we are provided with a graphical user interface for displaying our images. Moreover, we can perform color space conversions from and to RGBs, YUV, Lab, and HSL. Finally, it provides us with constructors for creating Lena, Gaussian, and Laplacian kernels. We will see the following functions. We will start with Lua Rocks list and install to check whether the ENV package is installed in our system. Then we will meet our new REPL, which allows us to use the Qt libraries. And we will use it with the end library. Then we will learn how to load an image. We will also learn the Equal operator in the QLua interpreter. We will learn how to scale an image, how to display an image. How to make a copy, a deep copy of an image. How to replace the content of a plane, for example, with a specific value. Moreover, we will see a more advanced display where we can specify a title for the window, a zoom factor, the number of multiple images we would like to show per row, and how much space you would like to put between those images. Moreover, we will see how to extract this collection of images we just displayed. We will see how to save an image in more detail a PNG file. How to crop an image. We will see the names of some popular color space conversions. And then finally, we will see how to draw text on an image and how to draw a rectangle. More precisely, it's going to be a bounding box around Lena's face. Let's say we have an image we would like to resize. In this tutorial, instead of using the report TH we have been using so far, we will be using QLua, which is a QT-enabled Lua shell. We shall check that the ENV package is installed on our machine. We can do so by typing LuaRocksListEnv and we can see that the ENV is installed on our machine. So let's open QLua-Lenv to load the library ENV, which provides our reply with nice functionalities. We can start by requiring the package image. Then we can have a variable ai equal image.load and then the name of the file ai.jpeg. In QLua we had to type an equal in order to have a result print on screen. So let's print the size of ai. ai has three planes, RGB, 1000 rows and 1500 columns. The type of ai is a double tensor. Let's say we would like to nicely visualize this image on our screen. Let's query the current resolution of my screen. On OSX I can do so by typing system profile, SP displayed data type and I can grab the resolution. And we have that the resolution is of 900 rows and 1440 columns. So we have that our image is higher and wider than the current screen. Let's resize our image to half of its dimension. So we can type ai.scale equal image.scale of our image ai. We can say half of its rows and half of its height. If we check now the dimensionality of a scale it's going to be three planes, 500 rows and 750 columns. We can now easily display this image on the screen. I can do so by typing image display and ai.scale And here is our image. Let's now check the content of green in this image. To do so let's go back to the terminal. Let's have ai.green equal ai.scale clone. In this way we made a deep clone of the ai.scale tensor. Otherwise you would have shared the same reference to the same tensor if you would have simply used the equal assignment operator. So ai.green again it's three planes, 500 rows, 750 columns. Let's take the first plane which is the red plane and fill it with zeros. Then RGB so let's take the third plane and also fill it with zeros. So now ai.green will have only content relative to the green channel. Let's visualize now the content of ai.green so image.display and I could simply type ai.green This time we change and we write curly bracket and then we have image equal ai.green legend equal green plane Let's check the result. Here we have the green content of the previous image. Let's say we would like to visualize both image on the same window. We can do so by typing image.display image equal the table of ai.scale and ai.green Then we have legend equal original and green plane and then let's put zoom equal 0.5 otherwise it won't fit. Let's check the result and here they are the original on the left-hand side and the green plane on the right-hand side. Let's display as well the other two channels perhaps below and on the right-hand side. Let's go back to the terminal. So let's have ai.red equal torch zeros of the size of ai.scale and then we copy over just the first plane equal ai.scale first plane and then we can have ai.blue equal torch.zeros ai.scale and then ai.blue RGB so B is the last one equal to ai.scale number three and now we can display all the four images so we can do image.display bracket and let's have image equal ai.scale and then we have ai RGB so R and then we have ai.green and then we have ai.blue and then let's put again the zoom equal 0.5 and let's set the number of rows to be two at most and then we write the legend which is going to be original and then we have i.red and below we have g and b close and let's check the result and here we have the four maps so we have the original image in the top left corner the red plane top right we can see that in the top right area there is glitter red where we have lots of green and as well here that we have mainly blue we have less red here the same way where we have more red here we can see that there is less green and then we can see in the yellow area there is basically in the red area there are not whatsoever blue values you can still see some spots here and here because they correspond to the bright white of those spots let's say we are satisfying with our result and we would like to save the content of this screen so let's go back we can convert this collection of images into one image by using a very similar function let's go to the beginning and instead of having display we have image to display tensor instead of having image we put input and then at the beginning we are going to have our output image and we can press enter now if we would like to display to be sure it is correct we can go image.display image equal output image so equal 0.5 and legend equal output and let's check so here we have that the output image are those four brains glued together let's save this image on our desktop so let's go back to the terminal we can do so by issuing the command image.save let's save in png perhaps initially we open a jpeg image and now we are saving a png so we can easily convert among different images format so let's put here the name and we have four glued brains .png and then we can insert our image we would like to save we said we would like to save it on the desktop so we can do this top slash four glued brains enter if you go back on the desktop we can see here that we have our four glued brains png and we can open it let's say now we would like to extract the top lift quadrant of our newly generated image so let's print first the size of our image which is three planes an RGB image so a color image with 1000 lines and 1500 columns let's save now our crop image equal image.crop of our output image from the 00 coordinate so top lift quadrant to the 1500 divided by 2x coordinate from 1000 divided by 2y coordinate we can check now the dimensionality which is actually a color image so three planes 500 rows and 750 columns we can now display this image to be sure we have cropped the right one so image display image equal crop image and then legend equal cropped and we can check the result now and there we go the cropped image there are many more transformations we can apply to our image we can have a list of all transformations by typing image.taptap we can see crop we can see horizontal flip we can also see vertical flip we can also see HSL to RGB and HSV to RGB or RGB to HSL RGB to HSV and RGB to LAB also RGB to NRGB and RGB to Y so black and white and RGB to YUV we can rotate the image we can save in different format like GMP and GMPPM as we saw we can scale our image and then also one interesting one is from a gray scale to a jet color map I wrote some time ago let's finish now by trying the lana function which returns an image that has been widely used in the computer vision field we can simply display this image by typing image.display and here she is finally let's see how to write some text and draw some rectangles on our images this is very important for writing labels and bounding boxes image draw text on image lana and we have hello new line word add coordinate and here we have image.display and if we check the result we have lana and the string hello word in the top left corner add the position 10px we can change now for example the position and color and size let's do the same and in here we can do 20px for example and then we have color equal 0 2550 and then we may have size equal 5 and if we check the result we have our hello word in green and bigger character we can try one more variation so let's go up and then let's also add here the ground color equal perhaps red 255 0 green font on red background finally we can learn how to draw a bounding box so let's go back here image.display and open parenthesis then let's go image draw rectangle and then we have image.lana coordinate 200 and then 370 and 400 and then we have some specifications for example we can have line with equal 5 and then we can have color equal perhaps green so let's close this guy and let's close this one and let's see our result so there we go we have a bounding box on lana's face