Created
February 4, 2015 21:20
-
-
Save sgillies/5368316f88bf67288bec to your computer and use it in GitHub Desktop.
Extracting characters from a PNG
This file contains 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
$ rio insp ~/Desktop/logo.png Rasterio 0.17.1 Interactive Inspector (Python 2.7.9) | |
Type "src.meta", "src.read_band(1)", or "help(src)" for more information. | |
>>> red = src.read(1) | |
>>> red | |
array([[255, 255, 255, ..., 255, 255, 255], | |
[255, 255, 255, ..., 255, 255, 255], | |
[255, 255, 255, ..., 255, 255, 255], | |
..., | |
[255, 255, 255, ..., 255, 255, 255], | |
[255, 255, 255, ..., 255, 255, 255], | |
[255, 255, 255, ..., 255, 255, 255]], dtype=uint8) | |
>>> selection = red < 250 | |
>>> img = np.ones_like(red) * 255 | |
>>> img[selection] = 0 | |
>>> from rasterio.features import shapes | |
>>> features = list(s[0] for s in shapes(img) if s[1] == 0) | |
>>> len(features) | |
4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment