Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comments

  1. PIL.ImageGrab works on macOS and Windows only.

  2. You can further crop a screenshot image using the method Image.crop.

import numpy as np
from PIL import Image, ImageFilter
img = Image.open("../../home/media/poker/4h.png")
img
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=37x54 at 0x7F856E0A3048>

ImageFilter.BLUR

The BLUR filter blurs an image.

img.filter(ImageFilter.BLUR)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E26A0>

ImageFilter.MinFilter

The MinFilter takes the minimum value of the specified neighborhood for each pixle. The direct effect is to make lines thicker in an image. The MaxFilter is also refer to as erosion.

img.filter(ImageFilter.MinFilter(3))
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E663650B8>

Or equivalently,

img.filter(ImageFilter.MinFilter)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E22E8>

ImageFilter.MaxFilter

The MaxFilter takes the maximum value of the specified neighborhood for each pixle. The direct effect is to make lines thinner in an image. The MaxFilter is also refer to as dilation.

img.filter(ImageFilter.MaxFilter)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F856C97D518>

ImageFilter.ModeFilter

The ModeFilter takes the mode value of the specified neighborhood for each pixle. The direct effect is to makes thin lines disappear.

img.filter(ImageFilter.ModeFilter)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F856C97DBA8>

ImageFilter.CONTOUR

The CONTOUR filter gets contours of objects in an image.

img.filter(ImageFilter.CONTOUR)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E2748>

ImageFilter.DETAIL

img.filter(ImageFilter.DETAIL)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E2E10>

ImageFilter.EDGE_ENHANCE

img.filter(ImageFilter.EDGE_ENHANCE)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E9160>

ImageFilter.EDGE_ENHANCE_MORE

img.filter(ImageFilter.EDGE_ENHANCE_MORE)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E9390>

ImageFilter.EMBOSS

img.filter(ImageFilter.EMBOSS)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E96A0>

ImageFilter.FIND_EDGES

img.filter(ImageFilter.FIND_EDGES)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E9C18>

ImageFilter.SHARPEN

img.filter(ImageFilter.SHARPEN)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599E9F98>

ImageFilter.SMOOTH

img.filter(ImageFilter.SMOOTH)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599F52B0>

ImageFilter.SMOOTH_MORE

img.filter(ImageFilter.SMOOTH_MORE)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F3E599F5588>