What is the method of converting numpy to Pillow?
This article mainly explains "what is the method of numpy-to-Pillow conversion". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the method of numpy-to-Pillow interconversion".
The lab code shows:
From PIL import Image, ImageDrawimport numpy as npim = Image.open (bryant.jpg) # im.show () ima = np.asarray (im) a.shape, a.dtype, a.min (), a.max () type (a.shape) im2 = Image.fromarray (a) # im2.show () im2# The crop method from the Image module takes four coordinates as input.# The right can also be represented as (left+width) # and lower can be represented as (upper+height). (left, upper, right, lower) = (500,20,900) Here the image "im" is cropped and assigned to new variable im_cropim_crop = im.crop ((left, upper, right, lower)) # im_crop.show () im_cropim (width, height) = (im.width / / 2, im.height / / 2) im_resized = im.resize ((width, height)) # im_resized.show () im_resizedim.resize ((200,300), box= (500,20,900,400) imdraw = ImageDraw.Draw (im) draw.rectangle ((500,20,900) 400), outline= (255255255), width=8,) im
Show the running results:
Thank you for your reading, the above is the content of "what is the method of numpy-to-Pillow conversion". After the study of this article, I believe you have a deeper understanding of what the method of numpy-to-Pillow conversion is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!