Skip to content

Instantly share code, notes, and snippets.

@tvercaut
Created October 28, 2021 08:28
Show Gist options
  • Save tvercaut/f31dcc3180b80c7cda50ab23d0eceb06 to your computer and use it in GitHub Desktop.
Save tvercaut/f31dcc3180b80c7cda50ab23d0eceb06 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import imageio
url = 'https://archive.org/download/10thframekixxc64800dpi48bit/10th%20Frame%20%28Kixx%29_C64_Cassette_800dpi_48bit.tif'
im0 = imageio.imread(url)
print('im0:',np.min(im0),np.max(im0),im0.shape,im0.dtype)
im0gray = 0.299*np.float32(im0[:,:,0]) + 0.587*np.float32(im0[:,:,1]) + 0.114*np.float32(im0[:,:,2])
im0gray = im0gray / np.max(im0gray)
im1 = np.uint16(np.round( im0gray*((1<<10)-1) ))
print('im1:',np.min(im1),np.max(im1),im1.shape,im1.dtype)
imageio.imwrite('sample10bit.png',im1)
plt.figure()
plt.imshow(np.float32(im0)/(1<<16))
plt.figure()
plt.imshow(im1,cmap='gray')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment