Created
April 3, 2017 19:03
-
-
Save pkage/be67a2b6264ce10a985a53cdb9108b1b to your computer and use it in GitHub Desktop.
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
from PIL import Image | |
import numpy as np | |
import glob, os | |
g3 = 'g3' | |
g4c = 'g4c' | |
g4nc = 'g4nc' | |
np = 'np' | |
filename = 'Prostate_Cancer_Data' | |
with open(filename, "wb") as f: | |
for img in glob.glob("*bmp"): | |
if g3 in img: | |
label = [0] | |
elif g4c in img: | |
label = [1] | |
elif gn4c in img: | |
label = [2] | |
elif np in img: | |
label = [3] | |
else: | |
# idk do something better here | |
throw Exception('something went tits up') | |
im = Image.open(img) | |
im = np.array(im) | |
red = im[:, :, 0].flatten() | |
green = im[:, :, 1].flatten() | |
blue = im[:, :, 2].flatten() | |
im = np.array(list(label) + list(red) + list(green) + list(blue), dtype = np.uint8) | |
f.write(im) | |
print(im) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment