Last active
August 29, 2015 14:21
-
-
Save NekoTashi/9b6225e38d1f6b751c1f to your computer and use it in GitHub Desktop.
Intento fallido de capturar el contorno de una imagen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from PIL import Image | |
| from PIL import ImageFilter | |
| # Get an image | |
| image = Image.open('images/image.jpg') | |
| # Get the contour | |
| image = image.filter(ImageFilter.CONTOUR) | |
| # Save image | |
| image.save('images/image_contour.jpg') | |
| # Show image | |
| image.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from PIL import Image | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # Read image to array | |
| image = np.array(Image.open('images/image.jpg').convert('L')) | |
| # Create a new figure | |
| plt.figure() | |
| # Convert to gray scale | |
| plt.gray() | |
| # Take contours with origin upper left corner | |
| plt.contour(image, origin='image') | |
| plt.axis('equal') | |
| plt.axis('off') | |
| # Show image | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from PIL import Image | |
| from PIL import ImageChops | |
| from PIL import ImageOps | |
| # Get an image | |
| image = Image.open('images/image.jpg') | |
| # Convert image to black and white | |
| convert_gray = image.convert('L') | |
| black_and_white_image = convert_gray.point(lambda x: 0 if x < 128 else 255, '1') | |
| black_and_white_image.save('images/image_bw.jpg') | |
| imported_bw_image = Image.open('images/image_bw.jpg') | |
| # Invert colors | |
| inverted_image = ImageOps.invert(imported_bw_image) | |
| inverted_image.save('images/image_inv.jpg') | |
| # Darken new image | |
| image = Image.open('images/image.jpg') | |
| darken_image = image.point(lambda x: x * 0.5) | |
| darken_image.save('images/image_dark.jpg') | |
| # Subtract images | |
| imported_darken_image = Image.open('images/image_dark.jpg').convert('CMYK') | |
| imported_inverted_image = Image.open('images/image_inv.jpg').convert('RGBA') | |
| diff = ImageChops.difference(imported_inverted_image, imported_darken_image) | |
| diff.save('images/result_image.jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment