This one looks a lot different when you have the image at full size because you can see the white noise a lot easier. You can do dithering with the ‘L’ mode, but I wanted to show what happens when you use ‘1’. The only difference between this function and the previous one is that we added a dithering argument and we also called the convert() method with a ‘1’ (one) instead of ‘L’. Let’s take a look at how that changes the code:ĭef black_and_white_dithering(input_image_path,īw = color_nvert('1', dither=Image.NONE) The Pillow project also supports creating black and white images with dithering, which is basically adding noise to the image. That looks pretty nice if I do say so myself. Let’s see what kind of output our code generated: The documentation states “When translating a color image to black and white (mode “Lâ€), the library uses the ITU-R 601-2 luma transform: L = R * 299/1000 + G * 587/1000 + B * 114/1000” where the RGB maps to Red, Green and Blue. The mode we care about at the moment is ‘L’. Pillow supports several modes including: ‘P’, ‘L’ and ‘1’. Here you will find that the first parameter to the convert() method is the mode. This may seem a bit strange, so let’s look at the documentation. We then use that object’s convert method to transform the image to black and white by passing it the string ‘L’. ![]() It contains a call to open the Image which will return an Image object. The piece we really care about in this script is this function. The function above takes two arguments: the input image’s file path and the path we want to save the output to. Now we just need to create a simple function that can turn our full color photo into a black and white one:Ĭolor_image = Image.open(input_image_path) For this example, we will use the following fuzzy caterpillar: The first obstacle is finding a photo that you would like to edit. ![]() In this article we will look at the two simple ways to convert a photo to black and white and then we will also learn how to make a sepia-toned photo. If you want to change a photo that you took into a black and white photo programmatically, the Pillow package has you covered. I have also rescued a drab photo by turning it black and white. I personally like to play around with them as you can sometimes take a boring photo and turn it into something dramatic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |