Skip to content

Instantly share code, notes, and snippets.

@trongan93
Last active June 12, 2020 09:15
Show Gist options
  • Save trongan93/881a4a16275b326042685a15a6bc15a2 to your computer and use it in GitHub Desktop.
Save trongan93/881a4a16275b326042685a15a6bc15a2 to your computer and use it in GitHub Desktop.
image = Image.open('./ships-in-satellite-imagery/scenes/scenes/sfbay_1.png')
pix = image.load()
n_spectrum = 3
width = image.size[0]
height = image.size[1]
# creat vector
picture_vector = []
for chanel in range(n_spectrum):
for y in range(height):
for x in range(width):
picture_vector.append(pix[x, y][chanel])
picture_vector = np.array(picture_vector).astype('uint8')
picture_tensor = picture_vector.reshape([n_spectrum, height, width]).transpose(1, 2, 0)
plt.figure(1, figsize = (15, 30))
plt.subplot(3, 1, 1)
plt.imshow(picture_tensor)
plt.show()
picture_tensor = picture_tensor.transpose(2,0,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment